Skip to content

Commit

Permalink
delete following when remote user is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
atsu1125 committed Aug 16, 2024
1 parent 856d779 commit fcbc770
Showing 1 changed file with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion src/queue/processors/db/delete-account.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import * as Bull from 'bull';
import { queueLogger } from '../../logger';
import { DriveFiles, Notes, Users } from '../../../models/index';
import { DriveFiles, Notes, Users, FollowRequests, Followings } from '../../../models/index';
import { DbUserJobData } from '../../../queue/types';
import { Note } from '../../../models/entities/note';
import { DriveFile } from '../../../models/entities/drive-file';
import { MoreThan } from 'typeorm';
import { deleteFileSync } from '../../../services/drive/delete-file';
import deleteFollowing from '../../../services/following/delete';
import cancelFollowRequest from '../../../services/following/requests/cancel';
import rejectFollowRequest from '../../../services/following/requests/reject';

const logger = queueLogger.createSubLogger('delete-account');

Expand All @@ -17,6 +20,83 @@ export async function deleteAccount(job: Bull.Job<DbUserJobData>): Promise<strin
return;
}

{ // Reject Follows
// When deleting a remote account, the account obviously doesn't
// actually become deleted on its origin server, i.e. unlike a
// locally deleted account it continues to have access to its home
// feed and other content. To prevent it from being able to continue
// to access toots it would receive because it follows local accounts,
// we have to force it to unfollow them.

if (!Users.isLocalUser(job.data.user)) {
const follower = user;

const followings = await Followings.find({
followerId: follower.id,
});

for (const following of followings) {
const followee = await Users.findOne({
id: following.followeeId,
});

if (followee != null) {
await deleteFollowing(follower, followee, true);
}
}

const requests = await FollowRequests.find({
followerId: follower.id,
});

for (const request of requests) {
const followee = await Users.findOne(request.followeeId);

if (followee != null) {
await rejectFollowRequest(followee, follower);
}
}
}
}

{ // Undo Follows
// When deleting a remote account, the account obviously doesn't
// actually become deleted on its origin server, but following relationships
// are severed on our end. Therefore, make the remote server aware that the
// follow relationships are severed to avoid confusion and potential issues
// if the remote account gets un-suspended.

if (!Users.isLocalUser(job.data.user)) {
const followee = user;

const followers = await Followings.find({
followeeId: followee.id,
});

for (const following of followers) {
const follower = await Users.findOne({
id: following.followerId,
});

if (follower != null) {
await deleteFollowing(follower, followee, true);
}
}

const requests = await FollowRequests.find({
followeeId: followee.id,
});

for (const request of requests) {
const follower = await Users.findOne(request.followerId);

if (follower != null) {
await cancelFollowRequest(followee, follower);
}
}
}
}

{ // Delete notes
let cursor: Note['id'] | null = null;

Expand Down

0 comments on commit fcbc770

Please sign in to comment.