From 1462ff12de08e8810023658e8ff7b5ee8bd7965b Mon Sep 17 00:00:00 2001 From: mei23 Date: Sat, 5 Oct 2019 14:47:03 +0900 Subject: [PATCH] Handle some additional reaction activities --- src/misc/reaction-lib.ts | 6 ++++-- src/remote/activitypub/kernel/like.ts | 5 +++-- src/remote/activitypub/kernel/undo/index.ts | 2 ++ src/remote/activitypub/type.ts | 4 ++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/misc/reaction-lib.ts b/src/misc/reaction-lib.ts index ced90ce78f..3d5608ef33 100644 --- a/src/misc/reaction-lib.ts +++ b/src/misc/reaction-lib.ts @@ -15,7 +15,9 @@ const basic10: Record = { '🍮': 'pudding', }; -export async function getFallbackReaction(): Promise { +export async function getFallbackReaction(reaction?: string | null): Promise { + if (reaction === '👎') return reaction; + const meta = await fetchMeta(); return meta.useStarForReactionFallback ? 'star' : 'like'; } @@ -26,7 +28,7 @@ export async function toDbReaction(reaction?: string | null, enableEmoji = true) // 既存の文字列リアクションはそのまま if (Object.values(basic10).includes(reaction)) return reaction; - if (!enableEmoji) return await getFallbackReaction(); + if (!enableEmoji) return await getFallbackReaction(reaction); // Unicode絵文字 const match = emojiRegex.exec(reaction); diff --git a/src/remote/activitypub/kernel/like.ts b/src/remote/activitypub/kernel/like.ts index 23b4aedd15..23dad682e2 100644 --- a/src/remote/activitypub/kernel/like.ts +++ b/src/remote/activitypub/kernel/like.ts @@ -15,9 +15,10 @@ export default async (actor: IRemoteUser, activity: ILike) => { const note = await Notes.findOne(noteId); if (note == null) { - apLogger.warn(`Like activity recivied, but no such note: ${id}`, { id }); + apLogger.warn(`${activity.type} activity recivied, but no such note: ${id}`, { id }); return; } - await create(actor, note, activity._misskey_reaction); + const reaction = activity.type === 'Dislike' ? '👎' : activity._misskey_reaction || activity.content || activity.name; + await create(actor, note, reaction); }; diff --git a/src/remote/activitypub/kernel/undo/index.ts b/src/remote/activitypub/kernel/undo/index.ts index f49f66cc69..6dfedf58e0 100644 --- a/src/remote/activitypub/kernel/undo/index.ts +++ b/src/remote/activitypub/kernel/undo/index.ts @@ -37,6 +37,8 @@ export default async (actor: IRemoteUser, activity: IUndo): Promise => { unblock(actor, object as IBlock); break; case 'Like': + case 'Dislike': + case 'EmojiReaction': undoLike(actor, object as ILike); break; case 'Announce': diff --git a/src/remote/activitypub/type.ts b/src/remote/activitypub/type.ts index 62475faefc..55fa418cea 100644 --- a/src/remote/activitypub/type.ts +++ b/src/remote/activitypub/type.ts @@ -159,7 +159,7 @@ export interface IRemove extends IActivity { } export interface ILike extends IActivity { - type: 'Like'; + type: 'Like' | 'Dislike' | 'EmojiReaction'; _misskey_reaction?: string; } @@ -180,6 +180,6 @@ export const isAccept = (object: IObject): object is IAccept => object.type === export const isReject = (object: IObject): object is IReject => object.type === 'Reject'; export const isAdd = (object: IObject): object is IAdd => object.type === 'Add'; export const isRemove = (object: IObject): object is IRemove => object.type === 'Remove'; -export const isLike = (object: IObject): object is ILike => object.type === 'Like'; +export const isLike = (object: IObject): object is ILike => object.type === 'Like' || object.type === 'Dislike' || object.type === 'EmojiReaction'; export const isAnnounce = (object: IObject): object is IAnnounce => object.type === 'Announce'; export const isBlock = (object: IObject): object is IBlock => object.type === 'Block';