diff --git a/packages/backend/src/server/api/endpoints/admin/cw-instance.ts b/packages/backend/src/server/api/endpoints/admin/cw-instance.ts index 5fd9fd10b3..0a60316170 100644 --- a/packages/backend/src/server/api/endpoints/admin/cw-instance.ts +++ b/packages/backend/src/server/api/endpoints/admin/cw-instance.ts @@ -34,21 +34,21 @@ export default class extends Endpoint { // eslint- super(meta, paramDef, async (ps, me) => { const instance = await this.federatedInstanceService.fetchOrRegister(ps.host); + // Collapse empty strings to null + const newCW = ps.cw || null; + const oldCW = instance.mandatoryCW; + // Skip if there's nothing to do - if (instance.mandatoryCW === ps.cw) return; + if (oldCW === newCW) return; + + // This synchronizes caches automatically + await this.federatedInstanceService.update(instance.id, { mandatoryCW: newCW }); - // Log event first. - // This ensures that we don't "lose" the log if an error occurs await this.moderationLogService.log(me, 'setMandatoryCWForInstance', { - newCW: ps.cw, - oldCW: instance.mandatoryCW, + newCW, + oldCW, host: ps.host, }); - - await this.federatedInstanceService.update(instance.id, { - // Collapse empty strings to null - mandatoryCW: ps.cw || null, - }); }); } } diff --git a/packages/backend/src/server/api/endpoints/admin/cw-note.ts b/packages/backend/src/server/api/endpoints/admin/cw-note.ts index cf513a4922..e036c2e530 100644 --- a/packages/backend/src/server/api/endpoints/admin/cw-note.ts +++ b/packages/backend/src/server/api/endpoints/admin/cw-note.ts @@ -43,23 +43,22 @@ export default class extends Endpoint { // eslint- }) as MiNote & { user: MiUser }; // Collapse empty strings to null - const mandatoryCW = ps.cw || null; + const newCW = ps.cw || null; + const oldCW = note.mandatoryCW; // Skip if there's nothing to do - if (note.mandatoryCW === mandatoryCW) return; + if (oldCW === newCW) return; + + await this.noteEditService.edit(note.user, note.id, { mandatoryCW: newCW }); - // Log event first. - // This ensures that we don't "lose" the log if an error occurs await this.moderationLogService.log(me, 'setMandatoryCWForNote', { - newCW: mandatoryCW, - oldCW: note.mandatoryCW, + newCW, + oldCW, noteId: note.id, noteUserId: note.user.id, noteUserUsername: note.user.username, noteUserHost: note.user.host, }); - - await this.noteEditService.edit(note.user, note.id, { mandatoryCW }); }); } } diff --git a/packages/backend/src/server/api/endpoints/admin/cw-user.ts b/packages/backend/src/server/api/endpoints/admin/cw-user.ts index 37480e9302..a318f830cf 100644 --- a/packages/backend/src/server/api/endpoints/admin/cw-user.ts +++ b/packages/backend/src/server/api/endpoints/admin/cw-user.ts @@ -41,20 +41,21 @@ export default class extends Endpoint { // eslint- super(meta, paramDef, async (ps, me) => { const user = await this.cacheService.findUserById(ps.userId); - // Skip if there's nothing to do - if (user.mandatoryCW === ps.cw) return; + // Collapse empty strings to null + const newCW = ps.cw || null; + const oldCW = user.mandatoryCW; - await this.usersRepository.update(ps.userId, { - // Collapse empty strings to null - mandatoryCW: ps.cw || null, - }); + // Skip if there's nothing to do + if (oldCW === newCW) return; + + await this.usersRepository.update(ps.userId, { mandatoryCW: newCW }); // Synchronize caches and other processes this.globalEventService.publishInternalEvent('localUserUpdated', { id: ps.userId }); await this.moderationLogService.log(me, 'setMandatoryCW', { - newCW: ps.cw, - oldCW: user.mandatoryCW, + newCW, + oldCW, userId: user.id, userUsername: user.username, userHost: user.host,