Fix cid/id handling. Edits from MAM work again now.

This commit is contained in:
Lance Stout 2013-09-12 13:24:52 -07:00
parent b8b6f03fca
commit aa69711b35
5 changed files with 28 additions and 23 deletions

View File

@ -6,6 +6,7 @@ var crypto = XMPP.crypto;
var _ = require('underscore'); var _ = require('underscore');
var async = require('async'); var async = require('async');
var log = require('andlog'); var log = require('andlog');
var uuid = require('node-uuid');
var Contact = require('../models/contact'); var Contact = require('../models/contact');
var Resource = require('../models/resource'); var Resource = require('../models/resource');
var Message = require('../models/message'); var Message = require('../models/message');
@ -149,7 +150,7 @@ module.exports = function (client, app) {
resource.set(pres); resource.set(pres);
} else { } else {
resource = new Resource(pres); resource = new Resource(pres);
resource.cid = pres.from.full; resource.id = pres.from.full;
contact.resources.add(resource); contact.resources.add(resource);
} }
} }
@ -204,17 +205,16 @@ module.exports = function (client, app) {
msg = msg.toJSON(); msg = msg.toJSON();
var contact = me.getContact(msg.from, msg.to); var contact = me.getContact(msg.from, msg.to);
if (contact && !msg.replace) { if (contact && !msg.replace) {
var message = new Message(); if (!msg.id) {
if (msg.id) { msg.id = uuid.v4();
message.cid = msg.id;
} }
message.set(msg);
var message = new Message(msg);
if (msg.archived) { if (msg.archived) {
msg.archived.forEach(function (archived) { msg.archived.forEach(function (archived) {
if (me.isMe(archived.by)) { if (me.isMe(archived.by)) {
message.id = archived.id; message.archivedId = archived.id;
message.cid = msg.id || archived.id;
} }
}); });
} }

View File

@ -2,6 +2,7 @@
//"use strict"; //"use strict";
var async = require('async'); var async = require('async');
var uuid = require('node-uuid');
var HumanModel = require('human-model'); var HumanModel = require('human-model');
var Resources = require('./resources'); var Resources = require('./resources');
var Messages = require('./messages'); var Messages = require('./messages');
@ -12,7 +13,7 @@ var crypto = XMPP.crypto;
module.exports = HumanModel.define({ module.exports = HumanModel.define({
initialize: function (attrs) { initialize: function (attrs) {
if (attrs.jid) { if (attrs.jid) {
this.cid = attrs.jid; this.id = attrs.jid;
} }
this.setAvatar(attrs.avatarID); this.setAvatar(attrs.avatarID);
@ -23,6 +24,7 @@ module.exports = HumanModel.define({
seal: true, seal: true,
type: 'contact', type: 'contact',
props: { props: {
id: ['string', true, false],
inRoster: ['bool', true, false], inRoster: ['bool', true, false],
owner: ['string', true, ''], owner: ['string', true, ''],
storageId: ['string', true, ''], storageId: ['string', true, ''],
@ -155,8 +157,6 @@ module.exports = HumanModel.define({
if (self.lockedResource) { if (self.lockedResource) {
client.getTime(self.lockedResource, function (err, res) { client.getTime(self.lockedResource, function (err, res) {
if (err) return; if (err) return;
console.log('RECV' + res.time.tzo);
console.log('RECV UTC' + res.time.utc);
self.timezoneOffset = res.time.tzo; self.timezoneOffset = res.time.tzo;
}); });
} else { } else {
@ -181,6 +181,10 @@ module.exports = HumanModel.define({
results.forEach(function (result) { results.forEach(function (result) {
result = result.toJSON(); result = result.toJSON();
var msg = result.mam.forwarded.message; var msg = result.mam.forwarded.message;
if (!msg.id) {
msg.id = uuid.v4();
}
if (!msg.delay) { if (!msg.delay) {
msg.delay = result.mam.forwarded.delay; msg.delay = result.mam.forwarded.delay;
@ -188,14 +192,14 @@ module.exports = HumanModel.define({
if (msg.replace) { if (msg.replace) {
var original = self.messages.get(msg.replace); var original = self.messages.get(msg.replace);
if (original) { // Drop the message if editing a previous, but
return original.correct(msg); // keep it if it didn't actually change an
} // existing message.
if (original && original.correct(msg)) return;
} }
var message = new Message(); var message = new Message(msg);
message.cid = msg.id || result.mam.id; message.archivedId = result.mam.id;
message.set(msg);
self.messages.add(message); self.messages.add(message);
}); });
}); });

View File

@ -9,15 +9,14 @@ module.exports = HumanModel.define({
this._created = Date.now(); this._created = Date.now();
}, },
type: 'message', type: 'message',
idDefinition: {
type: 'string'
},
props: { props: {
id: ['string', true, ''],
to: ['string', true, ''], to: ['string', true, ''],
from: ['string', true, ''], from: ['string', true, ''],
body: ['string', true, ''], body: ['string', true, ''],
type: ['string', true, 'normal'], type: ['string', true, 'normal'],
acked: ['bool', true, false] acked: ['bool', true, false],
archivedId: ['string', true, '']
}, },
derived: { derived: {
mine: { mine: {
@ -68,12 +67,14 @@ module.exports = HumanModel.define({
delay: 'object' delay: 'object'
}, },
correct: function (msg) { correct: function (msg) {
if (this.from !== msg.from) return; if (this.from.full !== msg.from.full) return false;
delete msg.id; delete msg.id;
this.set(msg); this.set(msg);
this._created = Date.now(); this._created = Date.now();
this.edited = true; this.edited = true;
return true;
} }
}); });

View File

@ -7,6 +7,7 @@ module.exports = HumanModel.define({
initialize: function () {}, initialize: function () {},
type: 'resource', type: 'resource',
session: { session: {
id: ['string', true],
jid: ['string', true], jid: ['string', true],
status: ['string', true, ''], status: ['string', true, ''],
show: ['string', true, ''], show: ['string', true, ''],

View File

@ -73,7 +73,6 @@ module.exports = BasePage.extend({
} }
}, },
pausedTyping: function () { pausedTyping: function () {
console.log('paused?', this.typing);
if (this.typing) { if (this.typing) {
this.typing = false; this.typing = false;
client.sendMessage({ client.sendMessage({
@ -94,7 +93,7 @@ module.exports = BasePage.extend({
chatState: 'active' chatState: 'active'
}; };
if (this.editMode) { if (this.editMode) {
message.replace = this.model.lastSentMessage.id; message.replace = this.model.lastSentMessage.id || this.model.lastSentMessage.cid;
} }
var id = client.sendMessage(message); var id = client.sendMessage(message);