1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-12 04:25:05 -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)
});
}
contact.messages.add(message);
var newInteraction = new Date(message.created);
if (!contact.lastInteraction || contact.lastInteraction < newInteraction) {
contact.lastInteraction = newInteraction;
}
if (!contact.lockedResource) {
contact.lockedResource = msg.from.full;
} 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());
},
set start(value) {
if (!value) return;
stanza.setSubText(this.xml, this.NS, 'start', value.toISOString());
},
get end() {
return new Date(stanza.getSubText(this.xml, this.NS, 'end') || Date.now());
},
set end(value) {
if (!value) return;
stanza.setSubText(this.xml, this.NS, 'end', value.toISOString());
}
};

View File

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