mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: send Update(Note) on chat message deletion and restoration, serving Tombstone if deleted
re: #12853
This commit is contained in:
@@ -107,8 +107,11 @@ inbox.update = async (req) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case isMessage: {
|
case isMessage: {
|
||||||
const roomId = await messaging.getMessageField(object.id, 'roomId');
|
const [roomId, deleted] = await messaging.getMessageFields(object.id, ['roomId', 'deleted']);
|
||||||
await messaging.editMessage(actor, object.id, roomId, object.content);
|
await messaging.editMessage(actor, object.id, roomId, object.content);
|
||||||
|
if (deleted) {
|
||||||
|
await api.chats.restoreMessage({ uid: actor }, { mid: object.id });
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,8 +143,9 @@ inbox.update = async (req) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case 'Tombstone': {
|
case 'Tombstone': {
|
||||||
const [isNote/* , isActor */] = await Promise.all([
|
const [isNote, isMessage/* , isActor */] = await Promise.all([
|
||||||
posts.exists(object.id),
|
posts.exists(object.id),
|
||||||
|
messaging.messageExists(object.id),
|
||||||
// db.isSortedSetMember('usersRemote:lastCrawled', object.id),
|
// db.isSortedSetMember('usersRemote:lastCrawled', object.id),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -151,6 +155,11 @@ inbox.update = async (req) => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case isMessage: {
|
||||||
|
await api.chats.deleteMessage({ uid: actor }, { mid: object.id });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// case isActor: {
|
// case isActor: {
|
||||||
// console.log('actor');
|
// console.log('actor');
|
||||||
// break;
|
// break;
|
||||||
|
|||||||
@@ -451,10 +451,20 @@ Mocks.notes.public = async (post) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Mocks.notes.private = async ({ messageObj }) => {
|
Mocks.notes.private = async ({ messageObj }) => {
|
||||||
// todo: deleted messages
|
const id = `${nconf.get('url')}/message/${messageObj.mid}`;
|
||||||
|
|
||||||
|
// Return a tombstone for a deleted message
|
||||||
|
if (messageObj.deleted === 1) {
|
||||||
|
return Mocks.tombstone({
|
||||||
|
id,
|
||||||
|
formerType: 'Note',
|
||||||
|
attributedTo: `${nconf.get('url')}/uid/${messageObj.fromuid}`,
|
||||||
|
// context: `${nconf.get('url')}/topic/${post.topic.tid}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let uids = await messaging.getUidsInRoom(messageObj.roomId, 0, -1);
|
let uids = await messaging.getUidsInRoom(messageObj.roomId, 0, -1);
|
||||||
uids = uids.filter(uid => String(uid) !== String(messageObj.fromuid)); // no author
|
uids = uids.filter(uid => String(uid) !== String(messageObj.fromuid)); // no author
|
||||||
const id = `${nconf.get('url')}/message/${messageObj.mid}`;
|
|
||||||
const to = new Set(uids.map(uid => (utils.isNumber(uid) ? `${nconf.get('url')}/uid/${uid}` : uid)));
|
const to = new Set(uids.map(uid => (utils.isNumber(uid) ? `${nconf.get('url')}/uid/${uid}` : uid)));
|
||||||
const published = messageObj.timestampISO;
|
const published = messageObj.timestampISO;
|
||||||
const updated = messageObj.edited ? messageObj.editedISO : undefined;
|
const updated = messageObj.edited ? messageObj.editedISO : undefined;
|
||||||
|
|||||||
@@ -288,16 +288,22 @@ activitypubApi.update.note = enabledCheck(async (caller, { post }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
activitypubApi.update.privateNote = enabledCheck(async (caller, { messageObj }) => {
|
activitypubApi.update.privateNote = enabledCheck(async (caller, { messageObj }) => {
|
||||||
|
if (!utils.isNumber(messageObj.mid)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { roomId } = messageObj;
|
const { roomId } = messageObj;
|
||||||
let targets = await messaging.getUidsInRoom(roomId, 0, -1);
|
let uids = await messaging.getUidsInRoom(roomId, 0, -1);
|
||||||
targets = targets.filter(uid => !utils.isNumber(uid)); // remote uids only
|
uids = uids.filter(uid => String(uid) !== String(messageObj.fromuid)); // no author
|
||||||
|
const to = uids.map(uid => (utils.isNumber(uid) ? `${nconf.get('url')}/uid/${uid}` : uid));
|
||||||
|
const targets = uids.filter(uid => !utils.isNumber(uid)); // remote uids only
|
||||||
|
|
||||||
const object = await activitypub.mocks.notes.private({ messageObj });
|
const object = await activitypub.mocks.notes.private({ messageObj });
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
id: `${object.id}#activity/create/${Date.now()}`,
|
id: `${object.id}#activity/create/${Date.now()}`,
|
||||||
type: 'Update',
|
type: 'Update',
|
||||||
to: object.to,
|
to,
|
||||||
object,
|
object,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const sockets = require('../socket.io');
|
const sockets = require('../socket.io');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
|
const api = require('../api');
|
||||||
|
|
||||||
module.exports = function (Messaging) {
|
module.exports = function (Messaging) {
|
||||||
Messaging.deleteMessage = async (mid, uid) => await doDeleteRestore(mid, 1, uid);
|
Messaging.deleteMessage = async (mid, uid) => await doDeleteRestore(mid, 1, uid);
|
||||||
@@ -18,6 +19,7 @@ module.exports = function (Messaging) {
|
|||||||
|
|
||||||
await Messaging.setMessageField(mid, 'deleted', state);
|
await Messaging.setMessageField(mid, 'deleted', state);
|
||||||
msgData.deleted = state;
|
msgData.deleted = state;
|
||||||
|
|
||||||
const ioRoom = sockets.in(`chat_room_${msgData.roomId}`);
|
const ioRoom = sockets.in(`chat_room_${msgData.roomId}`);
|
||||||
if (state === 1 && ioRoom) {
|
if (state === 1 && ioRoom) {
|
||||||
ioRoom.emit('event:chats.delete', mid);
|
ioRoom.emit('event:chats.delete', mid);
|
||||||
@@ -27,5 +29,7 @@ module.exports = function (Messaging) {
|
|||||||
ioRoom.emit('event:chats.restore', messages[0]);
|
ioRoom.emit('event:chats.restore', messages[0]);
|
||||||
plugins.hooks.fire('action:messaging.restore', { message: msgData });
|
plugins.hooks.fire('action:messaging.restore', { message: msgData });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api.activitypub.update.privateNote({ uid }, { messageObj: msgData });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user