mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: deleted chat messages (#11962)
* fix: deleted chat messages * fix spec
This commit is contained in:
committed by
GitHub
parent
b25793cd41
commit
1a1fd64d9a
@@ -50,6 +50,8 @@ MessageObject:
|
||||
type: number
|
||||
messageId:
|
||||
type: number
|
||||
isOwner:
|
||||
type: boolean
|
||||
fromUser:
|
||||
type: object
|
||||
properties:
|
||||
|
||||
@@ -52,6 +52,10 @@ module.exports = function (Messaging) {
|
||||
if (msg) {
|
||||
msg.messageId = parseInt(mids[idx], 10);
|
||||
msg.ip = undefined;
|
||||
msg.isOwner = msg.fromuid === parseInt(uid, 10);
|
||||
if (msg.deleted && !msg.isOwner) {
|
||||
msg.content = `<p>[[modules:chat.message-deleted]]</p>`;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
})
|
||||
|
||||
@@ -28,9 +28,13 @@ module.exports = function (Messaging) {
|
||||
|
||||
// Propagate this change to users in the room
|
||||
const messages = await Messaging.getMessagesData([mid], uid, roomId, true);
|
||||
sockets.in(`chat_room_${roomId}`).emit('event:chats.edit', {
|
||||
messages: messages,
|
||||
});
|
||||
if (messages[0]) {
|
||||
const roomName = messages[0].deleted ? `uid_${uid}` : `chat_room_${roomId}`;
|
||||
sockets.in(roomName).emit('event:chats.edit', {
|
||||
messages: messages,
|
||||
});
|
||||
}
|
||||
|
||||
plugins.hooks.fire('action:messaging.edit', {
|
||||
message: { ...messages[0], content: payload.content },
|
||||
});
|
||||
|
||||
@@ -55,10 +55,6 @@ Messaging.getMessages = async (params) => {
|
||||
const messageData = await Messaging.getMessagesData(mids, uid, roomId, isNew);
|
||||
messageData.forEach((msg) => {
|
||||
msg.index = indices[msg.messageId.toString()];
|
||||
msg.isOwner = msg.fromuid === parseInt(uid, 10);
|
||||
if (msg.deleted && !msg.isOwner) {
|
||||
msg.content = `<p>[[modules:chat.message-deleted]]</p>`;
|
||||
}
|
||||
});
|
||||
|
||||
return messageData;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const os = require('os');
|
||||
const nconf = require('nconf');
|
||||
const winston = require('winston');
|
||||
@@ -301,18 +302,16 @@ Sockets.getUidsInRoom = async function (room) {
|
||||
return [];
|
||||
}
|
||||
const ioRoom = Sockets.server.in(room);
|
||||
const uids = {};
|
||||
const uids = [];
|
||||
if (ioRoom) {
|
||||
const sockets = await ioRoom.fetchSockets();
|
||||
for (const s of sockets) {
|
||||
for (const r of s.rooms) {
|
||||
if (r.startsWith('uid_')) {
|
||||
uids[r.split('_').pop()] = 1;
|
||||
}
|
||||
if (s && s.data && s.data.uid > 0) {
|
||||
uids.push(s.data.uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Object.keys(uids);
|
||||
return _.uniq(uids);
|
||||
};
|
||||
|
||||
Sockets.warnDeprecated = (socket, replacement) => {
|
||||
|
||||
@@ -659,6 +659,13 @@ describe('Messaging Library', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not show deleted message to other users', async () => {
|
||||
const { body } = await callv3API('get', `/chats/${roomId}/messages/${mid}`, {}, 'herp');
|
||||
const message = body.response;
|
||||
assert.strictEqual(message.deleted, 1);
|
||||
assert.strictEqual(message.content, '<p>[[modules:chat.message-deleted]]</p>');
|
||||
});
|
||||
|
||||
it('should error out if a message is deleted again', async () => {
|
||||
const { statusCode, body } = await callv3API('delete', `/chats/${roomId}/messages/${mid}`, {}, 'foo');
|
||||
assert.strictEqual(statusCode, 400);
|
||||
|
||||
Reference in New Issue
Block a user