1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-25 10:42:17 -05:00

Fix backbone clobbering messages because of ids

This commit is contained in:
Lance Stout 2013-12-18 10:06:54 -08:00
parent 2bb319bcbb
commit a3fc8512d2
6 changed files with 21 additions and 18 deletions

View File

@ -6,6 +6,7 @@ var async = require('async');
var crypto = require('crypto');
var log = require('andlog');
var uuid = require('node-uuid');
var HumanModel = require('human-model');
var Contact = require('../models/contact');
var Resource = require('../models/resource');
var Message = require('../models/message');
@ -250,12 +251,11 @@ module.exports = function (client, app) {
client.on('chat', function (msg) {
msg = msg.toJSON();
msg.mid = msg.id || uuid.v4();
delete msg.id;
var contact = me.getContact(msg.from, msg.to);
if (contact && !msg.replace) {
if (!msg.id) {
msg.id = uuid.v4();
}
var message = new Message(msg);
if (msg.archived) {
@ -268,18 +268,19 @@ module.exports = function (client, app) {
message.acked = true;
contact.addMessage(message, true);
contact.lockedResource = msg.from.full;
if (msg.from.bare == contact.jid.bare) {
contact.lockedResource = msg.from.full;
}
}
});
client.on('groupchat', function (msg) {
msg = msg.toJSON();
msg.mid = msg.id || uuid.v4();
delete msg.id;
var contact = me.getContact(msg.from, msg.to);
if (contact && !msg.replace) {
if (!msg.id) {
msg.id = uuid.v4();
}
var message = new Message(msg);
message.acked = true;
contact.addMessage(message, true);
@ -292,7 +293,7 @@ module.exports = function (client, app) {
if (!contact) return;
var id = msg.replace;
var original = contact.messages.get(id);
var original = HumanModel.registry.lookup('message', id, 'messages');
if (!original) return;
@ -342,7 +343,7 @@ module.exports = function (client, app) {
if (stanza.body) {
var contact = me.getContact(stanza.to, stanza.from);
if (contact) {
var msg = contact.messages.get(stanza.id);
var msg = HumanModel.registry.lookup('message', stanza.id, 'messages');
if (msg) {
msg.acked = true;
}

View File

@ -1,6 +1,7 @@
/*global app, me*/
"use strict";
var uuid = require('node-uuid');
var HumanModel = require('human-model');
var templates = require('../templates');
var htmlify = require('../helpers/htmlify');
@ -9,11 +10,14 @@ var htmlify = require('../helpers/htmlify');
module.exports = HumanModel.define({
initialize: function (attrs) {
this._created = new Date(Date.now());
if (attrs.mid) {
HumanModel.registry._getCache('messages')['message' + attrs.mid] = this;
}
},
type: 'message',
props: {
mid: ['string', true],
owner: 'string',
id: ['string', true, ''],
to: ['object', true],
from: ['object', true],
body: ['string', true, ''],

View File

@ -86,8 +86,6 @@ module.exports = HumanModel.define({
this.messages.add(message);
if (mine) {
// Grab and save the existing message object that was updated
message = this.messages.get(message.id);
this.lastSentMessage = message;
}

View File

@ -178,7 +178,7 @@ module.exports = BasePage.extend(chatHelpers).extend({
}
var id = client.sendMessage(message);
message.id = id;
message.mid = id;
message.from = me.jid;
if (this.editMode) {

View File

@ -182,11 +182,11 @@ module.exports = BasePage.extend(chatHelpers).extend({
chatState: 'active'
};
if (this.editMode) {
message.replace = this.model.lastSentMessage.id || this.model.lastSentMessage.cid;
message.replace = this.model.lastSentMessage.mid || this.model.lastSentMessage.cid;
}
var id = client.sendMessage(message);
message.id = id;
message.mid = id;
message.from = client.JID(this.model.jid.bare + '/' + this.model.nick);
if (this.editMode) {

View File

@ -1,5 +1,5 @@
CACHE MANIFEST
# 0.0.1 1387301758200
# 0.0.1 1387390012229
CACHE:
/app.js