summaryrefslogtreecommitdiff
path: root/src/remote
diff options
context:
space:
mode:
authorMeiMei <30769358+mei23@users.noreply.github.com>2020-02-04 08:26:00 +0900
committerGitHub <noreply@github.com>2020-02-04 08:26:00 +0900
commitb7a4f286b02c8ebb376779569e5564f52496913e (patch)
treee113d71516c362eabd7034b3503769d343ec3249 /src/remote
parentAdd Unicode 12.1 Emojis (#5825) (diff)
downloadsharkey-b7a4f286b02c8ebb376779569e5564f52496913e.tar.gz
sharkey-b7a4f286b02c8ebb376779569e5564f52496913e.tar.bz2
sharkey-b7a4f286b02c8ebb376779569e5564f52496913e.zip
リモート投稿にリモートでされたリアクションが表示されるように (#5817)
* 第3インスタンスへのLikeも受け入れるように * リアクション済みだったらエラーにせずに置き換えるように * Likeを第3インスタンスにdeliverするように * fix * fix * 同じリアクションがすでにされていたら何もしない * リモートから自身の投稿へリアクションした場合にエラーにならないように
Diffstat (limited to 'src/remote')
-rw-r--r--src/remote/activitypub/kernel/like.ts21
-rw-r--r--src/remote/activitypub/kernel/undo/like.ts18
2 files changed, 14 insertions, 25 deletions
diff --git a/src/remote/activitypub/kernel/like.ts b/src/remote/activitypub/kernel/like.ts
index fa8983b38d..b25f80aedc 100644
--- a/src/remote/activitypub/kernel/like.ts
+++ b/src/remote/activitypub/kernel/like.ts
@@ -1,23 +1,16 @@
import { IRemoteUser } from '../../../models/entities/user';
-import { ILike } from '../type';
+import { ILike, getApId } from '../type';
import create from '../../../services/note/reaction/create';
-import { Notes } from '../../../models';
-import { apLogger } from '../logger';
+import { fetchNote } from '../models/note';
export default async (actor: IRemoteUser, activity: ILike) => {
- const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
- if (id == null) throw new Error('missing id');
+ const targetUri = getApId(activity.object);
- // Transform:
- // https://misskey.ex/notes/xxxx to
- // xxxx
- const noteId = id.split('/').pop();
+ const note = await fetchNote(targetUri);
+ if (!note) return `skip: target note not found ${targetUri}`;
- const note = await Notes.findOne(noteId);
- if (note == null) {
- apLogger.warn(`Like activity recivied, but no such note: ${id}`, { id });
- return;
- }
+ if (actor.id === note.userId) return `skip: cannot react to my note`;
await create(actor, note, activity._misskey_reaction || activity.content || activity.name);
+ return `ok`;
};
diff --git a/src/remote/activitypub/kernel/undo/like.ts b/src/remote/activitypub/kernel/undo/like.ts
index 2678828a9a..bd6930c66b 100644
--- a/src/remote/activitypub/kernel/undo/like.ts
+++ b/src/remote/activitypub/kernel/undo/like.ts
@@ -1,21 +1,17 @@
import { IRemoteUser } from '../../../../models/entities/user';
-import { ILike } from '../../type';
+import { ILike, getApId } from '../../type';
import deleteReaction from '../../../../services/note/reaction/delete';
-import { Notes } from '../../../../models';
+import { fetchNote } from '../../models/note';
/**
* Process Undo.Like activity
*/
-export default async (actor: IRemoteUser, activity: ILike): Promise<void> => {
- const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
- if (id == null) throw new Error('missing id');
+export default async (actor: IRemoteUser, activity: ILike) => {
+ const targetUri = getApId(activity.object);
- const noteId = id.split('/').pop();
-
- const note = await Notes.findOne(noteId);
- if (note == null) {
- throw new Error('note not found');
- }
+ const note = await fetchNote(targetUri);
+ if (!note) return `skip: target note not found ${targetUri}`;
await deleteReaction(actor, note);
+ return `ok`;
};