normalize new CW in all mandatory CW endpoints
This commit is contained in:
parent
e5dfcf6f64
commit
807aa1be3d
3 changed files with 26 additions and 26 deletions
|
|
@ -34,21 +34,21 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // 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,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,23 +43,22 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // 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 });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,20 +41,21 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // 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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue