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,32 +211,20 @@ 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';
|
var setKey = 'uid:' + uid + ':chat:room:' + roomId + ':mids';
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
async.apply(db.sortedSetRank, setKey, mid),
|
function(next) {
|
||||||
function(index, next) {
|
db.getSortedSetRevRangeWithScores(setKey, 0, 0, next);
|
||||||
if (index > 0) {
|
},
|
||||||
db.getSortedSetRange(setKey, index - 1, index, next);
|
function(messages, next) {
|
||||||
|
if (messages && messages.length) {
|
||||||
|
next(null, parseInt(timestamp, 10) > parseInt(messages[0].score, 10) + (1000 * 60 * 5));
|
||||||
} else {
|
} else {
|
||||||
next(null, true);
|
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(messages, next) {
|
|
||||||
if (typeof messages !== 'boolean' && messages && messages.length) {
|
|
||||||
next(null, parseInt(messages[1].timestamp, 10) > parseInt(messages[0].timestamp, 10) + (1000*60*5));
|
|
||||||
} else {
|
|
||||||
next(null, messages);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ module.exports = function(Messaging) {
|
|||||||
Messaging.addMessage = function(fromuid, roomId, content, timestamp, callback) {
|
Messaging.addMessage = function(fromuid, roomId, content, timestamp, callback) {
|
||||||
var mid;
|
var mid;
|
||||||
var message;
|
var message;
|
||||||
|
var isNewSet;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -63,6 +64,10 @@ module.exports = function(Messaging) {
|
|||||||
db.setObject('message:' + mid, message, next);
|
db.setObject('message:' + mid, message, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
|
Messaging.isNewSet(fromuid, roomId, timestamp, next);
|
||||||
|
},
|
||||||
|
function (_isNewSet, next) {
|
||||||
|
isNewSet = _isNewSet;
|
||||||
db.getSortedSetRange('chat:room:' + roomId + ':uids', 0, -1, next);
|
db.getSortedSetRange('chat:room:' + roomId + ':uids', 0, -1, next);
|
||||||
},
|
},
|
||||||
function (uids, next) {
|
function (uids, next) {
|
||||||
@@ -75,8 +80,7 @@ module.exports = function(Messaging) {
|
|||||||
function (results, next) {
|
function (results, next) {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
markRead: async.apply(Messaging.markRead, fromuid, roomId),
|
markRead: async.apply(Messaging.markRead, fromuid, roomId),
|
||||||
messages: async.apply(Messaging.getMessagesData, [mid], fromuid, roomId, true),
|
messages: async.apply(Messaging.getMessagesData, [mid], fromuid, roomId, true)
|
||||||
isNewSet: async.apply(Messaging.isNewSet, fromuid, roomId, mid)
|
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (results, next) {
|
function (results, next) {
|
||||||
@@ -84,7 +88,7 @@ module.exports = function(Messaging) {
|
|||||||
return next(null, null);
|
return next(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
results.messages[0].newSet = results.isNewSet;
|
results.messages[0].newSet = isNewSet;
|
||||||
results.messages[0].mid = mid;
|
results.messages[0].mid = mid;
|
||||||
results.messages[0].roomId = roomId;
|
results.messages[0].roomId = roomId;
|
||||||
next(null, results.messages[0]);
|
next(null, results.messages[0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user