* Resolve #5587

* stat
This commit is contained in:
MeiMei 2019-11-09 18:24:41 +09:00 committed by syuilo
parent 8ada1725bf
commit b34b728fbb
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); 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 //#region Decrement following count
Users.decrement({ id: follower.id }, 'followingCount', 1); Users.decrement({ id: follower.id }, 'followingCount', 1);
//#endregion //#endregion
@ -47,16 +63,4 @@ export default async function(follower: User, followee: User, silent = false) {
//#endregion //#endregion
perUserFollowingChart.update(follower, followee, false); 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 { deliver } from '../../../queue';
import { publishMainStream } from '../../stream'; import { publishMainStream } from '../../stream';
import { User, ILocalUser } from '../../../models/entities/user'; 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) { export default async function(followee: User, follower: User) {
if (Users.isRemoteUser(follower)) { if (Users.isRemoteUser(follower)) {
@ -17,11 +18,25 @@ export default async function(followee: User, follower: User) {
deliver(followee as ILocalUser, content, follower.inbox); deliver(followee as ILocalUser, content, follower.inbox);
} }
await FollowRequests.delete({ const request = await FollowRequests.findOne({
followeeId: followee.id, followeeId: followee.id,
followerId: follower.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, { Users.pack(followee, follower, {
detail: true detail: true
}).then(packed => publishMainStream(follower.id, 'unfollow', packed)); }).then(packed => publishMainStream(follower.id, 'unfollow', packed));