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
d4ceb6d3
Commit
d4ceb6d3
authored
Feb 07, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the ability to query for a disco identity
parent
2f19fd98
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
4 deletions
+87
-4
CHANGES.md
CHANGES.md
+6
-0
docs/source/developer_api.rst
docs/source/developer_api.rst
+34
-1
src/converse-disco.js
src/converse-disco.js
+47
-3
No files found.
CHANGES.md
View file @
d4ceb6d3
...
...
@@ -2,9 +2,15 @@
## 3.3.3 (Unreleased)
### Bugfixes
-
Attribute error when empty IQ stanza is returned for vCard query
### New features
-
XEP-0382 Spoiler Messages (currently only for private chats)
### API changes
-
New API method
`_converse.disco.getIdentity`
to check whether a JID has a given identity.
## 3.3.2 (2018-01-29)
### Bugfixes
...
...
docs/source/developer_api.rst
View file @
d4ceb6d3
...
...
@@ -437,6 +437,39 @@ The **disco** grouping
This grouping collects API functions related to `service discovery
<https://xmpp.org/extensions/xep-0030.html>`_.
getIdentity
~~~~~~~~~~~
Paramters:
* (String) category
* (String) type
* (String) entity JID
Get the identity (with the given category and type) for a given disco entity.
For example, when determining support for PEP (personal eventing protocol), you
want to know whether the user's own JID has an identity with
``category='pubsub'`` and ``type='pep'`` as explained in this section of
XEP-0163: https://xmpp.org/extensions/xep-0163.html#support
.. code-block:: javascript
converse.plugins.add('myplugin', {
initialize: function () {
_converse.api.disco.getIdentity('pubsub', 'pep', _converse.bare_jid).then(
function (identity) {
if (_.isNil(identity)) {
// The entity DOES NOT have this identity
} else {
// The entity DOES have this identity
}
}
).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}
});
supports
~~~~~~~~
...
...
@@ -450,7 +483,7 @@ Returns a `Promise` which, when resolved, returns a map/object with keys
converse.plugins.add('myplugin', {
initialize: function () {
_converse.api.disco.supports(
_converse.bare_jid, Strophe.NS.MAM
).then(
_converse.api.disco.supports(
Strophe.NS.MAM, _converse.bare_jid
).then(
function (value) {
// `value` is a map with two keys, `supported` and `feature`.
...
...
src/converse-disco.js
View file @
d4ceb6d3
...
...
@@ -65,6 +65,29 @@
},
getIdentity
(
category
,
type
)
{
/* Returns a Promise which resolves with a map indicating
* whether a given identity is provided.
*
* Parameters:
* (String) category - The identity category
* (String) type - The identity type
*/
const
entity
=
this
;
return
new
Promise
((
resolve
,
reject
)
=>
{
function
fulfillPromise
()
{
const
model
=
entity
.
identities
.
findWhere
({
'
category
'
:
category
,
'
type
'
:
type
});
resolve
(
model
);
}
entity
.
waitUntilFeaturesDiscovered
.
then
(
fulfillPromise
)
.
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
});
},
hasFeature
(
feature
)
{
/* Returns a Promise which resolves with a map indicating
* whether a given feature is supported.
...
...
@@ -130,8 +153,8 @@
_
.
forEach
(
stanza
.
querySelectorAll
(
'
identity
'
),
(
identity
)
=>
{
this
.
identities
.
create
({
'
category
'
:
identity
.
getAttribute
(
'
category
'
),
'
type
'
:
stanza
.
getAttribute
(
'
type
'
),
'
name
'
:
stanza
.
getAttribute
(
'
name
'
)
'
type
'
:
identity
.
getAttribute
(
'
type
'
),
'
name
'
:
identity
.
getAttribute
(
'
name
'
)
});
});
if
(
stanza
.
querySelector
(
'
feature[var="
'
+
Strophe
.
NS
.
DISCO_ITEMS
+
'
"]
'
))
{
...
...
@@ -245,7 +268,28 @@
return
_converse
.
api
.
waitUntil
(
'
discoInitialized
'
).
then
(()
=>
{
const
entity
=
_converse
.
api
.
disco
.
entities
.
get
(
entity_jid
,
true
);
return
entity
.
hasFeature
(
feature
);
});
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
},
'
getIdentity
'
(
category
,
type
,
entity_jid
)
{
/* Returns a Promise which resolves with a map indicating
* whether an identity with a given type is provided by
* the entity.
*
* Parameters:
* (String) category - The identity category.
* In the XML stanza, this is the `category`
* attribute of the `<identity>` element.
* For example: 'pubsub'
* (String) type - The identity type.
* In the XML stanza, this is the `type`
* attribute of the `<identity>` element.
* For example: 'pep'
*/
return
_converse
.
api
.
waitUntil
(
'
discoInitialized
'
).
then
(()
=>
{
const
entity
=
_converse
.
api
.
disco
.
entities
.
get
(
entity_jid
,
true
);
return
entity
.
getIdentity
(
category
,
type
);
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
}
}
});
...
...
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