@@ -326,9 +326,9 @@ converse.plugins.add('converse-chatboxes', {
326
326
327
327
initMessages ( ) {
328
328
this . messages = new this . messagesCollection ( ) ;
329
+ this . messages . chatbox = this ;
329
330
const storage = _converse . config . get ( 'storage' ) ;
330
331
this . messages . browserStorage = new BrowserStorage [ storage ] ( this . getMessagesCacheKey ( ) ) ;
331
- this . messages . chatbox = this ;
332
332
this . listenTo ( this . messages , 'change:upload' , message => {
333
333
if ( message . get ( 'upload' ) === _converse . SUCCESS ) {
334
334
_converse . api . send ( this . createMessageStanza ( message ) ) ;
@@ -1167,7 +1167,7 @@ converse.plugins.add('converse-chatboxes', {
1167
1167
if ( utils . isSameBareJID ( from_jid , _converse . bare_jid ) ) {
1168
1168
return ;
1169
1169
}
1170
- const chatbox = this . getChatBox ( from_jid ) ;
1170
+ const chatbox = await this . getChatBox ( from_jid ) ;
1171
1171
if ( ! chatbox ) {
1172
1172
return ;
1173
1173
}
@@ -1203,7 +1203,7 @@ converse.plugins.add('converse-chatboxes', {
1203
1203
/**
1204
1204
* Handler method for all incoming single-user chat "message" stanzas.
1205
1205
* @private
1206
- * @method _converse.ChatBox #onMessage
1206
+ * @method _converse.ChatBoxes #onMessage
1207
1207
* @param { XMLElement } stanza - The incoming message stanza
1208
1208
*/
1209
1209
async onMessage ( stanza ) {
@@ -1279,7 +1279,7 @@ converse.plugins.add('converse-chatboxes', {
1279
1279
// Get chat box, but only create when the message has something to show to the user
1280
1280
const has_body = sizzle ( `body, encrypted[xmlns="${ Strophe . NS . OMEMO } "]` , stanza ) . length > 0 ;
1281
1281
const roster_nick = get ( contact , 'attributes.nickname' ) ;
1282
- const chatbox = this . getChatBox ( contact_jid , { 'nickname' : roster_nick } , has_body ) ;
1282
+ const chatbox = await this . getChatBox ( contact_jid , { 'nickname' : roster_nick } , has_body ) ;
1283
1283
1284
1284
if ( chatbox ) {
1285
1285
const message = await chatbox . getDuplicateMessage ( stanza ) ;
@@ -1319,7 +1319,7 @@ converse.plugins.add('converse-chatboxes', {
1319
1319
* @param { object } attrs - Optional chat box atributes. If the
1320
1320
* chat box already exists, its attributes will be updated.
1321
1321
*/
1322
- getChatBox ( jid , attrs = { } , create ) {
1322
+ async getChatBox ( jid , attrs = { } , create ) {
1323
1323
if ( isObject ( jid ) ) {
1324
1324
create = attrs ;
1325
1325
attrs = jid ;
@@ -1337,6 +1337,7 @@ converse.plugins.add('converse-chatboxes', {
1337
1337
_converse . log ( response . responseText ) ;
1338
1338
}
1339
1339
} ) ;
1340
+ await chatbox . messages . fetched ;
1340
1341
if ( ! chatbox . isValid ( ) ) {
1341
1342
chatbox . destroy ( ) ;
1342
1343
return null ;
@@ -1470,7 +1471,7 @@ converse.plugins.add('converse-chatboxes', {
1470
1471
* // To open a single chat, provide the JID of the contact you're chatting with in that chat:
1471
1472
* converse.plugins.add('myplugin', {
1472
1473
* initialize: function() {
1473
- * var _converse = this._converse;
1474
+ * const _converse = this._converse;
1474
1475
* // Note, buddy@example .org must be in your contacts roster!
1475
1476
* _converse.api.chats.open('[email protected] ').then(chat => {
1476
1477
* // Now you can do something with the chat model
@@ -1482,7 +1483,7 @@ converse.plugins.add('converse-chatboxes', {
1482
1483
* // To open an array of chats, provide an array of JIDs:
1483
1484
* converse.plugins.add('myplugin', {
1484
1485
* initialize: function () {
1485
- * var _converse = this._converse;
1486
+ * const _converse = this._converse;
1486
1487
* // Note, these users must first be in your contacts roster!
1487
1488
* _converse.api.chats.open(['buddy1@example .com', '[email protected] ']).then(chats => {
1488
1489
* // Now you can do something with the chat models
@@ -1518,7 +1519,7 @@ converse.plugins.add('converse-chatboxes', {
1518
1519
*
1519
1520
* @method _converse.api.chats.get
1520
1521
* @param {String|string[] } jids - e.g. '[email protected] ' or ['[email protected] ', '[email protected] ']
1521
- * @returns {_converse.ChatBox }
1522
+ * @returns { Promise< _converse.ChatBox> }
1522
1523
*
1523
1524
* @example
1524
1525
* // To return a single chat, provide the JID of the contact you're chatting with in that chat:
0 commit comments