diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2024-12-12 07:31:11 -0500 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2024-12-12 08:13:44 -0500 |
| commit | 1c65f234458c5ce6f67280bc2aa7b4e04f1aa671 (patch) | |
| tree | 3c21d6e2427c3045339d27dee22f2328ba21ecbb | |
| parent | federate profile when changing `enableRss` value (diff) | |
| download | sharkey-1c65f234458c5ce6f67280bc2aa7b4e04f1aa671.tar.gz sharkey-1c65f234458c5ce6f67280bc2aa7b4e04f1aa671.tar.bz2 sharkey-1c65f234458c5ce6f67280bc2aa7b4e04f1aa671.zip | |
safer typings for `userNeedsPublishing` and `profileNeedsPublishing`
| -rw-r--r-- | packages/backend/src/server/api/endpoints/i/update.ts | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index 91f871a952..c22cbe5d4b 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -589,12 +589,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- // these two methods need to be kept in sync with // `ApRendererService.renderPerson` private userNeedsPublishing(oldUser: MiLocalUser, newUser: Partial<MiUser>): boolean { - for (const field of ['avatarId', 'bannerId', 'backgroundId', 'isBot', 'username', 'name', 'isLocked', 'isExplorable', 'isCat', 'noindex', 'speakAsCat', 'movedToUri', 'alsoKnownAs', 'hideOnlineStatus', 'enableRss'] as (keyof MiUser)[]) { + const basicFields: (keyof MiUser)[] = ['avatarId', 'bannerId', 'backgroundId', 'isBot', 'username', 'name', 'isLocked', 'isExplorable', 'isCat', 'noindex', 'speakAsCat', 'movedToUri', 'alsoKnownAs', 'hideOnlineStatus', 'enableRss']; + for (const field of basicFields) { if ((field in newUser) && oldUser[field] !== newUser[field]) { return true; } } - for (const arrayField of ['emojis', 'tags'] as (keyof MiUser)[]) { + + const arrayFields: (keyof MiUser)[] = ['emojis', 'tags']; + for (const arrayField of arrayFields) { if ((arrayField in newUser) !== (arrayField in oldUser)) { return true; } @@ -604,7 +607,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- if (!Array.isArray(oldArray) || !Array.isArray(newArray)) { return true; } - if (oldArray.join("\0") !== newArray.join("\0")) { + if (oldArray.join('\0') !== newArray.join('\0')) { return true; } } @@ -612,12 +615,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- } private profileNeedsPublishing(oldProfile: MiUserProfile, newProfile: Partial<MiUserProfile>): boolean { - for (const field of ['description', 'followedMessage', 'birthday', 'location', 'listenbrainz'] as (keyof MiUserProfile)[]) { + const basicFields: (keyof MiUserProfile)[] = ['description', 'followedMessage', 'birthday', 'location', 'listenbrainz']; + for (const field of basicFields) { if ((field in newProfile) && oldProfile[field] !== newProfile[field]) { return true; } } - for (const arrayField of ['fields'] as (keyof MiUserProfile)[]) { + + const arrayFields: (keyof MiUserProfile)[] = ['fields']; + for (const arrayField of arrayFields) { if ((arrayField in newProfile) !== (arrayField in oldProfile)) { return true; } @@ -627,7 +633,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- if (!Array.isArray(oldArray) || !Array.isArray(newArray)) { return true; } - if (oldArray.join("\0") !== newArray.join("\0")) { + if (oldArray.join('\0') !== newArray.join('\0')) { return true; } } |