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); + }); }); }); });