Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
b5a516e0
Commit
b5a516e0
authored
May 01, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new api method `vcard.update`
parent
f9aa75b6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
45 deletions
+55
-45
CHANGES.md
CHANGES.md
+1
-0
docs/source/developer_api.rst
docs/source/developer_api.rst
+27
-0
src/converse-vcard.js
src/converse-vcard.js
+27
-45
No files found.
CHANGES.md
View file @
b5a516e0
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
-
`_converse.api.vcard.get`
now also accepts a
`Backbone.Model`
instance and
-
`_converse.api.vcard.get`
now also accepts a
`Backbone.Model`
instance and
has an additional
`force`
parameter to force fetching the vcard even if it
has an additional
`force`
parameter to force fetching the vcard even if it
has already been fetched.
has already been fetched.
-
New API method
`_converse.api.vcard.update`
.
## UI changes
## UI changes
...
...
docs/source/developer_api.rst
View file @
b5a516e0
...
@@ -1292,3 +1292,30 @@ Example:
...
@@ -1292,3 +1292,30 @@ Example:
}
}
});
});
update
~~~~~~
Parameters:
* ``model`` a `Backbone.Model` instance
* ``force`` (optional), a boolean indicating whether the vcard should be
fetched again even if it's been fetched before.
Fetches the VCard associated with a particular `Backbone.Model` instance
(by using its `jid` or `muc_jid` attribute) and then updates the model with the
returned VCard data.
Example:
.. code-block:: javascript
converse.plugins.add('myplugin', {
initialize: function () {
_converse.api.waitUntil('rosterContactsFetched').then(() => {
const chatbox = _converse.chatboxes.getChatBox('someone@example.org');
_converse.api.vcard.update(chatbox);
});
}
});
src/converse-vcard.js
View file @
b5a516e0
...
@@ -16,35 +16,18 @@
...
@@ -16,35 +16,18 @@
function
onVCardData
(
_converse
,
jid
,
iq
,
callback
)
{
function
onVCardData
(
_converse
,
jid
,
iq
,
callback
)
{
const
vcard
=
iq
.
querySelector
(
'
vCard
'
);
const
vcard
=
iq
.
querySelector
(
'
vCard
'
);
if
(
_
.
isNull
(
vcard
))
{
let
result
=
{};
// Some servers return an empty IQ
if
(
!
_
.
isNull
(
vcard
))
{
return
onVCardError
(
_converse
,
jid
,
iq
,
callback
);
result
=
{
}
'
stanza
'
:
iq
,
const
img_type
=
_
.
get
(
vcard
.
querySelector
(
'
TYPE
'
),
'
textContent
'
),
'
fullname
'
:
_
.
get
(
vcard
.
querySelector
(
'
FN
'
),
'
textContent
'
),
img
=
_
.
get
(
vcard
.
querySelector
(
'
BINVAL
'
),
'
textContent
'
),
'
image
'
:
_
.
get
(
vcard
.
querySelector
(
'
BINVAL
'
),
'
textContent
'
),
url
=
_
.
get
(
vcard
.
querySelector
(
'
URL
'
),
'
textContent
'
),
'
image_type
'
:
_
.
get
(
vcard
.
querySelector
(
'
TYPE
'
),
'
textContent
'
),
fullname
=
_
.
get
(
vcard
.
querySelector
(
'
FN
'
),
'
textContent
'
);
'
url
'
:
_
.
get
(
vcard
.
querySelector
(
'
URL
'
),
'
textContent
'
)
};
if
(
!
u
.
isSameBareJID
(
jid
,
_converse
.
bare_jid
))
{
const
contact
=
_converse
.
roster
.
get
(
jid
);
if
(
contact
)
{
contact
.
save
({
'
fullname
'
:
fullname
||
_
.
get
(
contact
,
'
fullname
'
,
jid
),
'
image_type
'
:
img_type
,
'
image
'
:
img
,
'
url
'
:
url
,
'
vcard_updated
'
:
moment
().
format
()
});
}
}
}
if
(
callback
)
{
if
(
callback
)
{
callback
({
callback
(
result
);
'
stanza
'
:
iq
,
'
fullname
'
:
fullname
,
'
image
'
:
img
,
'
image_type
'
:
img_type
,
'
url
'
:
url
});
}
}
}
}
...
@@ -78,20 +61,11 @@
...
@@ -78,20 +61,11 @@
}
}
function
updateChatBoxFromVCard
(
_converse
,
jid
)
{
function
updateChatBoxFromVCard
(
_converse
,
jid
)
{
_converse
.
api
.
vcard
.
get
(
jid
)
const
chatbox
=
_converse
.
chatboxes
.
getChatBox
(
jid
);
.
then
((
vcard
)
=>
{
if
(
_
.
isNil
(
chatbox
))
{
const
chatbox
=
_converse
.
chatboxes
.
getChatBox
(
jid
);
return
;
if
(
!
_
.
isUndefined
(
chatbox
))
{
}
chatbox
.
save
(
_
.
pick
(
vcard
,
[
'
fullname
'
,
'
url
'
,
'
image_type
'
,
'
image
'
,
'
vcard_updated
'
]));
_converse
.
api
.
vcard
.
update
(
chatbox
);
}
})
.
catch
((
e
)
=>
{
_converse
.
log
(
e
,
Strophe
.
LogLevel
.
ERROR
);
_converse
.
log
(
"
updateChatBoxFromVCard: Error occured while attempting to update chatbox with VCard data
"
,
Strophe
.
LogLevel
.
ERROR
);
});
}
}
...
@@ -175,15 +149,14 @@
...
@@ -175,15 +149,14 @@
});
});
_converse
.
on
(
'
initialized
'
,
()
=>
{
_converse
.
on
(
'
initialized
'
,
()
=>
{
_converse
.
roster
.
on
(
"
add
"
,
(
contact
)
=>
_converse
.
api
.
vcard
.
get
(
contact
));
_converse
.
roster
.
on
(
"
add
"
,
(
contact
)
=>
_converse
.
api
.
vcard
.
update
(
contact
));
});
});
_converse
.
on
(
'
statusInitialized
'
,
function
fetchOwnVCard
()
{
_converse
.
on
(
'
statusInitialized
'
,
function
fetchOwnVCard
()
{
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
VCARD
,
_converse
.
domain
)
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
VCARD
,
_converse
.
domain
)
.
then
((
result
)
=>
{
.
then
((
result
)
=>
{
if
(
result
.
length
)
{
if
(
result
.
length
)
{
_converse
.
api
.
vcard
.
get
(
_converse
.
xmppstatus
)
_converse
.
api
.
vcard
.
update
(
_converse
.
xmppstatus
);
.
then
((
vcard
)
=>
_converse
.
xmppstatus
.
save
(
vcard
));
}})
}})
.
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
.
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
});
});
...
@@ -200,8 +173,17 @@
...
@@ -200,8 +173,17 @@
}
}
return
getVCard
(
_converse
,
jid
);
return
getVCard
(
_converse
,
jid
);
}
else
{
}
else
{
return
{}
;
return
Promise
.
resolve
({})
;
}
}
},
'
update
'
(
model
,
force
)
{
this
.
get
(
model
,
force
).
then
((
vcard
)
=>
{
model
.
save
(
_
.
extend
(
_
.
pick
(
vcard
,
[
'
fullname
'
,
'
url
'
,
'
image_type
'
,
'
image
'
,
'
vcard_updated
'
]),
{
'
vcard_updated
'
:
moment
().
format
()}
));
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
ERROR
));
}
}
}
}
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment