Node.js based forum software built for the modern web
feat: federate on chat message edit, #12834
Julian Lam1659015c98f3
diff --git a/src/api/activitypub.js b/src/api/activitypub.jsindex 21b330416d..a303a80e04 100644--- a/src/api/activitypub.js+++ b/src/api/activitypub.js@@ -289,6 +289,23 @@ activitypubApi.update.note = enabledCheck(async (caller, { post }) => {await activitypub.send('uid', caller.uid, Array.from(targets), payload);});+activitypubApi.update.privateNote = enabledCheck(async (caller, { messageObj }) => {+ const { roomId } = messageObj;+ let targets = await messaging.getUidsInRoom(roomId, 0, -1);+ targets = targets.filter(uid => !utils.isNumber(uid)); // remote uids only++ const object = await activitypub.mocks.notes.private({ messageObj });++ const payload = {+ id: `${object.id}#activity/create/${Date.now()}`,+ type: 'Update',+ to: object.to,+ object,+ };++ await activitypub.send('uid', messageObj.fromuid, targets, payload);+});+activitypubApi.delete = {};activitypubApi.delete.note = enabledCheck(async (caller, { pid }) => {diff --git a/src/messaging/edit.js b/src/messaging/edit.jsindex d42f4ce0ce..03621bedf8 100644--- a/src/messaging/edit.js+++ b/src/messaging/edit.js@@ -1,8 +1,10 @@'use strict';+const db = require('../database');const meta = require('../meta');const user = require('../user');const plugins = require('../plugins');+const api = require('../api');const privileges = require('../privileges');const sockets = require('../socket.io');@@ -11,6 +13,7 @@ const sockets = require('../socket.io');module.exports = function (Messaging) {Messaging.editMessage = async (uid, mid, roomId, content) => {await Messaging.checkContent(content);+ const isPublic = parseInt(await db.getObjectField(`chat:room:${roomId}`, 'public'), 10) === 1;const raw = await Messaging.getMessageField(mid, 'content');if (raw === content) {return;@@ -33,6 +36,10 @@ module.exports = function (Messaging) {sockets.in(roomName).emit('event:chats.edit', {messages: messages,});++ if (!isPublic) {+ api.activitypub.update.privateNote({ uid: messages[0].fromuid }, { messageObj: messages[0] });+ }}plugins.hooks.fire('action:messaging.edit', {