fix: #7483, show latest undeleted message as teaser

v1.18.x
Barış Soner Uşaklı 6 years ago
parent 988cbb63e1
commit 644504ff02

@ -206,30 +206,24 @@ Messaging.getTeaser = function (uid, roomId, callback) {
var teaser; var teaser;
async.waterfall([ async.waterfall([
function (next) { function (next) {
db.getSortedSetRevRange('uid:' + uid + ':chat:room:' + roomId + ':mids', 0, 0, next); Messaging.getLatestUndeletedMessage(uid, roomId, next);
}, },
function (mids, next) { function (mid, next) {
if (!mids || !mids.length) { if (!mid) {
return next(null, null); return callback(null, null);
} }
Messaging.getMessageFields(mids[0], ['fromuid', 'content', 'timestamp'], next); Messaging.getMessageFields(mid, ['fromuid', 'content', 'timestamp'], next);
},
function (teaser, next) {
if (!teaser) {
return callback();
}
user.blocks.is(teaser.fromuid, uid, function (err, blocked) {
if (err || blocked) {
return callback(err);
}
next(null, teaser);
});
}, },
function (_teaser, next) { function (_teaser, next) {
teaser = _teaser; teaser = _teaser;
if (!teaser) { if (!teaser.fromuid) {
return callback(); return callback(null, null);
}
user.blocks.is(teaser.fromuid, uid, next);
},
function (blocked, next) {
if (blocked) {
return callback(null, null);
} }
if (teaser.content) { if (teaser.content) {
teaser.content = utils.stripHTMLTags(utils.decodeHTMLEntities(teaser.content)); teaser.content = utils.stripHTMLTags(utils.decodeHTMLEntities(teaser.content));
@ -248,6 +242,44 @@ Messaging.getTeaser = function (uid, roomId, callback) {
], callback); ], callback);
}; };
Messaging.getLatestUndeletedMessage = function (uid, roomId, callback) {
var done = false;
var latestMid = null;
var index = 0;
var mids;
async.doWhilst(
function (next) {
async.waterfall([
function (_next) {
db.getSortedSetRevRange('uid:' + uid + ':chat:room:' + roomId + ':mids', index, index, _next);
},
function (_mids, _next) {
mids = _mids;
if (!mids.length) {
done = true;
return next();
}
Messaging.getMessageField(mids[0], 'deleted', _next);
},
function (deleted, _next) {
done = !deleted;
if (!deleted) {
latestMid = mids[0];
}
index += 1;
_next();
},
], next);
},
function (next) {
next(null, !done);
},
function (err) {
callback(err, parseInt(latestMid, 10));
}
);
};
Messaging.canMessageUser = function (uid, toUid, callback) { Messaging.canMessageUser = function (uid, toUid, callback) {
if (meta.config.disableChat || uid <= 0 || uid === toUid) { if (meta.config.disableChat || uid <= 0 || uid === toUid) {
return callback(new Error('[[error:chat-disabled]]')); return callback(new Error('[[error:chat-disabled]]'));

Loading…
Cancel
Save