Node.js based forum software built for the modern web
messaging.getTeaser
barisusakli4827ea04fcd1
diff --git a/src/messaging.js b/src/messaging.jsindex 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);