mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: federate on chat message edit, #12834
This commit is contained in:
@@ -289,6 +289,23 @@ activitypubApi.update.note = enabledCheck(async (caller, { post }) => {
|
|||||||
await activitypub.send('uid', caller.uid, Array.from(targets), payload);
|
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 = {};
|
||||||
|
|
||||||
activitypubApi.delete.note = enabledCheck(async (caller, { pid }) => {
|
activitypubApi.delete.note = enabledCheck(async (caller, { pid }) => {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const db = require('../database');
|
||||||
const meta = require('../meta');
|
const meta = require('../meta');
|
||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
|
const api = require('../api');
|
||||||
const privileges = require('../privileges');
|
const privileges = require('../privileges');
|
||||||
|
|
||||||
const sockets = require('../socket.io');
|
const sockets = require('../socket.io');
|
||||||
@@ -11,6 +13,7 @@ const sockets = require('../socket.io');
|
|||||||
module.exports = function (Messaging) {
|
module.exports = function (Messaging) {
|
||||||
Messaging.editMessage = async (uid, mid, roomId, content) => {
|
Messaging.editMessage = async (uid, mid, roomId, content) => {
|
||||||
await Messaging.checkContent(content);
|
await Messaging.checkContent(content);
|
||||||
|
const isPublic = parseInt(await db.getObjectField(`chat:room:${roomId}`, 'public'), 10) === 1;
|
||||||
const raw = await Messaging.getMessageField(mid, 'content');
|
const raw = await Messaging.getMessageField(mid, 'content');
|
||||||
if (raw === content) {
|
if (raw === content) {
|
||||||
return;
|
return;
|
||||||
@@ -33,6 +36,10 @@ module.exports = function (Messaging) {
|
|||||||
sockets.in(roomName).emit('event:chats.edit', {
|
sockets.in(roomName).emit('event:chats.edit', {
|
||||||
messages: messages,
|
messages: messages,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!isPublic) {
|
||||||
|
api.activitypub.update.privateNote({ uid: messages[0].fromuid }, { messageObj: messages[0] });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins.hooks.fire('action:messaging.edit', {
|
plugins.hooks.fire('action:messaging.edit', {
|
||||||
|
|||||||
Reference in New Issue
Block a user