diff options
| author | 2022-12-03 17:58:49 +0100 | |
|---|---|---|
| committer | 2022-12-03 17:58:49 +0100 | |
| commit | d00026ac063e960728c5147634ff3591828efced (patch) | |
| tree | 0456668b56eb64bfdbd2c513a479cc02b247a9d2 | |
| parent | New function timeline_simple_list(). (diff) | |
| download | snac2-d00026ac063e960728c5147634ff3591828efced.tar.gz snac2-d00026ac063e960728c5147634ff3591828efced.tar.xz snac2-d00026ac063e960728c5147634ff3591828efced.zip | |
Upgraded local/ to public/.
| -rw-r--r-- | data.c | 10 | ||||
| -rw-r--r-- | html.c | 8 | ||||
| -rw-r--r-- | snac.h | 6 | ||||
| -rw-r--r-- | upgrade.c | 59 |
4 files changed, 79 insertions, 4 deletions
| @@ -15,7 +15,7 @@ | |||
| 15 | #include <sys/file.h> | 15 | #include <sys/file.h> |
| 16 | #include <fcntl.h> | 16 | #include <fcntl.h> |
| 17 | 17 | ||
| 18 | double db_layout = 2.5; | 18 | double db_layout = 2.6; |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | int db_upgrade(d_char **error); | 21 | int db_upgrade(d_char **error); |
| @@ -500,9 +500,13 @@ int _object_add(const char *id, d_char *obj, int ow) | |||
| 500 | xs *c_idx = _object_fn(in_reply_to); | 500 | xs *c_idx = _object_fn(in_reply_to); |
| 501 | 501 | ||
| 502 | c_idx = xs_replace_i(c_idx, ".json", "_c.idx"); | 502 | c_idx = xs_replace_i(c_idx, ".json", "_c.idx"); |
| 503 | index_add(c_idx, id); | ||
| 504 | 503 | ||
| 505 | srv_debug(0, xs_fmt("object_add added child %s to %s", id, c_idx)); | 504 | if (!index_in(c_idx, id)) { |
| 505 | index_add(c_idx, id); | ||
| 506 | srv_debug(0, xs_fmt("object_add added child %s to %s", id, c_idx)); | ||
| 507 | } | ||
| 508 | else | ||
| 509 | srv_debug(0, xs_fmt("object_add %s child already in %s", id, c_idx)); | ||
| 506 | 510 | ||
| 507 | /* create a one-element index with the parent */ | 511 | /* create a one-element index with the parent */ |
| 508 | xs *p_idx = xs_replace(fn, ".json", "_p.idx"); | 512 | xs *p_idx = xs_replace(fn, ".json", "_p.idx"); |
| @@ -594,7 +594,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, int local, int level, int | |||
| 594 | /* is the parent not here? */ | 594 | /* is the parent not here? */ |
| 595 | char *parent = xs_dict_get(msg, "inReplyTo"); | 595 | char *parent = xs_dict_get(msg, "inReplyTo"); |
| 596 | 596 | ||
| 597 | if (!xs_is_null(parent) && !object_here(parent)) { | 597 | if (!xs_is_null(parent) && *parent && !object_here(parent)) { |
| 598 | xs *s1 = xs_fmt( | 598 | xs *s1 = xs_fmt( |
| 599 | "<div class=\"snac-origin\">%s " | 599 | "<div class=\"snac-origin\">%s " |
| 600 | "<a href=\"%s\">»</a></div>\n", | 600 | "<a href=\"%s\">»</a></div>\n", |
| @@ -625,6 +625,12 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, int local, int level, int | |||
| 625 | } | 625 | } |
| 626 | 626 | ||
| 627 | { | 627 | { |
| 628 | xs *md5 = xs_md5_hex(id, strlen(id)); | ||
| 629 | xs *s1 = xs_fmt("<p><code>%s</code></p>\n", md5); | ||
| 630 | s = xs_str_cat(s, s1); | ||
| 631 | } | ||
| 632 | |||
| 633 | { | ||
| 628 | xs *c = sanitize(xs_dict_get(msg, "content")); | 634 | xs *c = sanitize(xs_dict_get(msg, "content")); |
| 629 | char *p, *v; | 635 | char *p, *v; |
| 630 | 636 | ||
| @@ -60,18 +60,24 @@ int index_first(const char *fn, char *buf, int size); | |||
| 60 | d_char *index_list(const char *fn, int max); | 60 | d_char *index_list(const char *fn, int max); |
| 61 | d_char *index_list_desc(const char *fn, int max); | 61 | d_char *index_list_desc(const char *fn, int max); |
| 62 | 62 | ||
| 63 | int object_add(const char *id, d_char *obj); | ||
| 64 | int object_add_ow(const char *id, d_char *obj); | ||
| 63 | int object_here_by_md5(char *id); | 65 | int object_here_by_md5(char *id); |
| 64 | int object_here(char *id); | 66 | int object_here(char *id); |
| 65 | int object_get_by_md5(const char *md5, d_char **obj, const char *type); | 67 | int object_get_by_md5(const char *md5, d_char **obj, const char *type); |
| 66 | int object_get(const char *id, d_char **obj, const char *type); | 68 | int object_get(const char *id, d_char **obj, const char *type); |
| 67 | int object_del(const char *id); | 69 | int object_del(const char *id); |
| 68 | int object_del_if_unref(const char *id); | 70 | int object_del_if_unref(const char *id); |
| 71 | int object_admire(const char *id, const char *actor, int like); | ||
| 69 | 72 | ||
| 70 | d_char *object_children(const char *id); | 73 | d_char *object_children(const char *id); |
| 71 | d_char *object_likes(const char *id); | 74 | d_char *object_likes(const char *id); |
| 72 | d_char *object_announces(const char *id); | 75 | d_char *object_announces(const char *id); |
| 73 | int object_parent(const char *id, char *buf, int size); | 76 | int object_parent(const char *id, char *buf, int size); |
| 74 | 77 | ||
| 78 | int object_user_cache_add(snac *snac, const char *id, const char *cachedir); | ||
| 79 | int object_user_cache_del(snac *snac, const char *id, const char *cachedir); | ||
| 80 | |||
| 75 | int follower_add(snac *snac, const char *actor); | 81 | int follower_add(snac *snac, const char *actor); |
| 76 | int follower_del(snac *snac, const char *actor); | 82 | int follower_del(snac *snac, const char *actor); |
| 77 | int follower_check(snac *snac, const char *actor); | 83 | int follower_check(snac *snac, const char *actor); |
| @@ -171,6 +171,65 @@ int db_upgrade(d_char **error) | |||
| 171 | 171 | ||
| 172 | nf = 2.5; | 172 | nf = 2.5; |
| 173 | } | 173 | } |
| 174 | else | ||
| 175 | if (f < 2.6) { | ||
| 176 | /* upgrade local/ to public/ */ | ||
| 177 | xs *users = user_list(); | ||
| 178 | char *p, *v; | ||
| 179 | |||
| 180 | p = users; | ||
| 181 | while (xs_list_iter(&p, &v)) { | ||
| 182 | snac snac; | ||
| 183 | |||
| 184 | if (user_open(&snac, v)) { | ||
| 185 | xs *spec = xs_fmt("%s/local/" "*.json", snac.basedir); | ||
| 186 | xs *dir = xs_glob(spec, 0, 0); | ||
| 187 | char *p, *v; | ||
| 188 | |||
| 189 | p = dir; | ||
| 190 | while (xs_list_iter(&p, &v)) { | ||
| 191 | FILE *f; | ||
| 192 | |||
| 193 | if ((f = fopen(v, "r")) != NULL) { | ||
| 194 | xs *s = xs_readall(f); | ||
| 195 | xs *o = xs_json_loads(s); | ||
| 196 | fclose(f); | ||
| 197 | |||
| 198 | xs *meta = xs_dup(xs_dict_get(o, "_snac")); | ||
| 199 | o = xs_dict_del(o, "_snac"); | ||
| 200 | |||
| 201 | char *id = xs_dict_get(o, "id"); | ||
| 202 | |||
| 203 | /* store object */ | ||
| 204 | object_add_ow(id, o); | ||
| 205 | |||
| 206 | /* if it's from us, add to public */ | ||
| 207 | if (xs_startswith(id, snac.actor)) { | ||
| 208 | char *p, *v; | ||
| 209 | |||
| 210 | object_user_cache_add(&snac, id, "public"); | ||
| 211 | |||
| 212 | p = xs_dict_get(meta, "announced_by"); | ||
| 213 | while (xs_list_iter(&p, &v)) | ||
| 214 | object_admire(id, v, 0); | ||
| 215 | p = xs_dict_get(meta, "liked_by"); | ||
| 216 | while (xs_list_iter(&p, &v)) | ||
| 217 | object_admire(id, v, 1); | ||
| 218 | } | ||
| 219 | |||
| 220 | unlink(v); | ||
| 221 | } | ||
| 222 | } | ||
| 223 | |||
| 224 | xs *od = xs_fmt("%s/local", snac.basedir); | ||
| 225 | rmdir(od); | ||
| 226 | |||
| 227 | user_free(&snac); | ||
| 228 | } | ||
| 229 | } | ||
| 230 | |||
| 231 | nf = 2.6; | ||
| 232 | } | ||
| 174 | 233 | ||
| 175 | if (f < nf) { | 234 | if (f < nf) { |
| 176 | f = nf; | 235 | f = nf; |