mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-04 00:15:35 +02:00
Implement unfollow by remote account
This commit is contained in:
23
src/remote/activitypub/act/undo/index.ts
Normal file
23
src/remote/activitypub/act/undo/index.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import act from '../../act';
|
||||
import unfollow from './unfollow';
|
||||
|
||||
export default async (resolver, actor, activity) => {
|
||||
if ('actor' in activity && actor.account.uri !== activity.actor) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
const results = await act(resolver, actor, activity.object);
|
||||
|
||||
await Promise.all(results.map(async result => {
|
||||
if (result === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (result.object.$ref) {
|
||||
case 'following':
|
||||
await unfollow(result.resolver, result.object);
|
||||
}
|
||||
}));
|
||||
|
||||
return null;
|
||||
};
|
||||
24
src/remote/activitypub/act/undo/unfollow.ts
Normal file
24
src/remote/activitypub/act/undo/unfollow.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import FollowedLog from '../../../../models/followed-log';
|
||||
import Following from '../../../../models/following';
|
||||
import FollowingLog from '../../../../models/following-log';
|
||||
import User from '../../../../models/user';
|
||||
|
||||
export default async (resolver, { $id }) => {
|
||||
const following = await Following.findOneAndDelete({ _id: $id });
|
||||
if (following === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
User.update({ _id: following.followerId }, { $inc: { followingCount: -1 } }),
|
||||
User.findOne({ _id: following.followerId }).then(({ followingCount }) => FollowingLog.insert({
|
||||
userId: following.followerId,
|
||||
count: followingCount - 1
|
||||
})),
|
||||
User.update({ _id: following.followeeId }, { $inc: { followersCount: -1 } }),
|
||||
User.findOne({ _id: following.followeeId }).then(({ followersCount }) => FollowedLog.insert({
|
||||
userId: following.followeeId,
|
||||
count: followersCount - 1
|
||||
})),
|
||||
]);
|
||||
};
|
||||
Reference in New Issue
Block a user