mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
created chat:room hashes, save owner uid in hash, update chat uids when they message
This commit is contained in:
@@ -74,7 +74,8 @@ module.exports = function(Messaging) {
|
||||
async.parallel([
|
||||
async.apply(Messaging.addRoomToUsers, roomId, uids, timestamp),
|
||||
async.apply(Messaging.addMessageToUsers, roomId, uids, mid, timestamp),
|
||||
async.apply(Messaging.markUnread, uids, roomId)
|
||||
async.apply(Messaging.markUnread, uids, roomId),
|
||||
async.apply(Messaging.addUsersToRoom, fromuid, [fromuid], roomId)
|
||||
], next);
|
||||
},
|
||||
function (results, next) {
|
||||
|
||||
@@ -16,10 +16,14 @@ module.exports = function(Messaging) {
|
||||
},
|
||||
function (_roomId, next) {
|
||||
roomId = _roomId;
|
||||
db.sortedSetAdd('chat:room:' + roomId + ':uids', now, uid, next);
|
||||
var room = {
|
||||
owner: uid,
|
||||
roomId: roomId
|
||||
};
|
||||
db.setObject('chat:room:' + roomId, room, next);
|
||||
},
|
||||
function (next) {
|
||||
Messaging.addUsersToRoom(uid, toUids, roomId, next);
|
||||
Messaging.addUsersToRoom(uid, [uid].concat(toUids), roomId, next);
|
||||
},
|
||||
function (next) {
|
||||
Messaging.addRoomToUsers(roomId, [uid].concat(toUids), now, next);
|
||||
@@ -39,14 +43,12 @@ module.exports = function(Messaging) {
|
||||
};
|
||||
|
||||
Messaging.isRoomOwner = function(uid, roomId, callback) {
|
||||
db.getSortedSetRange('chat:room:' + roomId + ':uids', 0, 0, function(err, uids) {
|
||||
db.getObjectField('chat:room:' + roomId, 'owner', function(err, owner) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
if (!Array.isArray(uids) || !uids.length) {
|
||||
return callback(null, false);
|
||||
}
|
||||
callback(null, parseInt(uids[0], 10) === parseInt(uid, 10));
|
||||
|
||||
callback(null, parseInt(uid, 10) === parseInt(owner, 10));
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ var db = require('./database'),
|
||||
schemaDate, thisSchemaDate,
|
||||
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||
latestSchema = Date.UTC(2015, 11, 15);
|
||||
latestSchema = Date.UTC(2015, 11, 23);
|
||||
|
||||
Upgrade.check = function(callback) {
|
||||
db.get('schemaDate', function(err, value) {
|
||||
@@ -232,6 +232,52 @@ Upgrade.upgrade = function(callback) {
|
||||
winston.info('[2015/12/15] Chats upgrade skipped!');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = Date.UTC(2015, 11, 23);
|
||||
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
winston.info('[2015/12/23] Upgrading chat room hashes');
|
||||
|
||||
db.getObjectField('global', 'nextChatRoomId', function(err, nextChatRoomId) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
var currentChatRoomId = 1;
|
||||
async.whilst(function() {
|
||||
return currentChatRoomId < nextChatRoomId;
|
||||
}, function(next) {
|
||||
db.getSortedSetRange('chat:room:' + currentChatRoomId + ':uids', 0, 0, function(err, uids) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (!Array.isArray(uids) || !uids.length || !uids[0]) {
|
||||
++ currentChatRoomId;
|
||||
return next();
|
||||
}
|
||||
|
||||
db.setObject('chat:room:' + currentChatRoomId, {owner: uids[0], roomId: currentChatRoomId}, function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
++ currentChatRoomId;
|
||||
next();
|
||||
});
|
||||
});
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
winston.info('[2015/12/23] Chats room hashes upgrade done!');
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
winston.info('[2015/12/23] Chats room hashes upgrade skipped!');
|
||||
next();
|
||||
}
|
||||
}
|
||||
// Add new schema updates here
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!
|
||||
|
||||
Reference in New Issue
Block a user