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
866f2737
Commit
866f2737
authored
Sep 02, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More JSDoc docstrings for API methods
parent
5f16babe
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
1703 additions
and
408 deletions
+1703
-408
dist/converse.js
dist/converse.js
+1025
-184
docs/source/developer_api.rst
docs/source/developer_api.rst
+12
-18
docs/source/jsdoc_intro.md
docs/source/jsdoc_intro.md
+8
-22
spec/disco.js
spec/disco.js
+3
-2
spec/presence.js
spec/presence.js
+5
-5
src/converse-chatboxes.js
src/converse-chatboxes.js
+10
-6
src/converse-chatview.js
src/converse-chatview.js
+22
-0
src/converse-core.js
src/converse-core.js
+43
-38
src/converse-disco.js
src/converse-disco.js
+156
-87
src/converse-mam.js
src/converse-mam.js
+167
-19
src/converse-muc-views.js
src/converse-muc-views.js
+41
-1
src/converse-muc.js
src/converse-muc.js
+98
-20
src/converse-push.js
src/converse-push.js
+1
-1
src/converse-roster.js
src/converse-roster.js
+48
-0
src/converse-vcard.js
src/converse-vcard.js
+64
-5
No files found.
dist/converse.js
View file @
866f2737
This diff is collapsed.
Click to expand it.
docs/source/developer_api.rst
View file @
866f2737
...
@@ -303,7 +303,6 @@ room under the ``with`` key.
...
@@ -303,7 +303,6 @@ room under the ``with`` key.
.. code-block:: javascript
.. code-block:: javascript
converse.plugins.add('myplugin', {
converse.plugins.add('myplugin', {
initialize: function () {
initialize: function () {
...
@@ -541,24 +540,19 @@ Returns a `Promise` which, when resolved, returns a map/object with keys
...
@@ -541,24 +540,19 @@ Returns a `Promise` which, when resolved, returns a map/object with keys
converse.plugins.add('myplugin', {
converse.plugins.add('myplugin', {
initialize: function () {
initialize: function () {
_converse.api.disco.supports(Strophe.NS.MAM, _converse.bare_jid).then(
_converse.api.disco.supports(Strophe.NS.MAM, _converse.bare_jid)
function (value) {
.then(value => {
// `value` is a map with two keys, `supported` and `feature`.
// `value` is a map with two keys, `supported` and `feature`.
if (value.supported) {
if (value.supported) {
// The feature is supported
// The feature is supported
} else {
} else {
// The feature is not supported
// The feature is not supported
}
},
function () { // Error
_converse.log(
"Error or timeout while checking for feature support",
Strophe.LogLevel.ERROR
);
}
}
).catch((msg) => {
}).catch(() => {
_converse.log(msg, Strophe.LogLevel.FATAL);
_converse.log(
"Error or timeout while checking for feature support",
Strophe.LogLevel.ERROR
);
});
});
}
}
});
});
...
...
docs/source/jsdoc_intro.md
View file @
866f2737
...
@@ -23,29 +23,15 @@ closured object.
...
@@ -23,29 +23,15 @@ closured object.
## API Namespaces
## API Namespaces
The Converse API
is often broken up into different logical "namespaces" (for
The Converse API
(private and public) makes use of namespaces to logically
example
`converse.plugins`
or
`converse.contacts`
)
.
group relevant methods
.
There are some exceptions to this, like
`converse.initialize`
, which aren't
So, for example, all the XEP-0030 service discovery methods are under the
namespaces but single methods
.
{@link
\_
converse.api.disco} namespace, in the [private API]{@link
\_
converse.api}
.
The namespaces logically group methods, such as standardised accessors and
Which means that you access it via
`_converse.api.disco`
.
mutators:
*
.get
Namespaces can be nested. So the {@link
\_
converse.api.disco} namespace
*
.set
namespace has {@link
\_
converse.api.disco.own} as a nested namespace.
*
.add
*
.remove
So for example, to get a contact, you would do the following:
_converse.api.contacts.get('jid@example.com');
To get multiple contacts, just pass in an array of jids:
_converse.api.contacts.get(['jid1@example.com', 'jid2@example.com']);
To get all contacts, simply call
``get``
without any jids:
_converse.api.contacts.get();
Not all methods are however within a namespace. For example {@link converse.initialize}.
spec/disco.js
View file @
866f2737
...
@@ -164,8 +164,9 @@
...
@@ -164,8 +164,9 @@
'
name
'
:
'
Music from the time of Shakespeare
'
'
name
'
:
'
Music from the time of Shakespeare
'
});
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
stanza
));
return
test_utils
.
waitUntil
(()
=>
_converse
.
disco_entities
);
entities
=
_converse
.
disco_entities
;
}).
then
(()
=>
{
const
entities
=
_converse
.
disco_entities
;
expect
(
entities
.
length
).
toBe
(
2
);
// We have an extra entity, which is the user's JID
expect
(
entities
.
length
).
toBe
(
2
);
// We have an extra entity, which is the user's JID
expect
(
entities
.
get
(
_converse
.
domain
).
items
.
length
).
toBe
(
3
);
expect
(
entities
.
get
(
_converse
.
domain
).
items
.
length
).
toBe
(
3
);
expect
(
_
.
includes
(
entities
.
get
(
_converse
.
domain
).
items
.
pluck
(
'
jid
'
),
'
people.shakespeare.lit
'
)).
toBeTruthy
();
expect
(
_
.
includes
(
entities
.
get
(
_converse
.
domain
).
items
.
pluck
(
'
jid
'
),
'
people.shakespeare.lit
'
)).
toBeTruthy
();
...
...
spec/presence.js
View file @
866f2737
...
@@ -47,7 +47,7 @@
...
@@ -47,7 +47,7 @@
"
<presence xmlns='jabber:client'>
"
+
"
<presence xmlns='jabber:client'>
"
+
"
<status>Hello world</status>
"
+
"
<status>Hello world</status>
"
+
"
<priority>0</priority>
"
+
"
<priority>0</priority>
"
+
"
<c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://conversejs.org' ver='
ggltNSI5YG/7dFKB57Bk2dRYRU0
='/>
"
+
"
<c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://conversejs.org' ver='
K7kn/M6VtmdMyo61pgn/jkZlax8
='/>
"
+
"
</presence>
"
"
</presence>
"
);
);
_converse
.
priority
=
2
;
_converse
.
priority
=
2
;
...
@@ -57,7 +57,7 @@
...
@@ -57,7 +57,7 @@
"
<show>away</show>
"
+
"
<show>away</show>
"
+
"
<status>Going jogging</status>
"
+
"
<status>Going jogging</status>
"
+
"
<priority>2</priority>
"
+
"
<priority>2</priority>
"
+
"
<c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://conversejs.org' ver='
ggltNSI5YG/7dFKB57Bk2dRYRU0
='/>
"
+
"
<c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://conversejs.org' ver='
K7kn/M6VtmdMyo61pgn/jkZlax8
='/>
"
+
"
</presence>
"
"
</presence>
"
);
);
...
@@ -68,7 +68,7 @@
...
@@ -68,7 +68,7 @@
"
<show>dnd</show>
"
+
"
<show>dnd</show>
"
+
"
<status>Doing taxes</status>
"
+
"
<status>Doing taxes</status>
"
+
"
<priority>0</priority>
"
+
"
<priority>0</priority>
"
+
"
<c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://conversejs.org' ver='
ggltNSI5YG/7dFKB57Bk2dRYRU0
='/>
"
+
"
<c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://conversejs.org' ver='
K7kn/M6VtmdMyo61pgn/jkZlax8
='/>
"
+
"
</presence>
"
"
</presence>
"
);
);
}));
}));
...
@@ -97,7 +97,7 @@
...
@@ -97,7 +97,7 @@
.
toBe
(
"
<presence xmlns='jabber:client'>
"
+
.
toBe
(
"
<presence xmlns='jabber:client'>
"
+
"
<status>My custom status</status>
"
+
"
<status>My custom status</status>
"
+
"
<priority>0</priority>
"
+
"
<priority>0</priority>
"
+
"
<c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://conversejs.org' ver='
ggltNSI5YG/7dFKB57Bk2dRYRU0
='/>
"
+
"
<c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://conversejs.org' ver='
K7kn/M6VtmdMyo61pgn/jkZlax8
='/>
"
+
"
</presence>
"
)
"
</presence>
"
)
return
test_utils
.
waitUntil
(
function
()
{
return
test_utils
.
waitUntil
(
function
()
{
...
@@ -113,7 +113,7 @@
...
@@ -113,7 +113,7 @@
modal
.
el
.
querySelector
(
'
[type="submit"]
'
).
click
();
modal
.
el
.
querySelector
(
'
[type="submit"]
'
).
click
();
expect
(
_converse
.
connection
.
send
.
calls
.
mostRecent
().
args
[
0
].
toLocaleString
())
expect
(
_converse
.
connection
.
send
.
calls
.
mostRecent
().
args
[
0
].
toLocaleString
())
.
toBe
(
"
<presence xmlns='jabber:client'><show>dnd</show><status>My custom status</status><priority>0</priority>
"
+
.
toBe
(
"
<presence xmlns='jabber:client'><show>dnd</show><status>My custom status</status><priority>0</priority>
"
+
"
<c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://conversejs.org' ver='
ggltNSI5YG/7dFKB57Bk2dRYRU0
='/>
"
+
"
<c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='https://conversejs.org' ver='
K7kn/M6VtmdMyo61pgn/jkZlax8
='/>
"
+
"
</presence>
"
)
"
</presence>
"
)
done
();
done
();
});
});
...
...
src/converse-chatboxes.js
View file @
866f2737
...
@@ -906,11 +906,17 @@
...
@@ -906,11 +906,17 @@
/************************ BEGIN API ************************/
/************************ BEGIN API ************************/
_
.
extend
(
_converse
.
api
,
{
_
.
extend
(
_converse
.
api
,
{
/**
/**
* The "chats"
grouping
(used for one-on-one chats)
* The "chats"
namespace
(used for one-on-one chats)
*
*
* @namespace
* @namespace _converse.api.chats
* @memberOf _converse.api
*/
*/
'
chats
'
:
{
'
chats
'
:
{
/**
* @method _converse.api.chats.create
* @param {string|string[]} jid|jids An jid or array of jids
* @param {object} attrs An object containing configuration attributes.
*/
'
create
'
(
jids
,
attrs
)
{
'
create
'
(
jids
,
attrs
)
{
if
(
_
.
isUndefined
(
jids
))
{
if
(
_
.
isUndefined
(
jids
))
{
_converse
.
log
(
_converse
.
log
(
...
@@ -939,8 +945,7 @@
...
@@ -939,8 +945,7 @@
/**
/**
* Opens a new one-on-one chat.
* Opens a new one-on-one chat.
*
*
* @function
* @method _converse.api.chats.open
*
* @param {String|string[]} name - e.g. 'buddy@example.com' or ['buddy1@example.com', 'buddy2@example.com']
* @param {String|string[]} name - e.g. 'buddy@example.com' or ['buddy1@example.com', 'buddy2@example.com']
* @returns {Promise} Promise which resolves with the Backbone.Model representing the chat.
* @returns {Promise} Promise which resolves with the Backbone.Model representing the chat.
*
*
...
@@ -991,8 +996,7 @@
...
@@ -991,8 +996,7 @@
/**
/**
* Returns a chat model. The chat should already be open.
* Returns a chat model. The chat should already be open.
*
*
* @function
* @method _converse.api.chats.get
*
* @param {String|string[]} name - e.g. 'buddy@example.com' or ['buddy1@example.com', 'buddy2@example.com']
* @param {String|string[]} name - e.g. 'buddy@example.com' or ['buddy1@example.com', 'buddy2@example.com']
* @returns {Backbone.Model}
* @returns {Backbone.Model}
*
*
...
...
src/converse-chatview.js
View file @
866f2737
...
@@ -1275,7 +1275,29 @@
...
@@ -1275,7 +1275,29 @@
/************************ BEGIN API ************************/
/************************ BEGIN API ************************/
_
.
extend
(
_converse
.
api
,
{
_
.
extend
(
_converse
.
api
,
{
/**
* The "chatview" namespace groups methods pertaining to views
* for one-on-one chats.
*
* @namespace _converse.api.chatviews
* @memberOf _converse.api
*/
'
chatviews
'
:
{
'
chatviews
'
:
{
/**
* Get the view of an already open chat.
*
* @method _converse.api.chatviews.get
* @returns {ChatBoxView} A [Backbone.View](http://backbonejs.org/#View) instance.
* The chat should already be open, otherwise `undefined` will be returned.
*
* @example
* // To return a single view, provide the JID of the contact:
* _converse.api.chatviews.get('buddy@example.com')
*
* @example
* // To return an array of views, provide an array of JIDs:
* _converse.api.chatviews.get(['buddy1@example.com', 'buddy2@example.com'])
*/
'
get
'
(
jids
)
{
'
get
'
(
jids
)
{
if
(
_
.
isUndefined
(
jids
))
{
if
(
_
.
isUndefined
(
jids
))
{
_converse
.
log
(
_converse
.
log
(
...
...
src/converse-core.js
View file @
866f2737
...
@@ -59,9 +59,8 @@
...
@@ -59,9 +59,8 @@
};
};
/**
/**
* A private, closured object containing the private api (via
* A private, closured object containing the private api (via `_converse.api`)
* `_converse.api`) as well as private methods and internal
* as well as private methods and internal data-structures.
* data-structures.
*
*
* @namespace _converse
* @namespace _converse
*/
*/
...
@@ -1234,7 +1233,7 @@
...
@@ -1234,7 +1233,7 @@
/**
/**
* ### The private API
* ### The private API
*
*
* The private API methods are only accessible via the closured
`_converse`
* The private API methods are only accessible via the closured
{@link _converse}
* object, which is only available to plugins.
* object, which is only available to plugins.
*
*
* These methods are kept private (i.e. not global) because they may return
* These methods are kept private (i.e. not global) because they may return
...
@@ -1273,10 +1272,10 @@
...
@@ -1273,10 +1272,10 @@
/**
/**
* Lets you emit (i.e. trigger) events, which can be listened to via
* Lets you emit (i.e. trigger) events, which can be listened to via
*
`_converse.api.listen.on` or `_converse.api.listen.once`
*
{@link _converse.api.listen.on} or {@link _converse.api.listen.once}
* (see [_converse.api.listen](http://localhost:8000/docs/html/api/-_converse.api.listen.html)).
* (see [_converse.api.listen](http://localhost:8000/docs/html/api/-_converse.api.listen.html)).
*
*
* @method _converse.api.
connection.
emit
* @method _converse.api.emit
*/
*/
'
emit
'
()
{
'
emit
'
()
{
_converse
.
emit
.
apply
(
_converse
,
arguments
);
_converse
.
emit
.
apply
(
_converse
,
arguments
);
...
@@ -1395,7 +1394,9 @@
...
@@ -1395,7 +1394,9 @@
},
},
/**
/**
* This grouping allows access to the configuration settings of Converse.
* This grouping allows access to the
* [configuration settings](/docs/html/configuration.html#configuration-settings)
* of Converse.
*
*
* @namespace _converse.api.settings
* @namespace _converse.api.settings
* @memberOf _converse.api
* @memberOf _converse.api
...
@@ -1436,7 +1437,7 @@
...
@@ -1436,7 +1437,7 @@
/**
/**
* Set one or many configuration settings.
* Set one or many configuration settings.
*
*
* Note, this is not an alternative to calling
`converse.initialize`
, which still needs
* Note, this is not an alternative to calling
{@link converse.initialize}
, which still needs
* to be called. Generally, you'd use this method after Converse is already
* to be called. Generally, you'd use this method after Converse is already
* running and you want to change the configuration on-the-fly.
* running and you want to change the configuration on-the-fly.
*
*
...
@@ -1464,8 +1465,7 @@
...
@@ -1464,8 +1465,7 @@
/**
/**
* Converse and its plugins emit various events which you can listen to via the
* Converse and its plugins emit various events which you can listen to via the
* [_converse.api.listen](http://localhost:8000/docs/html/api/-_converse.api.listen.html)
* {@link _converse.api.listen} namespace.
* namespace.
*
*
* Some of these events are also available as [ES2015 Promises](http://es6-features.org/#PromiseUsage)
* Some of these events are also available as [ES2015 Promises](http://es6-features.org/#PromiseUsage)
* although not all of them could logically act as promises, since some events
* although not all of them could logically act as promises, since some events
...
@@ -1494,14 +1494,14 @@
...
@@ -1494,14 +1494,14 @@
/**
/**
* By calling `promises.add`, a new [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
* By calling `promises.add`, a new [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
* is made available for other code or plugins to depend on via the
* is made available for other code or plugins to depend on via the
*
`_converse.api.waitUntil`
method.
*
{@link _converse.api.waitUntil}
method.
*
*
* Generally, it's the responsibility of the plugin which adds the promise to
* Generally, it's the responsibility of the plugin which adds the promise to
* also resolve it.
* also resolve it.
*
*
* This is done by calling
`_converse.api.emit`
, which not only resolves the
* This is done by calling
{@link _converse.api.emit}
, which not only resolves the
* promise, but also emits an event with the same name (which can be listened to
* promise, but also emits an event with the same name (which can be listened to
* via
`_converse.api.listen`
).
* via
{@link _converse.api.listen}
).
*
*
* @method _converse.api.promises.add
* @method _converse.api.promises.add
* @param {string|array} [name|names] The name or an array of names for the promise(s) to be added
* @param {string|array} [name|names] The name or an array of names for the promise(s) to be added
...
@@ -1550,7 +1550,7 @@
...
@@ -1550,7 +1550,7 @@
'
listen
'
:
{
'
listen
'
:
{
/**
/**
* Lets you listen to an event exactly once.
* Lets you listen to an event exactly once.
*
* @method _converse.api.listen.once
* @method _converse.api.listen.once
* @param {string} name The event's name
* @param {string} name The event's name
* @param {function} callback The callback method to be called when the event is emitted.
* @param {function} callback The callback method to be called when the event is emitted.
...
@@ -1563,7 +1563,7 @@
...
@@ -1563,7 +1563,7 @@
* Lets you subscribe to an event.
* Lets you subscribe to an event.
*
*
* Every time the event fires, the callback method specified by `callback` will be called.
* Every time the event fires, the callback method specified by `callback` will be called.
*
* @method _converse.api.listen.on
* @method _converse.api.listen.on
* @param {string} name The event's name
* @param {string} name The event's name
* @param {function} callback The callback method to be called when the event is emitted.
* @param {function} callback The callback method to be called when the event is emitted.
...
@@ -1573,10 +1573,10 @@
...
@@ -1573,10 +1573,10 @@
'
on
'
:
_converse
.
on
.
bind
(
_converse
),
'
on
'
:
_converse
.
on
.
bind
(
_converse
),
/**
/**
* To stop listening to an event, you can use the `
`not`
` method.
* To stop listening to an event, you can use the `
not
` method.
*
*
* Every time the event fires, the callback method specified by `callback` will be called.
* Every time the event fires, the callback method specified by `callback` will be called.
*
* @method _converse.api.listen.not
* @method _converse.api.listen.not
* @param {string} name The event's name
* @param {string} name The event's name
* @param {function} callback The callback method that is to no longer be called when the event fires
* @param {function} callback The callback method that is to no longer be called when the event fires
...
@@ -1588,7 +1588,7 @@
...
@@ -1588,7 +1588,7 @@
* Subscribe to an incoming stanza
* Subscribe to an incoming stanza
*
*
* Every a matched stanza is received, the callback method specified by `callback` will be called.
* Every a matched stanza is received, the callback method specified by `callback` will be called.
*
* @method _converse.api.listen.stanza
* @method _converse.api.listen.stanza
* @param {string} name The stanza's name
* @param {string} name The stanza's name
* @param {object} options Matching options
* @param {object} options Matching options
...
@@ -1619,6 +1619,7 @@
...
@@ -1619,6 +1619,7 @@
*
*
* @method _converse.api.waitUntil
* @method _converse.api.waitUntil
* @param {string} name The name of the promise
* @param {string} name The name of the promise
* @returns {Promise}
*/
*/
'
waitUntil
'
(
name
)
{
'
waitUntil
'
(
name
)
{
const
promise
=
_converse
.
promises
[
name
];
const
promise
=
_converse
.
promises
[
name
];
...
@@ -1627,14 +1628,23 @@
...
@@ -1627,14 +1628,23 @@
}
}
return
promise
;
return
promise
;
},
},
/**
/**
*
Send a stanza
*
Allows you to send XML stanzas.
*
*
* @method _converse.api.send
* @method _converse.api.send
* @example
* const msg = converse.env.$msg({
* 'from': 'juliet@example.com/balcony',
* 'to': 'romeo@example.net',
* 'type':'chat'
* });
* _converse.api.send(msg);
*/
*/
'
send
'
(
stanza
)
{
'
send
'
(
stanza
)
{
_converse
.
connection
.
send
(
stanza
);
_converse
.
connection
.
send
(
stanza
);
},
},
/**
/**
* Send an IQ stanza and receive a promise
* Send an IQ stanza and receive a promise
*
*
...
@@ -1649,33 +1659,28 @@
...
@@ -1649,33 +1659,28 @@
}
}
};
};
/**
* The Public API
* @namespace window
*/
/**
/**
* ### The Public API
*
* This namespace contains public API methods which are are
* This namespace contains public API methods which are are
* accessible on the global
window.converse
object.
* accessible on the global
`converse`
object.
* They are public, because any JavaScript in the
* They are public, because any JavaScript in the
* page can call them. Public methods therefore don’t expose any sensitive
* page can call them. Public methods therefore don’t expose any sensitive
* or closured data. To do that, you’ll need to create a plugin, which has
* or closured data. To do that, you’ll need to create a plugin, which has
* access to the private API method.
* access to the private API method.
*
*
* @namespace window.converse
* @namespace converse
* @memberOf window
*/
*/
window
.
converse
=
{
const
converse
=
{
/**
/**
* Public API method which initializes Converse.
* Public API method which initializes Converse.
* This method must always be called when using Converse.
* This method must always be called when using Converse.
*
*
* @memberOf
window.
converse
* @memberOf converse
* @method initialize
* @method initialize
* @param {object} config A map of [configuration-settings](https://conversejs.org/docs/html/configuration.html#configuration-settings).
* @param {object} config A map of [configuration-settings](https://conversejs.org/docs/html/configuration.html#configuration-settings).
*
*
* @example
* @example
*
* converse.initialize({
* converse.initialize({
* allow_otr: true,
* allow_otr: true,
* auto_list_rooms: false,
* auto_list_rooms: false,
...
@@ -1698,16 +1703,15 @@
...
@@ -1698,16 +1703,15 @@
* Exposes methods for adding and removing plugins. You'll need to write a plugin
* Exposes methods for adding and removing plugins. You'll need to write a plugin
* if you want to have access to the private API methods defined further down below.
* if you want to have access to the private API methods defined further down below.
*
*
* For more information on plugins, read the
section :ref:`writing-a-plugin`
.
* For more information on plugins, read the
documentation on [writing a plugin](/docs/html/plugin_development.html)
.
*
*
* @
property {object} window.converse
* @
namespace plugins
* @memberOf
window.
converse
* @memberOf converse
*/
*/
'
plugins
'
:
{
'
plugins
'
:
{
/** Registers a new plugin.
/** Registers a new plugin.
*
*
* @memberOf window.converse.plugins
* @method converse.plugins.add
* @method add
* @param {string} name The name of the plugin
* @param {string} name The name of the plugin
* @param {object} plugin The plugin object
* @param {object} plugin The plugin object
*
*
...
@@ -1740,7 +1744,7 @@
...
@@ -1740,7 +1744,7 @@
},
},
/**
/**
* Utility methods and globals from bundled 3rd party libraries.
* Utility methods and globals from bundled 3rd party libraries.
* @memberOf
window.
converse
* @memberOf converse
*
*
* @property {function} converse.env.$build - Creates a Strophe.Builder, for creating stanza objects.
* @property {function} converse.env.$build - Creates a Strophe.Builder, for creating stanza objects.
* @property {function} converse.env.$iq - Creates a Strophe.Builder with an <iq/> element as the root.
* @property {function} converse.env.$iq - Creates a Strophe.Builder with an <iq/> element as the root.
...
@@ -1772,6 +1776,7 @@
...
@@ -1772,6 +1776,7 @@
'
utils
'
:
u
'
utils
'
:
u
}
}
};
};
window
.
converse
=
converse
;
window
.
dispatchEvent
(
new
CustomEvent
(
'
converse-loaded
'
));
window
.
dispatchEvent
(
new
CustomEvent
(
'
converse-loaded
'
));
return
window
.
converse
;
return
converse
;
}));
}));
src/converse-disco.js
View file @
866f2737
This diff is collapsed.
Click to expand it.
src/converse-mam.js
View file @
866f2737
This diff is collapsed.
Click to expand it.
src/converse-muc-views.js
View file @
866f2737
...
@@ -1951,7 +1951,6 @@
...
@@ -1951,7 +1951,6 @@
}
}
/************************ BEGIN Event Handlers ************************/
/************************ BEGIN Event Handlers ************************/
_converse
.
on
(
'
chatBoxesInitialized
'
,
()
=>
{
_converse
.
on
(
'
chatBoxesInitialized
'
,
()
=>
{
const
that
=
_converse
.
chatboxviews
;
const
that
=
_converse
.
chatboxviews
;
_converse
.
chatboxes
.
on
(
'
add
'
,
item
=>
{
_converse
.
chatboxes
.
on
(
'
add
'
,
item
=>
{
...
@@ -1983,6 +1982,47 @@
...
@@ -1983,6 +1982,47 @@
}
}
_converse
.
on
(
'
reconnected
'
,
reconnectToChatRooms
);
_converse
.
on
(
'
reconnected
'
,
reconnectToChatRooms
);
/************************ END Event Handlers ************************/
/************************ END Event Handlers ************************/
/************************ BEGIN API ************************/
_
.
extend
(
_converse
.
api
,
{
/**
* The "roomviews" namespace groups methods relevant to chatroom
* (aka groupchats) views.
*
* @namespace _converse.api.roomviews
* @memberOf _converse.api
*/
'
roomviews
'
:
{
/**
* Lets you close open chatrooms.
*
* You can call this method without any arguments to close
* all open chatrooms, or you can specify a single JID or
* an array of JIDs.
*
* @method _converse.api.roomviews.close
* @param {(String[]|String)} jids The JID or array of JIDs of the chatroom(s)
*/
'
close
'
(
jids
)
{
if
(
_
.
isUndefined
(
jids
))
{
_converse
.
chatboxviews
.
each
(
function
(
view
)
{
if
(
view
.
is_chatroom
&&
view
.
model
)
{
view
.
close
();
}
});
}
else
if
(
_
.
isString
(
jids
))
{
const
view
=
_converse
.
chatboxviews
.
get
(
jids
);
if
(
view
)
{
view
.
close
();
}
}
else
{
_
.
each
(
jids
,
function
(
jid
)
{
const
view
=
_converse
.
chatboxviews
.
get
(
jid
);
if
(
view
)
{
view
.
close
();
}
});
}
}
}
});
}
}
});
});
}));
}));
src/converse-muc.js
View file @
866f2737
...
@@ -423,7 +423,7 @@
...
@@ -423,7 +423,7 @@
const
jid
=
Strophe
.
getBareJidFromJid
(
groupchat
);
const
jid
=
Strophe
.
getBareJidFromJid
(
groupchat
);
return
jid
+
(
nick
!==
null
?
`/
${
nick
}
`
:
""
);
return
jid
+
(
nick
!==
null
?
`/
${
nick
}
`
:
""
);
},
},
sendChatState
()
{
sendChatState
()
{
/* Sends a message with the status of the user in this chat session
/* Sends a message with the status of the user in this chat session
* as taken from the 'chat_state' attribute of the chat box.
* as taken from the 'chat_state' attribute of the chat box.
...
@@ -956,7 +956,7 @@
...
@@ -956,7 +956,7 @@
this
.
save
(
'
connection_status
'
,
converse
.
ROOMSTATUS
.
CONNECTED
);
this
.
save
(
'
connection_status
'
,
converse
.
ROOMSTATUS
.
CONNECTED
);
}
}
},
},
onOwnPresence
(
pres
)
{
onOwnPresence
(
pres
)
{
/* Handles a received presence relating to the current
/* Handles a received presence relating to the current
* user.
* user.
...
@@ -1288,25 +1288,26 @@
...
@@ -1288,25 +1288,26 @@
/************************ BEGIN API ************************/
/************************ BEGIN API ************************/
// We extend the default converse.js API to add methods specific to MUC groupchats.
// We extend the default converse.js API to add methods specific to MUC groupchats.
_
.
extend
(
_converse
.
api
,
{
_
.
extend
(
_converse
.
api
,
{
/**
* The "rooms" namespace groups methods relevant to chatrooms
* (aka groupchats).
*
* @namespace _converse.api.rooms
* @memberOf _converse.api
*/
'
rooms
'
:
{
'
rooms
'
:
{
'
close
'
(
jids
)
{
/**
if
(
_
.
isUndefined
(
jids
))
{
* Creates a new MUC chatroom (aka groupchat)
// FIXME: can't access views here
*
_converse
.
chatboxviews
.
each
(
function
(
view
)
{
* Similar to {@link _converse.api.rooms.open}, but creates
if
(
view
.
is_chatroom
&&
view
.
model
)
{
* the chatroom in the background (i.e. doesn't cause a
view
.
close
();
* view to open).
}
*
});
* @method _converse.api.rooms.create
}
else
if
(
_
.
isString
(
jids
))
{
* @param {(string[]|string)} jid|jids The JID or array of
const
view
=
_converse
.
chatboxviews
.
get
(
jids
);
* JIDs of the chatroom(s) to create
if
(
view
)
{
view
.
close
();
}
* @param {object} [attrs] attrs The room attributes
}
else
{
*/
_
.
each
(
jids
,
function
(
jid
)
{
const
view
=
_converse
.
chatboxviews
.
get
(
jid
);
if
(
view
)
{
view
.
close
();
}
});
}
},
'
create
'
(
jids
,
attrs
)
{
'
create
'
(
jids
,
attrs
)
{
if
(
_
.
isString
(
attrs
))
{
if
(
_
.
isString
(
attrs
))
{
attrs
=
{
'
nick
'
:
attrs
};
attrs
=
{
'
nick
'
:
attrs
};
...
@@ -1327,6 +1328,60 @@
...
@@ -1327,6 +1328,60 @@
return
_
.
map
(
jids
,
_
.
partial
(
createChatRoom
,
_
,
attrs
));
return
_
.
map
(
jids
,
_
.
partial
(
createChatRoom
,
_
,
attrs
));
},
},
/**
* Opens a MUC chatroom (aka groupchat)
*
* Similar to {@link _converse.api.chats.open}, but for groupchats.
*
* @method _converse.api.rooms.open
* @param {string} jid The room JID or JIDs (if not specified, all
* currently open rooms will be returned).
* @param {string} attrs A map containing any extra room attributes.
* @param {string} [attrs.nick] The current user's nickname for the MUC
* @param {boolean} [attrs.auto_configure] A boolean, indicating
* whether the room should be configured automatically or not.
* If set to `true`, then it makes sense to pass in configuration settings.
* @param {object} [attrs.roomconfig] A map of configuration settings to be used when the room gets
* configured automatically. Currently it doesn't make sense to specify
* `roomconfig` values if `auto_configure` is set to `false`.
* For a list of configuration values that can be passed in, refer to these values
* in the [XEP-0045 MUC specification](http://xmpp.org/extensions/xep-0045.html#registrar-formtype-owner).
* The values should be named without the `muc#roomconfig_` prefix.
* @param {boolean} [attrs.maximize] A boolean, indicating whether minimized rooms should also be
* maximized, when opened. Set to `false` by default.
* @param {boolean} [attrs.bring_to_foreground] A boolean indicating whether the room should be
* brought to the foreground and therefore replace the currently shown chat.
* If there is no chat currently open, then this option is ineffective.
*
* @example
* this._converse.api.rooms.open('group@muc.example.com')
*
* @example
* // To return an array of rooms, provide an array of room JIDs:
* _converse.api.rooms.open(['group1@muc.example.com', 'group2@muc.example.com'])
*
* @example
* // To setup a custom nickname when joining the room, provide the optional nick argument:
* _converse.api.rooms.open('group@muc.example.com', {'nick': 'mycustomnick'})
*
* @example
* // For example, opening a room with a specific default configuration:
* _converse.api.rooms.open(
* 'myroom@conference.example.org',
* { 'nick': 'coolguy69',
* 'auto_configure': true,
* 'roomconfig': {
* 'changesubject': false,
* 'membersonly': true,
* 'persistentroom': true,
* 'publicroom': true,
* 'roomdesc': 'Comfy room for hanging out',
* 'whois': 'anyone'
* }
* },
* true
* );
*/
'
open
'
(
jids
,
attrs
)
{
'
open
'
(
jids
,
attrs
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
_converse
.
api
.
waitUntil
(
'
chatBoxesFetched
'
).
then
(()
=>
{
_converse
.
api
.
waitUntil
(
'
chatBoxesFetched
'
).
then
(()
=>
{
...
@@ -1343,6 +1398,29 @@
...
@@ -1343,6 +1398,29 @@
});
});
},
},
/**
* Returns an object representing a MUC chatroom (aka groupchat)
*
* @method _converse.api.rooms.get
* @param {string} [jid] The room JID (if not specified, all rooms will be returned).
* @param {object} attrs A map containing any extra room attributes For example, if you want
* to specify the nickname, use `{'nick': 'bloodninja'}`. Previously (before
* version 1.0.7, the second parameter only accepted the nickname (as a string
* value). This is currently still accepted, but then you can't pass in any
* other room attributes. If the nickname is not specified then the node part of
* the user's JID will be used.
* @param {boolean} create A boolean indicating whether the room should be created
* if not found (default: `false`)
* @example
* _converse.api.waitUntil('roomsAutoJoined').then(() => {
* const create_if_not_found = true;
* _converse.api.rooms.get(
* 'group@muc.example.com',
* {'nick': 'dread-pirate-roberts'},
* create_if_not_found
* )
* });
*/
'
get
'
(
jids
,
attrs
,
create
)
{
'
get
'
(
jids
,
attrs
,
create
)
{
if
(
_
.
isString
(
attrs
))
{
if
(
_
.
isString
(
attrs
))
{
attrs
=
{
'
nick
'
:
attrs
};
attrs
=
{
'
nick
'
:
attrs
};
...
...
src/converse-push.js
View file @
866f2737
...
@@ -36,7 +36,7 @@
...
@@ -36,7 +36,7 @@
}
}
Promise
.
all
([
Promise
.
all
([
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
PUSH
,
_converse
.
bare_jid
)
_converse
.
api
.
disco
.
supports
(
Strophe
.
NS
.
PUSH
,
_converse
.
bare_jid
)
]).
then
(
(
result
)
=>
{
]).
then
(
result
=>
{
if
(
!
result
[
0
].
length
&&
!
result
[
1
].
length
)
{
if
(
!
result
[
0
].
length
&&
!
result
[
1
].
length
)
{
return
_converse
.
log
(
return
_converse
.
log
(
`Not disabling push app server "
${
push_app_server
.
jid
}
", no disco support from your server.`
,
`Not disabling push app server "
${
push_app_server
.
jid
}
", no disco support from your server.`
,
...
...
src/converse-roster.js
View file @
866f2737
...
@@ -864,7 +864,43 @@
...
@@ -864,7 +864,43 @@
// API methods only available to plugins
// API methods only available to plugins
_
.
extend
(
_converse
.
api
,
{
_
.
extend
(
_converse
.
api
,
{
/**
* @namespace _converse.api.contacts
* @memberOf _converse.api
*/
'
contacts
'
:
{
'
contacts
'
:
{
/**
* This method is used to retrieve roster contacts.
*
* @method _converse.api.contacts.get
* @params {(string[]|string)} jid|jids The JID or JIDs of
* the contacts to be returned.
* @returns {(RosterContact[]|RosterContact)} [Backbone.Model](http://backbonejs.org/#Model)
* (or an array of them) representing the contact.
*
* @example
* // Fetch a single contact
* _converse.api.listen.on('rosterContactsFetched', function () {
* const contact = _converse.api.contacts.get('buddy@example.com')
* // ...
* });
*
* @example
* // To get multiple contacts, pass in an array of JIDs:
* _converse.api.listen.on('rosterContactsFetched', function () {
* const contacts = _converse.api.contacts.get(
* ['buddy1@example.com', 'buddy2@example.com']
* )
* // ...
* });
*
* @example
* // To return all contacts, simply call ``get`` without any parameters:
* _converse.api.listen.on('rosterContactsFetched', function () {
* const contacts = _converse.api.contacts.get();
* // ...
* });
*/
'
get
'
(
jids
)
{
'
get
'
(
jids
)
{
const
_getter
=
function
(
jid
)
{
const
_getter
=
function
(
jid
)
{
return
_converse
.
roster
.
get
(
Strophe
.
getBareJidFromJid
(
jid
))
||
null
;
return
_converse
.
roster
.
get
(
Strophe
.
getBareJidFromJid
(
jid
))
||
null
;
...
@@ -876,6 +912,18 @@
...
@@ -876,6 +912,18 @@
}
}
return
_
.
map
(
jids
,
_getter
);
return
_
.
map
(
jids
,
_getter
);
},
},
/**
* Add a contact.
*
* @method _converse.api.contacts.add
* @param {string} jid The JID of the contact to be added
* @param {string} [name] A custom name to show the user by
* in the roster.
* @example
* _converse.api.contacts.add('buddy@example.com')
* @example
* _converse.api.contacts.add('buddy@example.com', 'Buddy')
*/
'
add
'
(
jid
,
name
)
{
'
add
'
(
jid
,
name
)
{
if
(
!
_
.
isString
(
jid
)
||
!
_
.
includes
(
jid
,
'
@
'
))
{
if
(
!
_
.
isString
(
jid
)
||
!
_
.
includes
(
jid
,
'
@
'
))
{
throw
new
TypeError
(
'
contacts.add: invalid jid
'
);
throw
new
TypeError
(
'
contacts.add: invalid jid
'
);
...
...
src/converse-vcard.js
View file @
866f2737
...
@@ -146,12 +146,57 @@
...
@@ -146,12 +146,57 @@
});
});
_
.
extend
(
_converse
.
api
,
{
_
.
extend
(
_converse
.
api
,
{
/**
* The XEP-0054 VCard API
*
* This API lets you access and update user VCards
*
* @namespace _converse.api.vcard
* @memberOf _converse.api
*/
'
vcard
'
:
{
'
vcard
'
:
{
/**
* Enables setting new values for a VCard.
*
* @method _converse.api.vcard.set
* @param {string} jid The JID for which the VCard should be set
* @param {object} data A map of VCard keys and values
* @example
* _converse.api.vcard.set({
* 'jid': _converse.bare_jid,
* 'fn': 'John Doe',
* 'nickname': 'jdoe'
* }).then(() => {
* // Succes
* }).catch(() => {
* // Failure
* }).
*/
'
set
'
(
jid
,
data
)
{
'
set
'
(
jid
,
data
)
{
return
setVCard
(
jid
,
data
);
return
setVCard
(
jid
,
data
);
},
},
'
get
'
(
model
,
force
)
{
/**
* @method _converse.api.vcard.get
* @param {Backbone.Model|string} model Either a `Backbone.Model` instance, or a string JID.
* If a `Backbone.Model` instance is passed in, then it must have either a `jid`
* attribute or a `muc_jid` attribute.
* @param {boolean} [force] A boolean indicating whether the vcard should be
* fetched even if it's been fetched before.
* @returns {promise} A Promise which resolves with the VCard data for a particular JID or for
* a `Backbone.Model` instance which represents an entity with a JID (such as a roster contact,
* chat or chatroom occupant).
*
* @example
* _converse.api.waitUntil('rosterContactsFetched').then(() => {
* _converse.api.vcard.get('someone@example.org').then(
* (vcard) => {
* // Do something with the vcard...
* }
* );
* });
*/
'
get
'
(
model
,
force
)
{
if
(
_
.
isString
(
model
))
{
if
(
_
.
isString
(
model
))
{
return
getVCard
(
_converse
,
model
);
return
getVCard
(
_converse
,
model
);
}
else
if
(
force
||
}
else
if
(
force
||
...
@@ -168,14 +213,28 @@
...
@@ -168,14 +213,28 @@
}
}
},
},
/**
* 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.
*
* @method _converse.api.vcard.update
* @param {Backbone.Model} model A `Backbone.Model` instance
* @param {boolean} [force] A boolean indicating whether the vcard should be
* fetched again even if it's been fetched before.
* @returns {promise} A promise which resolves once the update has completed.
* @example
* _converse.api.waitUntil('rosterContactsFetched').then(() => {
* const chatbox = _converse.chatboxes.getChatBox('someone@example.org');
* _converse.api.vcard.update(chatbox);
* });
*/
'
update
'
(
model
,
force
)
{
'
update
'
(
model
,
force
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
this
.
get
(
model
,
force
)
this
.
get
(
model
,
force
).
then
((
vcard
)
=>
{
.
then
(
vcard
=>
{
delete
vcard
[
'
stanza
'
]
delete
vcard
[
'
stanza
'
]
model
.
save
(
vcard
);
model
.
save
(
vcard
);
resolve
();
});
});
});
}
}
}
}
});
});
...
...
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