After reconnection, fetch new messages for private chats
This commit is contained in:
parent
c26ccf5e01
commit
4df61cc496
@ -11,6 +11,7 @@
|
|||||||
(function (root, factory) {
|
(function (root, factory) {
|
||||||
define(["sizzle",
|
define(["sizzle",
|
||||||
"converse-core",
|
"converse-core",
|
||||||
|
"utils",
|
||||||
"converse-disco",
|
"converse-disco",
|
||||||
"converse-chatview", // Could be made a soft dependency
|
"converse-chatview", // Could be made a soft dependency
|
||||||
"converse-muc", // Could be made a soft dependency
|
"converse-muc", // Could be made a soft dependency
|
||||||
@ -18,6 +19,7 @@
|
|||||||
], factory);
|
], factory);
|
||||||
}(this, function (sizzle, converse, utils) {
|
}(this, function (sizzle, converse, utils) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
const CHATROOMS_TYPE = 'chatroom';
|
||||||
const { Promise, Strophe, $iq, _, moment } = converse.env;
|
const { Promise, Strophe, $iq, _, moment } = converse.env;
|
||||||
|
|
||||||
const RSM_ATTRIBUTES = ['max', 'first', 'last', 'after', 'before', 'index', 'count'];
|
const RSM_ATTRIBUTES = ['max', 'first', 'last', 'after', 'before', 'index', 'count'];
|
||||||
@ -53,6 +55,45 @@
|
|||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
fetchNewestMessages () {
|
||||||
|
/* Fetches messages that might have been archived *after*
|
||||||
|
* the last archived message in our local cache.
|
||||||
|
*/
|
||||||
|
if (this.disable_mam) { return; }
|
||||||
|
const { _converse } = this.__super__;
|
||||||
|
this.addSpinner();
|
||||||
|
|
||||||
|
_converse.api.disco.supports(Strophe.NS.MAM, _converse.bare_jid).then(
|
||||||
|
(result) => { // Success
|
||||||
|
if (result.supported) {
|
||||||
|
const most_recent_msg = utils.getMostRecentMessage(this.model);
|
||||||
|
const archive_id = most_recent_msg.get('archive_id');
|
||||||
|
if (archive_id) {
|
||||||
|
this.fetchArchivedMessages({
|
||||||
|
'after': most_recent_msg.get('archive_id')
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.fetchArchivedMessages({
|
||||||
|
'start': most_recent_msg.get('time')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.clearSpinner();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
() => { // Error
|
||||||
|
this.clearSpinner();
|
||||||
|
_converse.log(
|
||||||
|
"Error or timeout while checking for MAM support",
|
||||||
|
Strophe.LogLevel.ERROR
|
||||||
|
);
|
||||||
|
}
|
||||||
|
).catch((msg) => {
|
||||||
|
this.clearSpinner();
|
||||||
|
_converse.log(msg, Strophe.LogLevel.FATAL);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
fetchArchivedMessagesIfNecessary () {
|
fetchArchivedMessagesIfNecessary () {
|
||||||
/* Check if archived messages should be fetched, and if so, do so. */
|
/* Check if archived messages should be fetched, and if so, do so. */
|
||||||
if (this.disable_mam || this.model.get('mam_initialized')) {
|
if (this.disable_mam || this.model.get('mam_initialized')) {
|
||||||
@ -385,6 +426,13 @@
|
|||||||
chatboxview.fetchArchivedMessagesIfNecessary();
|
chatboxview.fetchArchivedMessagesIfNecessary();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_converse.on('reconnected', () => {
|
||||||
|
const private_chats = _converse.chatboxviews.filter(
|
||||||
|
(view) => _.at(view, 'model.attributes.type')[0] === 'chatbox'
|
||||||
|
);
|
||||||
|
_.each(private_chats, (view) => view.fetchNewestMessages())
|
||||||
|
});
|
||||||
|
|
||||||
_.extend(_converse.api, {
|
_.extend(_converse.api, {
|
||||||
/* Extend default converse.js API to add methods specific to MAM
|
/* Extend default converse.js API to add methods specific to MAM
|
||||||
*/
|
*/
|
||||||
|
@ -275,6 +275,11 @@
|
|||||||
Strophe.getBareJidFromJid(jid2).toLowerCase();
|
Strophe.getBareJidFromJid(jid2).toLowerCase();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
u.getMostRecentMessage = function (model) {
|
||||||
|
const messages = model.messages.filter('message');
|
||||||
|
return messages[messages.length-1];
|
||||||
|
}
|
||||||
|
|
||||||
u.isNewMessage = function (message) {
|
u.isNewMessage = function (message) {
|
||||||
/* Given a stanza, determine whether it's a new
|
/* Given a stanza, determine whether it's a new
|
||||||
* message, i.e. not a MAM archived one.
|
* message, i.e. not a MAM archived one.
|
||||||
|
Loading…
Reference in New Issue
Block a user