1
0
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:
Akihiko Odaki
2018-04-03 16:33:16 +09:00
parent 1a347ae9a0
commit 6b66ec1231
6 changed files with 108 additions and 37 deletions

View 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;
};

View 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
})),
]);
};