2023-05-18 11:25:57 +00:00
|
|
|
import { IRemoteUser } from '@/models/entities/user.js';
|
2022-10-16 21:49:41 +00:00
|
|
|
import { createReaction } from '@/services/note/reaction/create.js';
|
2022-08-03 11:18:33 +00:00
|
|
|
import { ILike, getApId } from '../type.js';
|
2023-05-30 04:17:56 +00:00
|
|
|
import { fetchNote } from '../models/note.js';
|
|
|
|
import { extractEmojis } from '../models/tag.js';
|
2018-04-04 10:29:06 +00:00
|
|
|
|
2023-05-18 11:25:57 +00:00
|
|
|
export default async (actor: IRemoteUser, activity: ILike) => {
|
2020-02-03 23:26:00 +00:00
|
|
|
const targetUri = getApId(activity.object);
|
2018-04-04 10:29:06 +00:00
|
|
|
|
2020-02-03 23:26:00 +00:00
|
|
|
const note = await fetchNote(targetUri);
|
|
|
|
if (!note) return `skip: target note not found ${targetUri}`;
|
2018-04-04 10:29:06 +00:00
|
|
|
|
2020-04-13 15:42:59 +00:00
|
|
|
await extractEmojis(activity.tag || [], actor.host).catch(() => null);
|
|
|
|
|
2023-02-11 16:43:44 +00:00
|
|
|
return await createReaction(actor, note, activity.content || activity.name).catch(e => {
|
2021-05-11 03:41:02 +00:00
|
|
|
if (e.id === '51c42bb4-931a-456b-bff7-e5a8a70dd298') {
|
|
|
|
return 'skip: already reacted';
|
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}).then(() => 'ok');
|
2018-04-04 10:29:06 +00:00
|
|
|
};
|