update messaging.editMessage

v1.18.x
barisusakli 9 years ago
parent 5d1169e686
commit 6b12bd2328

@ -10,35 +10,36 @@ var sockets = require('../socket.io');
module.exports = function(Messaging) { module.exports = function(Messaging) {
Messaging.editMessage = function(mid, content, callback) { Messaging.editMessage = function(uid, mid, roomId, content, callback) {
async.series([ var uids;
async.waterfall([
function(next) { function(next) {
// Verify that the message actually changed Messaging.getMessageField(mid, 'content', next);
Messaging.getMessageField(mid, 'content', function(err, raw) { },
if (raw === content) { function (raw, next) {
// No dice. if (raw === content) {
return callback(); return callback();
} }
next(); Messaging.setMessageFields(mid, {
}); content: content,
edited: Date.now()
}, next);
}, },
async.apply(Messaging.setMessageFields, mid, { function (next) {
content: content, Messaging.getUidsInRoom(roomId, 0, -1, next);
edited: Date.now() },
}), function (_uids, next) {
function(next) { uids = _uids;
Messaging.getMessageFields(mid, ['fromuid', 'touid'], function(err, data) { Messaging.getMessagesData([mid], uid, roomId, true, next);
Messaging.getMessagesData([mid], data.fromuid, data.touid, true, function(err, messages) { },
sockets.in('uid_' + data.fromuid).emit('event:chats.edit', { function (messages, next) {
messages: messages uids.forEach(function(uid) {
}); sockets.in('uid_' + uid).emit('event:chats.edit', {
sockets.in('uid_' + data.touid).emit('event:chats.edit', { messages: messages
messages: messages
});
next();
}); });
}); });
next();
} }
], callback); ], callback);
}; };

Loading…
Cancel
Save