commit 36c3030

default  ·  2024-11-23 16:33:49 +0000 UTC
parent c88d7e7
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.
1 files changed,  +26, -0
M data.c
M data.c
+26, -0
 1@@ -336,6 +336,32 @@ int user_persist(snac *snac, int publish)
 2     xs *bfn = xs_fmt("%s.bak", fn);
 3     FILE *f;
 4 
 5+    if (publish) {
 6+        /* check if any of the relevant fields have really changed */
 7+        if ((f = fopen(fn, "r")) != NULL) {
 8+            xs *old = xs_json_load(f);
 9+            fclose(f);
10+
11+            if (old != NULL) {
12+                int nw = 0;
13+                const char *fields[] = { "header", "avatar", "name", "bio", "metadata", NULL };
14+
15+                for (int n = 0; fields[n]; n++) {
16+                    const char *of = xs_dict_get(old, fields[n]);
17+                    const char *nf = xs_dict_get(snac->config, fields[n]);
18+
19+                    if (xs_type(of) != XSTYPE_STRING || xs_type(nf) != XSTYPE_STRING || strcmp(of, nf)) {
20+                        nw = 1;
21+                        break;
22+                    }
23+                }
24+
25+                if (!nw)
26+                    publish = 0;
27+            }
28+        }
29+    }
30+
31     rename(fn, bfn);
32 
33     if ((f = fopen(fn, "w")) != NULL) {