Skip to content

Commit

Permalink
第3インスタンスへのLikeも受け入れるように
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Feb 2, 2020
1 parent 117d726 commit 3989ee9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 37 deletions.
26 changes: 6 additions & 20 deletions src/remote/activitypub/kernel/like.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import * as mongo from 'mongodb';
import Note from '../../../models/note';
import { IRemoteUser } from '../../../models/user';
import { ILike } from '../type';
import { ILike, getApId } from '../type';
import create from '../../../services/note/reaction/create';
import { isSelfHost, extractApHost } from '../../../misc/convert-host';
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;
const targetUri = getApId(activity.object);

if (!isSelfHost(extractApHost(id))) {
apLogger.warn(`skip ${activity.type} to foreign host (${id})`);
return;
}

// Transform:
// https://misskey.ex/notes/xxxx to
// xxxx
const noteId = new mongo.ObjectID(id.split('/').pop());

const note = await Note.findOne({ _id: noteId });
if (note === null) {
throw new Error();
}
const note = await fetchNote(targetUri);
if (!note) return `skip: target note not found ${targetUri}`;

await create(actor, note, activity._misskey_reaction || activity.content || activity.name);
return `ok`;
};
24 changes: 7 additions & 17 deletions src/remote/activitypub/kernel/undo/like.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
import * as mongo from 'mongodb';
import { IRemoteUser } from '../../../../models/user';
import { ILike } from '../../type';
import Note from '../../../../models/note';
import { ILike, getApId } from '../../type';
import deleteReaction from '../../../../services/note/reaction/delete';
import { isSelfHost, extractApHost } from '../../../../misc/convert-host';
import { apLogger } from '../../logger';
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;
export default async (actor: IRemoteUser, activity: ILike) => {
const targetUri = getApId(activity.object);

if (!isSelfHost(extractApHost(id))) {
apLogger.warn(`skip Undo ${activity.type} to foreign host (${id})`);
return;
}
const noteId = new mongo.ObjectID(id.split('/').pop());

const note = await Note.findOne({ _id: noteId });
if (note === null) {
throw 'note not found';
}
const note = await fetchNote(targetUri);
if (!note) return `skip: target note not found ${targetUri}`;

await deleteReaction(actor, note);
return `ok`;
};

0 comments on commit 3989ee9

Please sign in to comment.