diff --git a/clientapp/helpers/xmppEventHandlers.js b/clientapp/helpers/xmppEventHandlers.js index d94d28c..774fbbf 100644 --- a/clientapp/helpers/xmppEventHandlers.js +++ b/clientapp/helpers/xmppEventHandlers.js @@ -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; } diff --git a/clientapp/models/message.js b/clientapp/models/message.js index 36ac582..f34fa1f 100644 --- a/clientapp/models/message.js +++ b/clientapp/models/message.js @@ -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, ''], diff --git a/clientapp/models/muc.js b/clientapp/models/muc.js index 9c91939..bcec2b4 100644 --- a/clientapp/models/muc.js +++ b/clientapp/models/muc.js @@ -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; } diff --git a/clientapp/pages/chat.js b/clientapp/pages/chat.js index 40bba31..d34eb35 100644 --- a/clientapp/pages/chat.js +++ b/clientapp/pages/chat.js @@ -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) { diff --git a/clientapp/pages/groupchat.js b/clientapp/pages/groupchat.js index aa7bc3a..475021b 100644 --- a/clientapp/pages/groupchat.js +++ b/clientapp/pages/groupchat.js @@ -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) { diff --git a/public/x-manifest.cache b/public/x-manifest.cache index fa4b0fa..7256a26 100644 --- a/public/x-manifest.cache +++ b/public/x-manifest.cache @@ -1,5 +1,5 @@ CACHE MANIFEST -# 0.0.1 1387301758200 +# 0.0.1 1387390012229 CACHE: /app.js