From 4683e1a93e1a03c127ba9719ca25087af1cbb573 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 18 Apr 2023 22:48:40 +0200 Subject: [PATCH] activitypub: no longer deliver chat read Prospectively, the messaging messages will be removed as objects so it does not make sense to refactor this to match the remainder of refactoring away the user from deliver. It is just easier to remove this use of delivering something that is not an activity. Changelog: Removed --- .../src/remote/activitypub/renderer/read.ts | 9 --------- .../api/common/read-messaging-message.ts | 19 ------------------- .../api/endpoints/messaging/messages.ts | 7 +------ .../server/api/stream/channels/messaging.ts | 9 +-------- 4 files changed, 2 insertions(+), 42 deletions(-) delete mode 100644 packages/backend/src/remote/activitypub/renderer/read.ts diff --git a/packages/backend/src/remote/activitypub/renderer/read.ts b/packages/backend/src/remote/activitypub/renderer/read.ts deleted file mode 100644 index a30e649f6..000000000 --- a/packages/backend/src/remote/activitypub/renderer/read.ts +++ /dev/null @@ -1,9 +0,0 @@ -import config from '@/config/index.js'; -import { User } from '@/models/entities/user.js'; -import { MessagingMessage } from '@/models/entities/messaging-message.js'; - -export const renderReadActivity = (user: { id: User['id'] }, message: MessagingMessage) => ({ - type: 'Read', - actor: `${config.url}/users/${user.id}`, - object: message.uri, -}); diff --git a/packages/backend/src/server/api/common/read-messaging-message.ts b/packages/backend/src/server/api/common/read-messaging-message.ts index 5f3ea8e27..9f713a9d6 100644 --- a/packages/backend/src/server/api/common/read-messaging-message.ts +++ b/packages/backend/src/server/api/common/read-messaging-message.ts @@ -7,10 +7,6 @@ import { MessagingMessages, UserGroupJoinings, Users } from '@/models/index.js'; import { IdentifiableError } from '@/misc/identifiable-error.js'; import { UserGroup } from '@/models/entities/user-group.js'; import { toArray } from '@/prelude/array.js'; -import { renderReadActivity } from '@/remote/activitypub/renderer/read.js'; -import { renderActivity } from '@/remote/activitypub/renderer/index.js'; -import { deliver } from '@/queue/index.js'; -import orderedCollection from '@/remote/activitypub/renderer/ordered-collection.js'; /** * Mark messages as read @@ -133,18 +129,3 @@ export async function readGroupMessagingMessage( } } } - -export async function deliverReadActivity(user: { id: User['id']; host: null; }, recipient: IRemoteUser, messages: MessagingMessage | MessagingMessage[]) { - const contents = toArray(messages) - .filter(x => x.uri) - .map(x => renderReadActivity(user, x)); - - if (contents.length > 1) { - const collection = orderedCollection(null, contents.length, undefined, undefined, contents); - deliver(renderActivity(collection), recipient.inbox); - } else { - for (const content of contents) { - deliver(renderActivity(content), recipient.inbox); - } - } -} diff --git a/packages/backend/src/server/api/endpoints/messaging/messages.ts b/packages/backend/src/server/api/endpoints/messaging/messages.ts index f00b84e49..db7184a0b 100644 --- a/packages/backend/src/server/api/endpoints/messaging/messages.ts +++ b/packages/backend/src/server/api/endpoints/messaging/messages.ts @@ -4,7 +4,7 @@ import define from '@/server/api/define.js'; import { ApiError } from '@/server/api/error.js'; import { getUser } from '@/server/api/common/getters.js'; import { makePaginationQuery } from '@/server/api/common/make-pagination-query.js'; -import { readUserMessagingMessage, readGroupMessagingMessage, deliverReadActivity } from '@/server/api/common/read-messaging-message.js'; +import { readUserMessagingMessage, readGroupMessagingMessage } from '@/server/api/common/read-messaging-message.js'; export const meta = { tags: ['messaging'], @@ -75,11 +75,6 @@ export default define(meta, paramDef, async (ps, user) => { // Mark all as read if (ps.markAsRead) { readUserMessagingMessage(user.id, recipient.id, messages.filter(m => m.recipientId === user.id).map(x => x.id)); - - // リモートユーザーとのメッセージだったら既読配信 - if (Users.isLocalUser(user) && Users.isRemoteUser(recipient)) { - deliverReadActivity(user, recipient, messages); - } } return await Promise.all(messages.map(message => MessagingMessages.pack(message, user, { diff --git a/packages/backend/src/server/api/stream/channels/messaging.ts b/packages/backend/src/server/api/stream/channels/messaging.ts index e10ede776..009acf440 100644 --- a/packages/backend/src/server/api/stream/channels/messaging.ts +++ b/packages/backend/src/server/api/stream/channels/messaging.ts @@ -1,7 +1,7 @@ import { UserGroupJoinings, Users, MessagingMessages } from '@/models/index.js'; import { User, ILocalUser, IRemoteUser } from '@/models/entities/user.js'; import { UserGroup } from '@/models/entities/user-group.js'; -import { readUserMessagingMessage, readGroupMessagingMessage, deliverReadActivity } from '@/server/api/common/read-messaging-message.js'; +import { readUserMessagingMessage, readGroupMessagingMessage } from '@/server/api/common/read-messaging-message.js'; import Channel from '@/server/api/stream/channel.js'; import { StreamMessages } from '@/server/api/stream/types.js'; @@ -69,13 +69,6 @@ export default class extends Channel { case 'read': if (this.otherpartyId) { readUserMessagingMessage(this.user!.id, this.otherpartyId, [body.id]); - - // リモートユーザーからのメッセージだったら既読配信 - if (Users.isLocalUser(this.user!) && Users.isRemoteUser(this.otherparty!)) { - MessagingMessages.findOneBy({ id: body.id }).then(message => { - if (message) deliverReadActivity(this.user as ILocalUser, this.otherparty as IRemoteUser, message); - }); - } } else if (this.groupId) { readGroupMessagingMessage(this.user!.id, this.groupId, [body.id]); }