From 0f5c1d1892770ca24da9a4c6a7fffb0912a53cf0 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 9 Jul 2014 12:43:02 -0400 Subject: [PATCH] added messaging hook #1798 --- docs/plugins/hooks.rst | 3 +++ src/messaging.js | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index 136b8cbe00..5d332b337d 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -94,6 +94,9 @@ Executed when a post or signature needs to be parsed from raw text to HTML (for ``filter:post.parse`` ^^^^^^^^^^^^^^^^^^^^^ +``filter:messaging.save`` +^^^^^^^^^^^^^^^^^^^^^^^^ + ``filter:messaging.parse`` ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/messaging.js b/src/messaging.js index 9f59948320..a8e2447eac 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -28,18 +28,24 @@ var db = require('./database'), touid: touid }; - db.setObject('message:' + mid, message, function(err) { + plugins.fireHook('filter:messaging.save', message, function(err, message) { if (err) { return callback(err); } - db.listAppend('messages:' + uids[0] + ':' + uids[1], mid); + db.setObject('message:' + mid, message, function(err) { + if (err) { + return callback(err); + } - Messaging.updateChatTime(fromuid, touid); - Messaging.updateChatTime(touid, fromuid); + db.listAppend('messages:' + uids[0] + ':' + uids[1], mid); - getMessages([mid], fromuid, touid, true, function(err, messages) { - callback(err, messages ? messages[0] : null); + Messaging.updateChatTime(fromuid, touid); + Messaging.updateChatTime(touid, fromuid); + + getMessages([mid], fromuid, touid, true, function(err, messages) { + callback(err, messages ? messages[0] : null); + }); }); }); });