From 4827ea04fcd1c7d2b7fc865c95f0f268e14c7de9 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 17 Dec 2015 12:35:49 +0200 Subject: [PATCH] messaging.getTeaser --- src/messaging.js | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/messaging.js b/src/messaging.js index eb254a235b..c7c8f26978 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -254,19 +254,7 @@ var async = require('async'), }, teasers: function(next) { async.map(roomIds, function(roomId, next) { - Messaging.getMessages({ - uid: uid, - roomId: roomId, - isNew: false, - count: 1, - markRead: false - }, function(err, teaser) { - teaser = teaser[0]; - if (teaser && teaser.content) { - teaser.content = S(teaser.content).stripTags().decodeHTMLEntities().s; - } - next(err, teaser); - }); + Messaging.getTeaser(uid, roomId, next); }, next); } }, function(err, results) { @@ -300,6 +288,28 @@ var async = require('async'), }); }; + Messaging.getTeaser = function (uid, roomId, callback) { + async.waterfall([ + function (next) { + db.getSortedSetRevRange('uid:' + uid + ':chat:room:' + roomId + ':mids', 0, 0, next); + }, + function (mids, next) { + if (!mids || !mids.length) { + return next(null, null); + } + Messaging.getMessageFields(mids[0], ['content', 'timestamp'], next); + }, + function (teaser, next) { + if (teaser && teaser.content) { + teaser.content = S(teaser.content).stripTags().decodeHTMLEntities().s; + teaser.timestampISO = utils.toISOString(teaser.timestamp); + } + + next(null, teaser); + } + ], callback); + }; + Messaging.canMessageUser = function(uid, toUid, callback) { if (parseInt(meta.config.disableChat) === 1 || !uid || uid === toUid) { return callback(null, false);