aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2024-11-23 17:33:49 +0100
committerdefault <nobody@localhost>2024-11-23 17:33:49 +0100
commit36c3030231ed806c29c182e38cb0957993c835d1 (patch)
tree2d23148266ff5b30130950782081c3db8aa6ec16
parentc88d7e72f0531114e7e000f79ee6ce9a11f23952 (diff)
In user_persist(), only publish the actor to the world if a relevant field has changed.
This way, changing user preferences does not trigger an automatic send storm.
-rw-r--r--data.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/data.c b/data.c
index f2fa521..bbebdb8 100644
--- a/data.c
+++ b/data.c
@@ -336,6 +336,32 @@ int user_persist(snac *snac, int publish)
xs *bfn = xs_fmt("%s.bak", fn);
FILE *f;
+ if (publish) {
+ /* check if any of the relevant fields have really changed */
+ if ((f = fopen(fn, "r")) != NULL) {
+ xs *old = xs_json_load(f);
+ fclose(f);
+
+ if (old != NULL) {
+ int nw = 0;
+ const char *fields[] = { "header", "avatar", "name", "bio", "metadata", NULL };
+
+ for (int n = 0; fields[n]; n++) {
+ const char *of = xs_dict_get(old, fields[n]);
+ const char *nf = xs_dict_get(snac->config, fields[n]);
+
+ if (xs_type(of) != XSTYPE_STRING || xs_type(nf) != XSTYPE_STRING || strcmp(of, nf)) {
+ nw = 1;
+ break;
+ }
+ }
+
+ if (!nw)
+ publish = 0;
+ }
+ }
+ }
+
rename(fn, bfn);
if ((f = fopen(fn, "w")) != NULL) {