1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-12-23 16:18:48 -05:00

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

View File

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

View File

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

View File

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

View File

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