* Resolve #5587

* stat
This commit is contained in:
MeiMei 2019-11-09 18:24:41 +09:00 committed by syuilo
parent 1b919cd7e3
commit 0646f77ed1
2 changed files with 33 additions and 14 deletions

View file

@ -24,6 +24,22 @@ export default async function(follower: User, followee: User, silent = false) {
await Followings.delete(following.id);
decrementFollowing(follower, followee);
// Publish unfollow event
if (!silent && Users.isLocalUser(follower)) {
Users.pack(followee, follower, {
detail: true
}).then(packed => publishMainStream(follower.id, 'unfollow', packed));
}
if (Users.isLocalUser(follower) && Users.isRemoteUser(followee)) {
const content = renderActivity(renderUndo(renderFollow(follower, followee), follower));
deliver(follower, content, followee.inbox);
}
}
export async function decrementFollowing(follower: User, followee: User) {
//#region Decrement following count
Users.decrement({ id: follower.id }, 'followingCount', 1);
//#endregion
@ -47,16 +63,4 @@ export default async function(follower: User, followee: User, silent = false) {
//#endregion
perUserFollowingChart.update(follower, followee, false);
// Publish unfollow event
if (!silent && Users.isLocalUser(follower)) {
Users.pack(followee, follower, {
detail: true
}).then(packed => publishMainStream(follower.id, 'unfollow', packed));
}
if (Users.isLocalUser(follower) && Users.isRemoteUser(followee)) {
const content = renderActivity(renderUndo(renderFollow(follower, followee), follower));
deliver(follower, content, followee.inbox);
}
}

View file

@ -4,7 +4,8 @@ import renderReject from '../../../remote/activitypub/renderer/reject';
import { deliver } from '../../../queue';
import { publishMainStream } from '../../stream';
import { User, ILocalUser } from '../../../models/entities/user';
import { Users, FollowRequests } from '../../../models';
import { Users, FollowRequests, Followings } from '../../../models';
import { decrementFollowing } from '../delete';
export default async function(followee: User, follower: User) {
if (Users.isRemoteUser(follower)) {
@ -17,11 +18,25 @@ export default async function(followee: User, follower: User) {
deliver(followee as ILocalUser, content, follower.inbox);
}
await FollowRequests.delete({
const request = await FollowRequests.findOne({
followeeId: followee.id,
followerId: follower.id
});
if (request) {
await FollowRequests.delete(request.id);
} else {
const following = await Followings.findOne({
followeeId: followee.id,
followerId: follower.id
});
if (following) {
await Followings.delete(following.id);
decrementFollowing(follower, followee);
}
}
Users.pack(followee, follower, {
detail: true
}).then(packed => publishMainStream(follower.id, 'unfollow', packed));