summaryrefslogtreecommitdiff
path: root/src/remote/activitypub/kernel/undo
diff options
context:
space:
mode:
Diffstat (limited to 'src/remote/activitypub/kernel/undo')
-rw-r--r--src/remote/activitypub/kernel/undo/block.ts13
-rw-r--r--src/remote/activitypub/kernel/undo/follow.ts27
-rw-r--r--src/remote/activitypub/kernel/undo/index.ts4
-rw-r--r--src/remote/activitypub/kernel/undo/like.ts14
4 files changed, 26 insertions, 32 deletions
diff --git a/src/remote/activitypub/kernel/undo/block.ts b/src/remote/activitypub/kernel/undo/block.ts
index 4a22ac7924..8ef70a9bef 100644
--- a/src/remote/activitypub/kernel/undo/block.ts
+++ b/src/remote/activitypub/kernel/undo/block.ts
@@ -1,28 +1,27 @@
-import * as mongo from 'mongodb';
-import User, { IRemoteUser } from '../../../../models/user';
import config from '../../../../config';
import { IBlock } from '../../type';
import unblock from '../../../../services/blocking/delete';
import { apLogger } from '../../logger';
+import { IRemoteUser } from '../../../../models/entities/user';
+import { Users } from '../../../../models';
const logger = apLogger;
export default async (actor: IRemoteUser, activity: IBlock): Promise<void> => {
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
+ if (id == null) throw new Error('missing id');
const uri = activity.id || activity;
logger.info(`UnBlock: ${uri}`);
if (!id.startsWith(config.url + '/')) {
- return null;
+ return;
}
- const blockee = await User.findOne({
- _id: new mongo.ObjectID(id.split('/').pop())
- });
+ const blockee = await Users.findOne(id.split('/').pop());
- if (blockee === null) {
+ if (blockee == null) {
throw new Error('blockee not found');
}
diff --git a/src/remote/activitypub/kernel/undo/follow.ts b/src/remote/activitypub/kernel/undo/follow.ts
index af06aa5b31..d75f055640 100644
--- a/src/remote/activitypub/kernel/undo/follow.ts
+++ b/src/remote/activitypub/kernel/undo/follow.ts
@@ -1,24 +1,21 @@
-import * as mongo from 'mongodb';
-import User, { IRemoteUser } from '../../../../models/user';
import config from '../../../../config';
import unfollow from '../../../../services/following/delete';
import cancelRequest from '../../../../services/following/requests/cancel';
import { IFollow } from '../../type';
-import FollowRequest from '../../../../models/follow-request';
-import Following from '../../../../models/following';
+import { IRemoteUser } from '../../../../models/entities/user';
+import { Users, FollowRequests, Followings } from '../../../../models';
export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
const id = typeof activity.object == 'string' ? activity.object : activity.object.id;
+ if (id == null) throw new Error('missing id');
if (!id.startsWith(config.url + '/')) {
- return null;
+ return;
}
- const followee = await User.findOne({
- _id: new mongo.ObjectID(id.split('/').pop())
- });
+ const followee = await Users.findOne(id.split('/').pop());
- if (followee === null) {
+ if (followee == null) {
throw new Error('followee not found');
}
@@ -26,14 +23,14 @@ export default async (actor: IRemoteUser, activity: IFollow): Promise<void> => {
throw new Error('フォロー解除しようとしているユーザーはローカルユーザーではありません');
}
- const req = await FollowRequest.findOne({
- followerId: actor._id,
- followeeId: followee._id
+ const req = await FollowRequests.findOne({
+ followerId: actor.id,
+ followeeId: followee.id
});
- const following = await Following.findOne({
- followerId: actor._id,
- followeeId: followee._id
+ const following = await Followings.findOne({
+ followerId: actor.id,
+ followeeId: followee.id
});
if (req) {
diff --git a/src/remote/activitypub/kernel/undo/index.ts b/src/remote/activitypub/kernel/undo/index.ts
index 80b44fae04..5f2e58c3bf 100644
--- a/src/remote/activitypub/kernel/undo/index.ts
+++ b/src/remote/activitypub/kernel/undo/index.ts
@@ -1,4 +1,4 @@
-import { IRemoteUser } from '../../../../models/user';
+import { IRemoteUser } from '../../../../models/entities/user';
import { IUndo, IFollow, IBlock, ILike } from '../../type';
import unfollow from './follow';
import unblock from './block';
@@ -39,6 +39,4 @@ export default async (actor: IRemoteUser, activity: IUndo): Promise<void> => {
undoLike(actor, object as ILike);
break;
}
-
- return null;
};
diff --git a/src/remote/activitypub/kernel/undo/like.ts b/src/remote/activitypub/kernel/undo/like.ts
index b324ec854c..2678828a9a 100644
--- a/src/remote/activitypub/kernel/undo/like.ts
+++ b/src/remote/activitypub/kernel/undo/like.ts
@@ -1,20 +1,20 @@
-import * as mongo from 'mongodb';
-import { IRemoteUser } from '../../../../models/user';
+import { IRemoteUser } from '../../../../models/entities/user';
import { ILike } from '../../type';
-import Note from '../../../../models/note';
import deleteReaction from '../../../../services/note/reaction/delete';
+import { Notes } from '../../../../models';
/**
* 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');
- const noteId = new mongo.ObjectID(id.split('/').pop());
+ const noteId = id.split('/').pop();
- const note = await Note.findOne({ _id: noteId });
- if (note === null) {
- throw 'note not found';
+ const note = await Notes.findOne(noteId);
+ if (note == null) {
+ throw new Error('note not found');
}
await deleteReaction(actor, note);