summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/i
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-11-27 09:57:24 +0000
committerdakkar <dakkar@thenautilus.net>2024-11-27 10:36:19 +0000
commitfc277839b66bd919e2c0ca0c2e2840cd3484afb0 (patch)
tree1f13e017f5c691abc59545b6ebcb4d972a58267d /packages/backend/src/server/api/endpoints/i
parentmerge: Add aliases to webfinger request. (!778) (diff)
downloadsharkey-fc277839b66bd919e2c0ca0c2e2840cd3484afb0.tar.gz
sharkey-fc277839b66bd919e2c0ca0c2e2840cd3484afb0.tar.bz2
sharkey-fc277839b66bd919e2c0ca0c2e2840cd3484afb0.zip
only "publish to followers" when things really change - fixes #733
Diffstat (limited to 'packages/backend/src/server/api/endpoints/i')
-rw-r--r--packages/backend/src/server/api/endpoints/i/update.ts52
1 files changed, 51 insertions, 1 deletions
diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts
index 8994c3fff6..f0e8dfc832 100644
--- a/packages/backend/src/server/api/endpoints/i/update.ts
+++ b/packages/backend/src/server/api/endpoints/i/update.ts
@@ -539,7 +539,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
// フォロワーにUpdateを配信
- this.accountUpdateService.publishToFollowers(user.id);
+ if (this.userNeedsPublishing(user, updates) || this.profileNeedsPublishing(profile, updatedProfile)) {
+ this.accountUpdateService.publishToFollowers(user.id);
+ }
const urls = updatedProfile.fields.filter(x => x.value.startsWith('https://'));
for (const url of urls) {
@@ -581,4 +583,52 @@ 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'] as (keyof MiUser)[]) {
+ if (newUser.hasOwnProperty(field) && oldUser[field] !== newUser[field]) {
+ return true;
+ }
+ }
+ for (const arrayField of ['emojis', 'tags'] as (keyof MiUser)[]) {
+ if (newUser.hasOwnProperty(arrayField) !== oldUser.hasOwnProperty(arrayField)) {
+ return true;
+ }
+
+ const oldArray = oldUser[arrayField] ?? [];
+ const newArray = newUser[arrayField] ?? [];
+ if (!Array.isArray(oldArray) || !Array.isArray(newArray)) {
+ return true;
+ }
+ if (oldArray.join("\0") !== newArray.join("\0")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private profileNeedsPublishing(oldProfile: MiUserProfile, newProfile: Partial<MiUserProfile>): boolean {
+ for (const field of ['description', 'followedMessage', 'birthday', 'location', 'listenbrainz'] as (keyof MiUserProfile)[]) {
+ if (newProfile.hasOwnProperty(field) && oldProfile[field] !== newProfile[field]) {
+ return true;
+ }
+ }
+ for (const arrayField of ['fields'] as (keyof MiUserProfile)[]) {
+ if (newProfile.hasOwnProperty(arrayField) !== oldProfile.hasOwnProperty(arrayField)) {
+ return true;
+ }
+
+ const oldArray = oldProfile[arrayField] ?? [];
+ const newArray = newProfile[arrayField] ?? [];
+ if (!Array.isArray(oldArray) || !Array.isArray(newArray)) {
+ return true;
+ }
+ if (oldArray.join("\0") !== newArray.join("\0")) {
+ return true;
+ }
+ }
+ return false;
+ }
}