summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.c10
-rw-r--r--html.c8
-rw-r--r--snac.h6
-rw-r--r--upgrade.c59
4 files changed, 79 insertions, 4 deletions
diff --git a/data.c b/data.c
index 12ba447..f3a1ce8 100644
--- a/data.c
+++ b/data.c
@@ -15,7 +15,7 @@
15#include <sys/file.h> 15#include <sys/file.h>
16#include <fcntl.h> 16#include <fcntl.h>
17 17
18double db_layout = 2.5; 18double db_layout = 2.6;
19 19
20 20
21int db_upgrade(d_char **error); 21int 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");
diff --git a/html.c b/html.c
index 3c5d0bc..6790578 100644
--- a/html.c
+++ b/html.c
@@ -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
diff --git a/snac.h b/snac.h
index 1254584..0980321 100644
--- a/snac.h
+++ b/snac.h
@@ -60,18 +60,24 @@ int index_first(const char *fn, char *buf, int size);
60d_char *index_list(const char *fn, int max); 60d_char *index_list(const char *fn, int max);
61d_char *index_list_desc(const char *fn, int max); 61d_char *index_list_desc(const char *fn, int max);
62 62
63int object_add(const char *id, d_char *obj);
64int object_add_ow(const char *id, d_char *obj);
63int object_here_by_md5(char *id); 65int object_here_by_md5(char *id);
64int object_here(char *id); 66int object_here(char *id);
65int object_get_by_md5(const char *md5, d_char **obj, const char *type); 67int object_get_by_md5(const char *md5, d_char **obj, const char *type);
66int object_get(const char *id, d_char **obj, const char *type); 68int object_get(const char *id, d_char **obj, const char *type);
67int object_del(const char *id); 69int object_del(const char *id);
68int object_del_if_unref(const char *id); 70int object_del_if_unref(const char *id);
71int object_admire(const char *id, const char *actor, int like);
69 72
70d_char *object_children(const char *id); 73d_char *object_children(const char *id);
71d_char *object_likes(const char *id); 74d_char *object_likes(const char *id);
72d_char *object_announces(const char *id); 75d_char *object_announces(const char *id);
73int object_parent(const char *id, char *buf, int size); 76int object_parent(const char *id, char *buf, int size);
74 77
78int object_user_cache_add(snac *snac, const char *id, const char *cachedir);
79int object_user_cache_del(snac *snac, const char *id, const char *cachedir);
80
75int follower_add(snac *snac, const char *actor); 81int follower_add(snac *snac, const char *actor);
76int follower_del(snac *snac, const char *actor); 82int follower_del(snac *snac, const char *actor);
77int follower_check(snac *snac, const char *actor); 83int follower_check(snac *snac, const char *actor);
diff --git a/upgrade.c b/upgrade.c
index e2983e4..dbf878b 100644
--- a/upgrade.c
+++ b/upgrade.c
@@ -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;