summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-12-03 17:58:49 +0100
committerdefault <nobody@localhost>2022-12-03 17:58:49 +0100
commitd00026ac063e960728c5147634ff3591828efced (patch)
tree0456668b56eb64bfdbd2c513a479cc02b247a9d2
parentaf6d31ff83bfe1eb6f4d37c5623e35f149e9aee5 (diff)
Upgraded local/ to public/.
-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 @@
#include <sys/file.h>
#include <fcntl.h>
-double db_layout = 2.5;
+double db_layout = 2.6;
int db_upgrade(d_char **error);
@@ -500,9 +500,13 @@ int _object_add(const char *id, d_char *obj, int ow)
xs *c_idx = _object_fn(in_reply_to);
c_idx = xs_replace_i(c_idx, ".json", "_c.idx");
- index_add(c_idx, id);
- srv_debug(0, xs_fmt("object_add added child %s to %s", id, c_idx));
+ if (!index_in(c_idx, id)) {
+ index_add(c_idx, id);
+ srv_debug(0, xs_fmt("object_add added child %s to %s", id, c_idx));
+ }
+ else
+ srv_debug(0, xs_fmt("object_add %s child already in %s", id, c_idx));
/* create a one-element index with the parent */
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
/* is the parent not here? */
char *parent = xs_dict_get(msg, "inReplyTo");
- if (!xs_is_null(parent) && !object_here(parent)) {
+ if (!xs_is_null(parent) && *parent && !object_here(parent)) {
xs *s1 = xs_fmt(
"<div class=\"snac-origin\">%s "
"<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
}
{
+ xs *md5 = xs_md5_hex(id, strlen(id));
+ xs *s1 = xs_fmt("<p><code>%s</code></p>\n", md5);
+ s = xs_str_cat(s, s1);
+ }
+
+ {
xs *c = sanitize(xs_dict_get(msg, "content"));
char *p, *v;
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);
d_char *index_list(const char *fn, int max);
d_char *index_list_desc(const char *fn, int max);
+int object_add(const char *id, d_char *obj);
+int object_add_ow(const char *id, d_char *obj);
int object_here_by_md5(char *id);
int object_here(char *id);
int object_get_by_md5(const char *md5, d_char **obj, const char *type);
int object_get(const char *id, d_char **obj, const char *type);
int object_del(const char *id);
int object_del_if_unref(const char *id);
+int object_admire(const char *id, const char *actor, int like);
d_char *object_children(const char *id);
d_char *object_likes(const char *id);
d_char *object_announces(const char *id);
int object_parent(const char *id, char *buf, int size);
+int object_user_cache_add(snac *snac, const char *id, const char *cachedir);
+int object_user_cache_del(snac *snac, const char *id, const char *cachedir);
+
int follower_add(snac *snac, const char *actor);
int follower_del(snac *snac, const char *actor);
int 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)
nf = 2.5;
}
+ else
+ if (f < 2.6) {
+ /* upgrade local/ to public/ */
+ xs *users = user_list();
+ char *p, *v;
+
+ p = users;
+ while (xs_list_iter(&p, &v)) {
+ snac snac;
+
+ if (user_open(&snac, v)) {
+ xs *spec = xs_fmt("%s/local/" "*.json", snac.basedir);
+ xs *dir = xs_glob(spec, 0, 0);
+ char *p, *v;
+
+ p = dir;
+ while (xs_list_iter(&p, &v)) {
+ FILE *f;
+
+ if ((f = fopen(v, "r")) != NULL) {
+ xs *s = xs_readall(f);
+ xs *o = xs_json_loads(s);
+ fclose(f);
+
+ xs *meta = xs_dup(xs_dict_get(o, "_snac"));
+ o = xs_dict_del(o, "_snac");
+
+ char *id = xs_dict_get(o, "id");
+
+ /* store object */
+ object_add_ow(id, o);
+
+ /* if it's from us, add to public */
+ if (xs_startswith(id, snac.actor)) {
+ char *p, *v;
+
+ object_user_cache_add(&snac, id, "public");
+
+ p = xs_dict_get(meta, "announced_by");
+ while (xs_list_iter(&p, &v))
+ object_admire(id, v, 0);
+ p = xs_dict_get(meta, "liked_by");
+ while (xs_list_iter(&p, &v))
+ object_admire(id, v, 1);
+ }
+
+ unlink(v);
+ }
+ }
+
+ xs *od = xs_fmt("%s/local", snac.basedir);
+ rmdir(od);
+
+ user_free(&snac);
+ }
+ }
+
+ nf = 2.6;
+ }
if (f < nf) {
f = nf;