diff options
| author | dakkar <dakkar@thenautilus.net> | 2025-02-24 13:07:23 +0000 |
|---|---|---|
| committer | dakkar <dakkar@thenautilus.net> | 2025-02-24 13:08:19 +0000 |
| commit | 687cb5b168e3e91177ea700166286c8a39d89c44 (patch) | |
| tree | e5e2003d2786fce814554891f4bb952b04440ca1 /packages/backend/src/core | |
| parent | delete scheduled notes when deleting account - fixes #936 (diff) | |
| download | sharkey-687cb5b168e3e91177ea700166286c8a39d89c44.tar.gz sharkey-687cb5b168e3e91177ea700166286c8a39d89c44.tar.bz2 sharkey-687cb5b168e3e91177ea700166286c8a39d89c44.zip | |
handle scheduled notes when migrating account - fixes #931
I'm not sure we want the "change ownership of notes if dst is local",
though
Diffstat (limited to 'packages/backend/src/core')
| -rw-r--r-- | packages/backend/src/core/AccountMoveService.ts | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/packages/backend/src/core/AccountMoveService.ts b/packages/backend/src/core/AccountMoveService.ts index 24d11f29ff..0eb8a76bff 100644 --- a/packages/backend/src/core/AccountMoveService.ts +++ b/packages/backend/src/core/AccountMoveService.ts @@ -9,7 +9,7 @@ import { IsNull, In, MoreThan, Not } from 'typeorm'; import { bindThis } from '@/decorators.js'; import { DI } from '@/di-symbols.js'; import type { MiLocalUser, MiRemoteUser, MiUser } from '@/models/User.js'; -import type { BlockingsRepository, FollowingsRepository, InstancesRepository, MiMeta, MutingsRepository, UserListMembershipsRepository, UsersRepository } from '@/models/_.js'; +import type { BlockingsRepository, FollowingsRepository, InstancesRepository, MiMeta, MutingsRepository, UserListMembershipsRepository, UsersRepository, NoteScheduleRepository, MiNoteSchedule } from '@/models/_.js'; import type { RelationshipJobData, ThinUser } from '@/queue/types.js'; import { IdService } from '@/core/IdService.js'; @@ -49,6 +49,9 @@ export class AccountMoveService { @Inject(DI.instancesRepository) private instancesRepository: InstancesRepository, + @Inject(DI.noteScheduleRepository) + private noteScheduleRepository: NoteScheduleRepository, + private userEntityService: UserEntityService, private idService: IdService, private apPersonService: ApPersonService, @@ -119,6 +122,7 @@ export class AccountMoveService { await Promise.all([ this.copyBlocking(src, dst), this.copyMutings(src, dst), + this.updateScheduledNotes(src, dst), this.updateLists(src, dst), ]); } catch { @@ -201,6 +205,32 @@ export class AccountMoveService { await this.mutingsRepository.insert(arrayToInsert); } + @bindThis + public async updateScheduledNotes(src: ThinUser, dst: MiUser): Promise<void> { + // we're moving to a different local user: change scheduled notes' ownership + if (dst.host === null) { + await this.noteScheduleRepository.update( + { userId: src.id }, + { userId: dst.id }, + ); + + return; + } + + // we're moving to a remote user: delete scheduled notes + const scheduledNotes = await this.noteScheduleRepository.findBy({ + userId: src.id, + }) as MiNoteSchedule[]; + + for (const note of scheduledNotes) { + await this.queueService.ScheduleNotePostQueue.remove(`schedNote:${note.id}`); + } + + await this.noteScheduleRepository.delete({ + userId: src.id, + }); + } + /** * Update lists while moving accounts. * - No removal of the old account from the lists |