From 1b5287803c972863e3c59be47e399a4ec07bc787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 30 Sep 2016 14:00:49 +0300 Subject: [PATCH] closes #5071 --- src/messaging.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/messaging.js b/src/messaging.js index e2be899b46..2bad43ce79 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -312,6 +312,7 @@ var async = require('async'), }; Messaging.getTeaser = function (uid, roomId, callback) { + var teaser; async.waterfall([ function (next) { db.getSortedSetRevRange('uid:' + uid + ':chat:room:' + roomId + ':mids', 0, 0, next); @@ -320,14 +321,22 @@ var async = require('async'), if (!mids || !mids.length) { return next(null, null); } - Messaging.getMessageFields(mids[0], ['content', 'timestamp'], next); + Messaging.getMessageFields(mids[0], ['fromuid', 'content', 'timestamp'], next); }, - function (teaser, next) { - if (teaser && teaser.content) { - teaser.content = S(teaser.content).stripTags().decodeHTMLEntities().s; - teaser.timestampISO = utils.toISOString(teaser.timestamp); - } - + function (_teaser, next) { + teaser = _teaser; + if (!teaser) { + return callback(); + } + if (teaser.content) { + teaser.content = S(teaser.content).stripTags().decodeHTMLEntities().s; + } + + teaser.timestampISO = utils.toISOString(teaser.timestamp); + user.getUserFields(teaser.fromuid, ['uid', 'username', 'userslug', 'picture', 'status', 'lastonline'] , next); + }, + function(user, next) { + teaser.user = user; next(null, teaser); } ], callback);