1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-05 17:15:04 -05:00

Fix: Messages fetch & notifications

This commit is contained in:
Sébastien Hut 2015-02-15 18:06:39 +01:00 committed by Sébastien Hut
parent ddbccf7556
commit d3d2a1b2ae
4 changed files with 14 additions and 11 deletions

View File

@ -284,7 +284,9 @@ module.exports = function (client, app) {
}
message.acked = true;
contact.addMessage(message, true);
var localTime = new Date(Date.now() + app.timeInterval);
var notify = Math.round((localTime - message.created) / 1000) < 5;
contact.addMessage(message, notify);
if (msg.from.bare == contact.jid.bare) {
contact.lockedResource = msg.from.full;
}
@ -299,7 +301,9 @@ module.exports = function (client, app) {
if (contact && !msg.replace) {
var message = new Message(msg);
message.acked = true;
contact.addMessage(message, true);
var localTime = new Date(Date.now() + app.timeInterval);
var notify = Math.round((localTime - message.created) / 1000) < 5;
contact.addMessage(message, notify);
}
});
@ -341,7 +345,7 @@ module.exports = function (client, app) {
var msg = carbon.carbonReceived.forwarded.message;
var delay = carbon.carbonReceived.forwarded.delay;
if (!delay.stamp) {
delay.stamp = new Date(Date.now());
delay.stamp = new Date(Date.now() + app.timeInterval);
}
if (!msg._extensions.delay) {
@ -357,7 +361,7 @@ module.exports = function (client, app) {
var msg = carbon.carbonSent.forwarded.message;
var delay = carbon.carbonSent.forwarded.delay;
if (!delay.stamp) {
delay.stamp = new Date(Date.now());
delay.stamp = new Date(Date.now() + app.timeInterval);
}
if (!msg._extensions.delay) {

View File

@ -24,6 +24,8 @@ module.exports = HumanModel.define({
this.resources.bind('change', this.onResourceChange, this);
this.bind('change:topResource change:lockedResource change:_forceUpdate', this.summarizeResources, this);
this.fetchHistory();
},
type: 'contact',
props: {
@ -310,14 +312,14 @@ module.exports = HumanModel.define({
filter.start = self.lastHistoryFetch;
}
} else {
filter.end = new Date(Date.now());
filter.end = new Date(Date.now() + app.timeInterval);
}
}
client.getHistory(filter, function (err, res) {
if (err) return;
self.lastHistoryFetch = new Date(Date.now());
self.lastHistoryFetch = new Date(Date.now() + app.timeInterval);
var results = res.mamQuery.results || [];
if (!old) results.reverse();

View File

@ -210,7 +210,7 @@ var Message = module.exports = HumanModel.define({
delete msg.id;
this.set(msg);
this._edited = new Date(Date.now());
this._edited = new Date(Date.now() + app.timeInterval);
this.edited = true;
this.save();

View File

@ -95,8 +95,7 @@ module.exports = HumanModel.define({
message.mentions = mentions;
}
var localTime = new Date();
if (Math.round((localTime - message.created) / 1000) < 5 && notify && (!this.activeContact || (this.activeContact && !app.state.focused)) && !mine) {
if (notify && (!this.activeContact || (this.activeContact && !app.state.focused)) && !mine) {
this.unreadCount++;
if (message.mentions.length) {
app.notifications.create(this.displayName, {
@ -164,8 +163,6 @@ module.exports = HumanModel.define({
client.getHistory(filter, function (err, res) {
if (err) return;
self.lastHistoryFetch = new Date(Date.now());
var results = res.mamQuery.results || [];
results.forEach(function (result) {