commit d00026a

default  ·  2022-12-03 16:58:49 +0000 UTC
parent af6d31f
Upgraded local/ to public/.
4 files changed,  +79, -4
M data.c
M html.c
M snac.h
M data.c
+7, -3
 1@@ -15,7 +15,7 @@
 2 #include <sys/file.h>
 3 #include <fcntl.h>
 4 
 5-double db_layout = 2.5;
 6+double db_layout = 2.6;
 7 
 8 
 9 int db_upgrade(d_char **error);
10@@ -500,9 +500,13 @@ int _object_add(const char *id, d_char *obj, int ow)
11             xs *c_idx = _object_fn(in_reply_to);
12 
13             c_idx = xs_replace_i(c_idx, ".json", "_c.idx");
14-            index_add(c_idx, id);
15 
16-            srv_debug(0, xs_fmt("object_add added child %s to %s", id, c_idx));
17+            if (!index_in(c_idx, id)) {
18+                index_add(c_idx, id);
19+                srv_debug(0, xs_fmt("object_add added child %s to %s", id, c_idx));
20+            }
21+            else
22+                srv_debug(0, xs_fmt("object_add %s child already in %s", id, c_idx));
23 
24             /* create a one-element index with the parent */
25             xs *p_idx = xs_replace(fn, ".json", "_p.idx");
M html.c
+7, -1
 1@@ -594,7 +594,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, int local, int level, int
 2             /* is the parent not here? */
 3             char *parent = xs_dict_get(msg, "inReplyTo");
 4 
 5-            if (!xs_is_null(parent) && !object_here(parent)) {
 6+            if (!xs_is_null(parent) && *parent && !object_here(parent)) {
 7                 xs *s1 = xs_fmt(
 8                     "<div class=\"snac-origin\">%s "
 9                     "<a href=\"%s\">ยป</a></div>\n",
10@@ -624,6 +624,12 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, int local, int level, int
11         sensitive = 1;
12     }
13 
14+    {
15+        xs *md5 = xs_md5_hex(id, strlen(id));
16+        xs *s1  = xs_fmt("<p><code>%s</code></p>\n", md5);
17+        s = xs_str_cat(s, s1);
18+    }
19+
20     {
21         xs *c  = sanitize(xs_dict_get(msg, "content"));
22         char *p, *v;
M snac.h
+6, -0
 1@@ -60,18 +60,24 @@ int index_first(const char *fn, char *buf, int size);
 2 d_char *index_list(const char *fn, int max);
 3 d_char *index_list_desc(const char *fn, int max);
 4 
 5+int object_add(const char *id, d_char *obj);
 6+int object_add_ow(const char *id, d_char *obj);
 7 int object_here_by_md5(char *id);
 8 int object_here(char *id);
 9 int object_get_by_md5(const char *md5, d_char **obj, const char *type);
10 int object_get(const char *id, d_char **obj, const char *type);
11 int object_del(const char *id);
12 int object_del_if_unref(const char *id);
13+int object_admire(const char *id, const char *actor, int like);
14 
15 d_char *object_children(const char *id);
16 d_char *object_likes(const char *id);
17 d_char *object_announces(const char *id);
18 int object_parent(const char *id, char *buf, int size);
19 
20+int object_user_cache_add(snac *snac, const char *id, const char *cachedir);
21+int object_user_cache_del(snac *snac, const char *id, const char *cachedir);
22+
23 int follower_add(snac *snac, const char *actor);
24 int follower_del(snac *snac, const char *actor);
25 int follower_check(snac *snac, const char *actor);
+59, -0
 1@@ -171,6 +171,65 @@ int db_upgrade(d_char **error)
 2 
 3             nf = 2.5;
 4         }
 5+        else
 6+        if (f < 2.6) {
 7+            /* upgrade local/ to public/ */
 8+            xs *users = user_list();
 9+            char *p, *v;
10+
11+            p = users;
12+            while (xs_list_iter(&p, &v)) {
13+                snac snac;
14+
15+                if (user_open(&snac, v)) {
16+                    xs *spec = xs_fmt("%s/local/" "*.json", snac.basedir);
17+                    xs *dir  = xs_glob(spec, 0, 0);
18+                    char *p, *v;
19+
20+                    p = dir;
21+                    while (xs_list_iter(&p, &v)) {
22+                        FILE *f;
23+
24+                        if ((f = fopen(v, "r")) != NULL) {
25+                            xs *s = xs_readall(f);
26+                            xs *o = xs_json_loads(s);
27+                            fclose(f);
28+
29+                            xs *meta = xs_dup(xs_dict_get(o, "_snac"));
30+                            o = xs_dict_del(o, "_snac");
31+
32+                            char *id = xs_dict_get(o, "id");
33+
34+                            /* store object */
35+                            object_add_ow(id, o);
36+
37+                            /* if it's from us, add to public */
38+                            if (xs_startswith(id, snac.actor)) {
39+                                char *p, *v;
40+
41+                                object_user_cache_add(&snac, id, "public");
42+
43+                                p = xs_dict_get(meta, "announced_by");
44+                                while (xs_list_iter(&p, &v))
45+                                    object_admire(id, v, 0);
46+                                p = xs_dict_get(meta, "liked_by");
47+                                while (xs_list_iter(&p, &v))
48+                                    object_admire(id, v, 1);
49+                            }
50+
51+                            unlink(v);
52+                        }
53+                    }
54+
55+                    xs *od = xs_fmt("%s/local", snac.basedir);
56+                    rmdir(od);
57+
58+                    user_free(&snac);
59+                }
60+            }
61+
62+            nf = 2.6;
63+        }
64 
65         if (f < nf) {
66             f          = nf;