mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
simpler isNewSet
This commit is contained in:
@@ -211,30 +211,18 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
Messaging.isNewSet = function(uid, roomId, mid, callback) {
|
||||
Messaging.isNewSet = function(uid, roomId, timestamp, callback) {
|
||||
var setKey = 'uid:' + uid + ':chat:room:' + roomId + ':mids';
|
||||
|
||||
async.waterfall([
|
||||
async.apply(db.sortedSetRank, setKey, mid),
|
||||
function(index, next) {
|
||||
if (index > 0) {
|
||||
db.getSortedSetRange(setKey, index - 1, index, next);
|
||||
} else {
|
||||
next(null, true);
|
||||
}
|
||||
},
|
||||
function(mids, next) {
|
||||
if (typeof mids !== 'boolean' && mids && mids.length) {
|
||||
db.getObjects(['message:' + mids[0], 'message:' + mids[1]], next);
|
||||
} else {
|
||||
next(null, mids);
|
||||
}
|
||||
function(next) {
|
||||
db.getSortedSetRevRangeWithScores(setKey, 0, 0, next);
|
||||
},
|
||||
function(messages, next) {
|
||||
if (typeof messages !== 'boolean' && messages && messages.length) {
|
||||
next(null, parseInt(messages[1].timestamp, 10) > parseInt(messages[0].timestamp, 10) + (1000*60*5));
|
||||
if (messages && messages.length) {
|
||||
next(null, parseInt(timestamp, 10) > parseInt(messages[0].score, 10) + (1000 * 60 * 5));
|
||||
} else {
|
||||
next(null, messages);
|
||||
next(null, true);
|
||||
}
|
||||
}
|
||||
], callback);
|
||||
|
||||
@@ -41,6 +41,7 @@ module.exports = function(Messaging) {
|
||||
Messaging.addMessage = function(fromuid, roomId, content, timestamp, callback) {
|
||||
var mid;
|
||||
var message;
|
||||
var isNewSet;
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -63,6 +64,10 @@ module.exports = function(Messaging) {
|
||||
db.setObject('message:' + mid, message, next);
|
||||
},
|
||||
function (next) {
|
||||
Messaging.isNewSet(fromuid, roomId, timestamp, next);
|
||||
},
|
||||
function (_isNewSet, next) {
|
||||
isNewSet = _isNewSet;
|
||||
db.getSortedSetRange('chat:room:' + roomId + ':uids', 0, -1, next);
|
||||
},
|
||||
function (uids, next) {
|
||||
@@ -75,8 +80,7 @@ module.exports = function(Messaging) {
|
||||
function (results, next) {
|
||||
async.parallel({
|
||||
markRead: async.apply(Messaging.markRead, fromuid, roomId),
|
||||
messages: async.apply(Messaging.getMessagesData, [mid], fromuid, roomId, true),
|
||||
isNewSet: async.apply(Messaging.isNewSet, fromuid, roomId, mid)
|
||||
messages: async.apply(Messaging.getMessagesData, [mid], fromuid, roomId, true)
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
@@ -84,7 +88,7 @@ module.exports = function(Messaging) {
|
||||
return next(null, null);
|
||||
}
|
||||
|
||||
results.messages[0].newSet = results.isNewSet;
|
||||
results.messages[0].newSet = isNewSet;
|
||||
results.messages[0].mid = mid;
|
||||
results.messages[0].roomId = roomId;
|
||||
next(null, results.messages[0]);
|
||||
|
||||
Reference in New Issue
Block a user