summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-11-27 20:41:37 +0000
committerdakkar <dakkar@thenautilus.net>2024-11-27 20:41:37 +0000
commit3164e7b4fc88c72b1a9c887d7e5b4abf11fd194b (patch)
treebb60597e98b473d0a70bf3998e35d892091bd623 /packages/backend/src/server/api
parentmerge: better poll editing - fixes #668 (!783) (diff)
parentonly "publish to followers" when things really change - fixes #733 (diff)
downloadsharkey-3164e7b4fc88c72b1a9c887d7e5b4abf11fd194b.tar.gz
sharkey-3164e7b4fc88c72b1a9c887d7e5b4abf11fd194b.tar.bz2
sharkey-3164e7b4fc88c72b1a9c887d7e5b4abf11fd194b.zip
merge: only "publish to followers" when things really change - fixes #733 (!781)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/781 Closes #733 Approved-by: Hazelnoot <acomputerdog@gmail.com> Approved-by: Marie <github@yuugi.dev>
Diffstat (limited to 'packages/backend/src/server/api')
-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;
+ }
}