diff --git a/data.c b/data.c index c1c616d..a04dac1 100644 --- a/data.c +++ b/data.c @@ -14,7 +14,7 @@ #include #include -double db_layout = 2.2; +double db_layout = 2.3; int db_upgrade(d_char **error); @@ -913,50 +913,6 @@ void timeline_admire(snac *snac, char *id, char *admirer, int like) } -int timeline_hide(snac *snac, char *id, int hide) -/* hides/unhides a timeline entry */ -{ - int ret = 0; - xs *fn = _timeline_find_fn(snac, id); - FILE *f; - - if (fn != NULL && (f = fopen(fn, "r")) != NULL) { - xs *s1 = xs_readall(f); - xs *msg = xs_json_loads(s1); - xs *meta = xs_dup(xs_dict_get(msg, "_snac")); - xs *hdn = xs_val_new(hide ? XSTYPE_TRUE : XSTYPE_FALSE); - char *p, *v; - - fclose(f); - - /* if it's already in this hidden state, we're done */ - if ((v = xs_dict_get(meta, "hidden")) && xs_type(v) == xs_type(hdn)) - return ret; - - meta = xs_dict_set(meta, "hidden", hdn); - msg = xs_dict_set(msg, "_snac", meta); - - if ((f = fopen(fn, "w")) != NULL) { - xs *j1 = xs_json_dumps_pp(msg, 4); - - fwrite(j1, strlen(j1), 1, f); - fclose(f); - - snac_debug(snac, 1, xs_fmt("timeline_hide %d %s", hide, id)); - - /* now hide the children */ - p = xs_dict_get(meta, "children"); - while (xs_list_iter(&p, &v)) - timeline_hide(snac, v, hide); - - ret = 1; - } - } - - return ret; -} - - d_char *_following_fn(snac *snac, char *actor) { xs *md5 = xs_md5_hex(actor, strlen(actor)); @@ -1109,7 +1065,7 @@ int is_muted(snac *snac, char *actor) d_char *_hidden_fn(snac *snac, const char *id) { xs *md5 = xs_md5_hex(id, strlen(id)); - return xs_fmt("%s/hidden/%s.json", snac->basedir, md5); + return xs_fmt("%s/hidden/%s", snac->basedir, md5); } diff --git a/html.c b/html.c index 2743be9..624b6e7 100644 --- a/html.c +++ b/html.c @@ -497,7 +497,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i xs *s = xs_str_new(NULL); /* top wrap */ - if ((v = xs_dict_get(meta, "hidden")) && xs_type(v) == XSTYPE_TRUE) + if (is_hidden(snac, id)) s = xs_str_cat(s, "
\n"); else s = xs_str_cat(s, "
\n"); @@ -1300,7 +1300,7 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, } else if (strcmp(action, L("Hide")) == 0) { - timeline_hide(&snac, id, 1); + hide(&snac, id); } else if (strcmp(action, L("Follow")) == 0) { diff --git a/snac.h b/snac.h index 565d357..6edf50c 100644 --- a/snac.h +++ b/snac.h @@ -71,7 +71,6 @@ d_char *timeline_get(snac *snac, char *fn); d_char *timeline_list(snac *snac, int max); int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer); void timeline_admire(snac *snac, char *id, char *admirer, int like); -int timeline_hide(snac *snac, char *id, int hide); d_char *local_list(snac *snac, int max); diff --git a/upgrade.c b/upgrade.c index d5e5f0c..2473803 100644 --- a/upgrade.c +++ b/upgrade.c @@ -74,6 +74,25 @@ int db_upgrade(d_char **error) nf = 2.2; } + else + if (f < 2.3) { + xs *users = user_list(); + char *p, *v; + + p = users; + while (xs_list_iter(&p, &v)) { + snac snac; + + if (user_open(&snac, v)) { + xs *dir = xs_fmt("%s/hidden", snac.basedir); + + mkdir(dir, 0755); + user_free(&snac); + } + } + + nf = 2.3; + } if (f < nf) { f = nf; diff --git a/utils.c b/utils.c index f2543bb..bf457b2 100644 --- a/utils.c +++ b/utils.c @@ -237,7 +237,7 @@ int adduser(char *uid) } const char *dirs[] = { - "followers", "following", "local", "muted", + "followers", "following", "local", "muted", "hidden", "queue", "static", "timeline", "history", NULL }; int n;