summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/AccountMoveService.ts
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-05-07 16:33:18 +0000
committerHazelnoot <acomputerdog@gmail.com>2025-05-07 16:33:18 +0000
commitd39a56c1b7d74dd07cc78b4c82a6fb6e51036252 (patch)
tree24f9c6baa07fadc11c791f1a59bee2c3149cbf56 /packages/backend/src/core/AccountMoveService.ts
parentmerge: Add BunnyCDN Edge Storage support (!952) (diff)
parentisNotUserHome > isUserHome (diff)
downloadsharkey-d39a56c1b7d74dd07cc78b4c82a6fb6e51036252.tar.gz
sharkey-d39a56c1b7d74dd07cc78b4c82a6fb6e51036252.tar.bz2
sharkey-d39a56c1b7d74dd07cc78b4c82a6fb6e51036252.zip
merge: Merge upstream 2025.4.1 (!955)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/955 Closes #638, #1037, #734, and #766 Approved-by: dakkar <dakkar@thenautilus.net> Approved-by: Marie <github@yuugi.dev>
Diffstat (limited to 'packages/backend/src/core/AccountMoveService.ts')
-rw-r--r--packages/backend/src/core/AccountMoveService.ts46
1 files changed, 38 insertions, 8 deletions
diff --git a/packages/backend/src/core/AccountMoveService.ts b/packages/backend/src/core/AccountMoveService.ts
index e24fefb4b5..7bf33e13c5 100644
--- a/packages/backend/src/core/AccountMoveService.ts
+++ b/packages/backend/src/core/AccountMoveService.ts
@@ -20,10 +20,12 @@ import { ApPersonService } from '@/core/activitypub/models/ApPersonService.js';
import { ApDeliverManagerService } from '@/core/activitypub/ApDeliverManagerService.js';
import { ApRendererService } from '@/core/activitypub/ApRendererService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
-import { ProxyAccountService } from '@/core/ProxyAccountService.js';
import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
import InstanceChart from '@/core/chart/charts/instance.js';
import PerUserFollowingChart from '@/core/chart/charts/per-user-following.js';
+import { SystemAccountService } from '@/core/SystemAccountService.js';
+import { RoleService } from '@/core/RoleService.js';
+import { AntennaService } from '@/core/AntennaService.js';
@Injectable()
export class AccountMoveService {
@@ -58,12 +60,14 @@ export class AccountMoveService {
private apRendererService: ApRendererService,
private apDeliverManagerService: ApDeliverManagerService,
private globalEventService: GlobalEventService,
- private proxyAccountService: ProxyAccountService,
private perUserFollowingChart: PerUserFollowingChart,
private federatedInstanceService: FederatedInstanceService,
private instanceChart: InstanceChart,
private relayService: RelayService,
private queueService: QueueService,
+ private systemAccountService: SystemAccountService,
+ private roleService: RoleService,
+ private antennaService: AntennaService,
) {
}
@@ -123,18 +127,20 @@ export class AccountMoveService {
this.copyBlocking(src, dst),
this.copyMutings(src, dst),
this.deleteScheduledNotes(src),
+ this.copyRoles(src, dst),
this.updateLists(src, dst),
+ this.antennaService.onMoveAccount(src, dst),
]);
} catch {
/* skip if any error happens */
}
// follow the new account
- const proxy = await this.proxyAccountService.fetch();
+ const proxy = await this.systemAccountService.fetch('proxy');
const followings = await this.followingsRepository.findBy({
followeeId: src.id,
followerHost: IsNull(), // follower is local
- followerId: proxy ? Not(proxy.id) : undefined,
+ followerId: Not(proxy.id),
});
const followJobs = followings.map(following => ({
from: { id: following.followerId },
@@ -220,6 +226,32 @@ export class AccountMoveService {
});
}
+ @bindThis
+ public async copyRoles(src: ThinUser, dst: ThinUser): Promise<void> {
+ // Insert new roles with the same values except userId
+ // role service may have cache for roles so retrieve roles from service
+ const [oldRoleAssignments, roles] = await Promise.all([
+ this.roleService.getUserAssigns(src.id),
+ this.roleService.getRoles(),
+ ]);
+
+ if (oldRoleAssignments.length === 0) return;
+
+ // No promise all since the only async operation is writing to the database
+ for (const oldRoleAssignment of oldRoleAssignments) {
+ const role = roles.find(x => x.id === oldRoleAssignment.roleId);
+ if (role == null) continue; // Very unlikely however removing role may cause this case
+ if (!role.preserveAssignmentOnMoveAccount) continue;
+
+ try {
+ await this.roleService.assign(dst.id, role.id, oldRoleAssignment.expiresAt);
+ } catch (e) {
+ if (e instanceof RoleService.AlreadyAssignedError) continue;
+ throw e;
+ }
+ }
+ }
+
/**
* Update lists while moving accounts.
* - No removal of the old account from the lists
@@ -269,10 +301,8 @@ export class AccountMoveService {
// Have the proxy account follow the new account in the same way as UserListService.push
if (this.userEntityService.isRemoteUser(dst)) {
- const proxy = await this.proxyAccountService.fetch();
- if (proxy) {
- this.queueService.createFollowJob([{ from: { id: proxy.id }, to: { id: dst.id } }]);
- }
+ const proxy = await this.systemAccountService.fetch('proxy');
+ this.queueService.createFollowJob([{ from: { id: proxy.id }, to: { id: dst.id } }]);
}
}