mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-27 01:39:53 +01:00
remove since properly
This commit is contained in:
@@ -60,7 +60,6 @@ chatsController.get = function(req, res, callback) {
|
||||
callerUid: req.uid,
|
||||
uid: uid,
|
||||
roomId: req.params.roomid,
|
||||
since: 'recent',
|
||||
isNew: false
|
||||
}),
|
||||
room: async.apply(messaging.getRoomData, req.params.roomid)
|
||||
|
||||
@@ -22,13 +22,6 @@ var userNotifications = require('./user/notifications');
|
||||
require('./messaging/unread')(Messaging);
|
||||
require('./messaging/notifications')(Messaging);
|
||||
|
||||
var terms = {
|
||||
day: 86400000,
|
||||
week: 604800000,
|
||||
month: 2592000000,
|
||||
threemonths: 7776000000
|
||||
};
|
||||
|
||||
Messaging.getMessageField = function(mid, field, callback) {
|
||||
Messaging.getMessageFields(mid, [field], function(err, fields) {
|
||||
callback(err, fields ? fields[field] : null);
|
||||
@@ -50,18 +43,11 @@ var userNotifications = require('./user/notifications');
|
||||
Messaging.getMessages = function(params, callback) {
|
||||
var uid = params.uid;
|
||||
var roomId = params.roomId;
|
||||
var since = params.since;
|
||||
var isNew = params.isNew || false;
|
||||
var start = params.hasOwnProperty('start') ? params.start : 0;
|
||||
var count = params.count || 250;
|
||||
var stop = parseInt(start, 10) + ((params.count || 50) - 1);
|
||||
var markRead = params.markRead || true;
|
||||
|
||||
var min = params.count ? 0 : Date.now() - (terms[since] || terms.day);
|
||||
|
||||
if (since === 'recent') {
|
||||
count = 50;
|
||||
min = 0;
|
||||
}
|
||||
var indices = {};
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
@@ -71,7 +57,7 @@ var userNotifications = require('./user/notifications');
|
||||
if (!canGet) {
|
||||
return callback(null, null);
|
||||
}
|
||||
db.getSortedSetRevRangeByScore('uid:' + uid + ':chat:room:' + roomId + ':mids', start, count, '+inf', min, next);
|
||||
db.getSortedSetRevRange('uid:' + uid + ':chat:room:' + roomId + ':mids', start, stop, next);
|
||||
},
|
||||
function(mids, next) {
|
||||
if (!Array.isArray(mids) || !mids.length) {
|
||||
|
||||
@@ -115,11 +115,18 @@ SocketModules.chats.loadRoom = function(socket, data, callback) {
|
||||
|
||||
async.parallel({
|
||||
roomData: async.apply(Messaging.getRoomData, data.roomId),
|
||||
users: async.apply(Messaging.getUsersInRoom, data.roomId, 0, -1)
|
||||
users: async.apply(Messaging.getUsersInRoom, data.roomId, 0, -1),
|
||||
messages: async.apply(Messaging.getMessages, {
|
||||
callerUid: socket.uid,
|
||||
uid: data.uid || socket.uid,
|
||||
roomId: data.roomId,
|
||||
isNew: false
|
||||
}),
|
||||
}, next);
|
||||
},
|
||||
function (results, next) {
|
||||
results.roomData.users = results.users;
|
||||
results.roomData.messages = results.messages;
|
||||
results.roomData.groupChat = results.roomData.hasOwnProperty('groupChat') ? results.roomData.groupChat : results.users.length > 2;
|
||||
results.roomData.isOwner = parseInt(results.roomData.owner, 10) === socket.uid;
|
||||
results.roomData.maximumUsersInChatRoom = parseInt(meta.config.maximumUsersInChatRoom, 10) || 0;
|
||||
@@ -312,10 +319,6 @@ SocketModules.chats.getMessages = function(socket, data, callback) {
|
||||
markRead: false
|
||||
};
|
||||
|
||||
if (data.hasOwnProperty('since')) {
|
||||
params.since = data.since;
|
||||
}
|
||||
|
||||
if (data.hasOwnProperty('markRead')) {
|
||||
params.markRead = data.markRead;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user