mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 01:26:16 +01:00
System chat messages (#7771)
* fix: removed duplicate checkContent call in addMessage addMessage is called in one place (sendMessage), and the checks are already contained there. addMessage is the lower level call and so should be called only from within core itself. * feat: #7330 chat system messages for join, leave, rename * fix: add back content checking in .addMessage(); * fix: tests, and added .addSystemMessage() method Tests were relying on message indices that changed due to the new system messages. * feat: add tests for system chat messages * refactor: rewrite half of src/messaging/rooms.js, fix tests * feat: #7743 messaging/room.js * fix: tests for messaging/room.js, #7743 * fix: trying to fix tests * fix: omg :rage2:
This commit is contained in:
@@ -53,6 +53,7 @@ module.exports = function (Messaging) {
|
||||
var mid;
|
||||
var message;
|
||||
var isNewSet;
|
||||
const timestamp = data.timestamp || new Date().getTime();
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
@@ -65,10 +66,11 @@ module.exports = function (Messaging) {
|
||||
mid = _mid;
|
||||
message = {
|
||||
content: String(data.content),
|
||||
timestamp: data.timestamp,
|
||||
timestamp: timestamp,
|
||||
fromuid: data.uid,
|
||||
roomId: data.roomId,
|
||||
deleted: 0,
|
||||
system: data.system || 0,
|
||||
};
|
||||
if (data.ip) {
|
||||
message.ip = data.ip;
|
||||
@@ -80,7 +82,7 @@ module.exports = function (Messaging) {
|
||||
db.setObject('message:' + mid, message, next);
|
||||
},
|
||||
function (next) {
|
||||
Messaging.isNewSet(data.uid, data.roomId, data.timestamp, next);
|
||||
Messaging.isNewSet(data.uid, data.roomId, timestamp, next);
|
||||
},
|
||||
function (_isNewSet, next) {
|
||||
isNewSet = _isNewSet;
|
||||
@@ -91,8 +93,8 @@ module.exports = function (Messaging) {
|
||||
},
|
||||
function (uids, next) {
|
||||
async.parallel([
|
||||
async.apply(Messaging.addRoomToUsers, data.roomId, uids, data.timestamp),
|
||||
async.apply(Messaging.addMessageToUsers, data.roomId, uids, mid, data.timestamp),
|
||||
async.apply(Messaging.addRoomToUsers, data.roomId, uids, timestamp),
|
||||
async.apply(Messaging.addMessageToUsers, data.roomId, uids, mid, timestamp),
|
||||
async.apply(Messaging.markUnread, uids, data.roomId),
|
||||
], next);
|
||||
},
|
||||
@@ -115,6 +117,16 @@ module.exports = function (Messaging) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
Messaging.addSystemMessage = async (content, uid, roomId) => {
|
||||
const message = await Messaging.addMessage({
|
||||
content: content,
|
||||
uid: uid,
|
||||
roomId: roomId,
|
||||
system: 1,
|
||||
});
|
||||
Messaging.notifyUsersInRoom(uid, roomId, message);
|
||||
};
|
||||
|
||||
Messaging.addRoomToUsers = function (roomId, uids, timestamp, callback) {
|
||||
if (!uids.length) {
|
||||
return callback();
|
||||
|
||||
Reference in New Issue
Block a user