mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-22 09:57:29 -07:00
unFollowAll on suspend (#4490)
* unFollowAll on suspend * use services * silent
This commit is contained in:
parent
bcdd4ba366
commit
ccc7d4a98d
2 changed files with 25 additions and 3 deletions
|
@ -1,7 +1,9 @@
|
||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import ID, { transform } from '../../../../misc/cafy-id';
|
import ID, { transform } from '../../../../misc/cafy-id';
|
||||||
import define from '../../define';
|
import define from '../../define';
|
||||||
import User from '../../../../models/user';
|
import User, { IUser } from '../../../../models/user';
|
||||||
|
import Following from '../../../../models/following';
|
||||||
|
import deleteFollowing from '../../../../services/following/delete';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
desc: {
|
desc: {
|
||||||
|
@ -51,5 +53,25 @@ export default define(meta, async (ps) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
unFollowAll(user);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function unFollowAll(follower: IUser) {
|
||||||
|
const followings = await Following.find({
|
||||||
|
followerId: follower._id
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const following of followings) {
|
||||||
|
const followee = await User.findOne({
|
||||||
|
_id: following.followeeId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (followee == null) {
|
||||||
|
throw `Cant find followee ${following.followeeId}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
await deleteFollowing(follower, followee, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import instanceChart from '../../services/chart/instance';
|
||||||
|
|
||||||
const logger = new Logger('following/delete');
|
const logger = new Logger('following/delete');
|
||||||
|
|
||||||
export default async function(follower: IUser, followee: IUser) {
|
export default async function(follower: IUser, followee: IUser, silent = false) {
|
||||||
const following = await Following.findOne({
|
const following = await Following.findOne({
|
||||||
followerId: follower._id,
|
followerId: follower._id,
|
||||||
followeeId: followee._id
|
followeeId: followee._id
|
||||||
|
@ -71,7 +71,7 @@ export default async function(follower: IUser, followee: IUser) {
|
||||||
perUserFollowingChart.update(follower, followee, false);
|
perUserFollowingChart.update(follower, followee, false);
|
||||||
|
|
||||||
// Publish unfollow event
|
// Publish unfollow event
|
||||||
if (isLocalUser(follower)) {
|
if (!silent && isLocalUser(follower)) {
|
||||||
packUser(followee, follower, {
|
packUser(followee, follower, {
|
||||||
detail: true
|
detail: true
|
||||||
}).then(packed => publishMainStream(follower._id, 'unfollow', packed));
|
}).then(packed => publishMainStream(follower._id, 'unfollow', packed));
|
||||||
|
|
Loading…
Reference in a new issue