1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-12-01 13:42:16 -05:00

Fix MAM retrieval when there are messages with no ids

This commit is contained in:
Lance Stout 2013-09-12 13:44:02 -07:00
parent aa69711b35
commit baf25a6bc8
3 changed files with 30 additions and 5 deletions

View File

@ -228,7 +228,14 @@ module.exports = function (client, app) {
onclick: _.bind(app.navigate, app, '/chat/' + contact.jid) onclick: _.bind(app.navigate, app, '/chat/' + contact.jid)
}); });
} }
contact.messages.add(message); contact.messages.add(message);
var newInteraction = new Date(message.created);
if (!contact.lastInteraction || contact.lastInteraction < newInteraction) {
contact.lastInteraction = newInteraction;
}
if (!contact.lockedResource) { if (!contact.lockedResource) {
contact.lockedResource = msg.from.full; contact.lockedResource = msg.from.full;
} else if (msg.from !== contact.lockedResource) { } else if (msg.from !== contact.lockedResource) {

View File

@ -2966,12 +2966,14 @@ MAMQuery.prototype = {
return new Date(stanza.getSubText(this.xml, this.NS, 'start') || Date.now()); return new Date(stanza.getSubText(this.xml, this.NS, 'start') || Date.now());
}, },
set start(value) { set start(value) {
if (!value) return;
stanza.setSubText(this.xml, this.NS, 'start', value.toISOString()); stanza.setSubText(this.xml, this.NS, 'start', value.toISOString());
}, },
get end() { get end() {
return new Date(stanza.getSubText(this.xml, this.NS, 'end') || Date.now()); return new Date(stanza.getSubText(this.xml, this.NS, 'end') || Date.now());
}, },
set end(value) { set end(value) {
if (!value) return;
stanza.setSubText(this.xml, this.NS, 'end', value.toISOString()); stanza.setSubText(this.xml, this.NS, 'end', value.toISOString());
} }
}; };

View File

@ -87,7 +87,8 @@ module.exports = HumanModel.define({
lastSentMessage: 'object', lastSentMessage: 'object',
timezoneOffset: ['number', false, 0], timezoneOffset: ['number', false, 0],
activeContact: ['bool', true, false], activeContact: ['bool', true, false],
unreadCount: ['number', true, 0] unreadCount: ['number', true, 0],
lastInteraction: 'date'
}, },
collections: { collections: {
resources: Resources, resources: Resources,
@ -167,12 +168,20 @@ module.exports = HumanModel.define({
fetchHistory: function () { fetchHistory: function () {
var self = this; var self = this;
app.whenConnected(function () { app.whenConnected(function () {
var filter = {
count: 20,
before: true,
};
var lastMessage = self.messages.last();
if (lastMessage && lastMessage.archivedId) {
filter.after = lastMessage.archivedId;
}
client.getHistory({ client.getHistory({
with: self.jid, with: self.jid,
rsm: { start: self.lastInteraction,
count: 20, rsm: filter
before: true
}
}, function (err, res) { }, function (err, res) {
if (err) return; if (err) return;
@ -198,8 +207,15 @@ module.exports = HumanModel.define({
if (original && original.correct(msg)) return; if (original && original.correct(msg)) return;
} }
var message = new Message(msg); var message = new Message(msg);
message.archivedId = result.mam.id; message.archivedId = result.mam.id;
var newInteraction = new Date(message.created);
if (!self.lastInteraction || newInteraction > self.lastInteraction) {
self.lastInteraction = newInteraction;
}
self.messages.add(message); self.messages.add(message);
}); });
}); });