messaging.getTeaser

v1.18.x
barisusakli 9 years ago
parent 5a26eb1c76
commit 4827ea04fc

@ -254,19 +254,7 @@ var async = require('async'),
}, },
teasers: function(next) { teasers: function(next) {
async.map(roomIds, function(roomId, next) { async.map(roomIds, function(roomId, next) {
Messaging.getMessages({ Messaging.getTeaser(uid, roomId, next);
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);
});
}, next); }, next);
} }
}, function(err, results) { }, 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) { Messaging.canMessageUser = function(uid, toUid, callback) {
if (parseInt(meta.config.disableChat) === 1 || !uid || uid === toUid) { if (parseInt(meta.config.disableChat) === 1 || !uid || uid === toUid) {
return callback(null, false); return callback(null, false);

Loading…
Cancel
Save