diff options
| author | 2022-11-24 09:49:54 +0100 | |
|---|---|---|
| committer | 2022-11-24 09:49:54 +0100 | |
| commit | d215f8ce4634ab769f52d70119fed2dd0d8124f9 (patch) | |
| tree | 979600293c8a3c5b917a369ce090680759f7e47d | |
| parent | New API for hidden threads. (diff) | |
| download | snac2-d215f8ce4634ab769f52d70119fed2dd0d8124f9.tar.gz snac2-d215f8ce4634ab769f52d70119fed2dd0d8124f9.tar.xz snac2-d215f8ce4634ab769f52d70119fed2dd0d8124f9.zip | |
Use the new hide API.
Diffstat (limited to '')
| -rw-r--r-- | data.c | 48 | ||||
| -rw-r--r-- | html.c | 4 | ||||
| -rw-r--r-- | snac.h | 1 | ||||
| -rw-r--r-- | upgrade.c | 19 | ||||
| -rw-r--r-- | utils.c | 2 |
5 files changed, 24 insertions, 50 deletions
| @@ -14,7 +14,7 @@ | |||
| 14 | #include <sys/file.h> | 14 | #include <sys/file.h> |
| 15 | #include <fcntl.h> | 15 | #include <fcntl.h> |
| 16 | 16 | ||
| 17 | double db_layout = 2.2; | 17 | double db_layout = 2.3; |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | int db_upgrade(d_char **error); | 20 | int db_upgrade(d_char **error); |
| @@ -913,50 +913,6 @@ void timeline_admire(snac *snac, char *id, char *admirer, int like) | |||
| 913 | } | 913 | } |
| 914 | 914 | ||
| 915 | 915 | ||
| 916 | int timeline_hide(snac *snac, char *id, int hide) | ||
| 917 | /* hides/unhides a timeline entry */ | ||
| 918 | { | ||
| 919 | int ret = 0; | ||
| 920 | xs *fn = _timeline_find_fn(snac, id); | ||
| 921 | FILE *f; | ||
| 922 | |||
| 923 | if (fn != NULL && (f = fopen(fn, "r")) != NULL) { | ||
| 924 | xs *s1 = xs_readall(f); | ||
| 925 | xs *msg = xs_json_loads(s1); | ||
| 926 | xs *meta = xs_dup(xs_dict_get(msg, "_snac")); | ||
| 927 | xs *hdn = xs_val_new(hide ? XSTYPE_TRUE : XSTYPE_FALSE); | ||
| 928 | char *p, *v; | ||
| 929 | |||
| 930 | fclose(f); | ||
| 931 | |||
| 932 | /* if it's already in this hidden state, we're done */ | ||
| 933 | if ((v = xs_dict_get(meta, "hidden")) && xs_type(v) == xs_type(hdn)) | ||
| 934 | return ret; | ||
| 935 | |||
| 936 | meta = xs_dict_set(meta, "hidden", hdn); | ||
| 937 | msg = xs_dict_set(msg, "_snac", meta); | ||
| 938 | |||
| 939 | if ((f = fopen(fn, "w")) != NULL) { | ||
| 940 | xs *j1 = xs_json_dumps_pp(msg, 4); | ||
| 941 | |||
| 942 | fwrite(j1, strlen(j1), 1, f); | ||
| 943 | fclose(f); | ||
| 944 | |||
| 945 | snac_debug(snac, 1, xs_fmt("timeline_hide %d %s", hide, id)); | ||
| 946 | |||
| 947 | /* now hide the children */ | ||
| 948 | p = xs_dict_get(meta, "children"); | ||
| 949 | while (xs_list_iter(&p, &v)) | ||
| 950 | timeline_hide(snac, v, hide); | ||
| 951 | |||
| 952 | ret = 1; | ||
| 953 | } | ||
| 954 | } | ||
| 955 | |||
| 956 | return ret; | ||
| 957 | } | ||
| 958 | |||
| 959 | |||
| 960 | d_char *_following_fn(snac *snac, char *actor) | 916 | d_char *_following_fn(snac *snac, char *actor) |
| 961 | { | 917 | { |
| 962 | xs *md5 = xs_md5_hex(actor, strlen(actor)); | 918 | xs *md5 = xs_md5_hex(actor, strlen(actor)); |
| @@ -1109,7 +1065,7 @@ int is_muted(snac *snac, char *actor) | |||
| 1109 | d_char *_hidden_fn(snac *snac, const char *id) | 1065 | d_char *_hidden_fn(snac *snac, const char *id) |
| 1110 | { | 1066 | { |
| 1111 | xs *md5 = xs_md5_hex(id, strlen(id)); | 1067 | xs *md5 = xs_md5_hex(id, strlen(id)); |
| 1112 | return xs_fmt("%s/hidden/%s.json", snac->basedir, md5); | 1068 | return xs_fmt("%s/hidden/%s", snac->basedir, md5); |
| 1113 | } | 1069 | } |
| 1114 | 1070 | ||
| 1115 | 1071 | ||
| @@ -497,7 +497,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i | |||
| 497 | xs *s = xs_str_new(NULL); | 497 | xs *s = xs_str_new(NULL); |
| 498 | 498 | ||
| 499 | /* top wrap */ | 499 | /* top wrap */ |
| 500 | if ((v = xs_dict_get(meta, "hidden")) && xs_type(v) == XSTYPE_TRUE) | 500 | if (is_hidden(snac, id)) |
| 501 | s = xs_str_cat(s, "<div style=\"display: none\">\n"); | 501 | s = xs_str_cat(s, "<div style=\"display: none\">\n"); |
| 502 | else | 502 | else |
| 503 | s = xs_str_cat(s, "<div>\n"); | 503 | s = xs_str_cat(s, "<div>\n"); |
| @@ -1300,7 +1300,7 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, | |||
| 1300 | } | 1300 | } |
| 1301 | else | 1301 | else |
| 1302 | if (strcmp(action, L("Hide")) == 0) { | 1302 | if (strcmp(action, L("Hide")) == 0) { |
| 1303 | timeline_hide(&snac, id, 1); | 1303 | hide(&snac, id); |
| 1304 | } | 1304 | } |
| 1305 | else | 1305 | else |
| 1306 | if (strcmp(action, L("Follow")) == 0) { | 1306 | if (strcmp(action, L("Follow")) == 0) { |
| @@ -71,7 +71,6 @@ d_char *timeline_get(snac *snac, char *fn); | |||
| 71 | d_char *timeline_list(snac *snac, int max); | 71 | d_char *timeline_list(snac *snac, int max); |
| 72 | int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer); | 72 | int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer); |
| 73 | void timeline_admire(snac *snac, char *id, char *admirer, int like); | 73 | void timeline_admire(snac *snac, char *id, char *admirer, int like); |
| 74 | int timeline_hide(snac *snac, char *id, int hide); | ||
| 75 | 74 | ||
| 76 | d_char *local_list(snac *snac, int max); | 75 | d_char *local_list(snac *snac, int max); |
| 77 | 76 | ||
| @@ -74,6 +74,25 @@ int db_upgrade(d_char **error) | |||
| 74 | 74 | ||
| 75 | nf = 2.2; | 75 | nf = 2.2; |
| 76 | } | 76 | } |
| 77 | else | ||
| 78 | if (f < 2.3) { | ||
| 79 | xs *users = user_list(); | ||
| 80 | char *p, *v; | ||
| 81 | |||
| 82 | p = users; | ||
| 83 | while (xs_list_iter(&p, &v)) { | ||
| 84 | snac snac; | ||
| 85 | |||
| 86 | if (user_open(&snac, v)) { | ||
| 87 | xs *dir = xs_fmt("%s/hidden", snac.basedir); | ||
| 88 | |||
| 89 | mkdir(dir, 0755); | ||
| 90 | user_free(&snac); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | nf = 2.3; | ||
| 95 | } | ||
| 77 | 96 | ||
| 78 | if (f < nf) { | 97 | if (f < nf) { |
| 79 | f = nf; | 98 | f = nf; |
| @@ -237,7 +237,7 @@ int adduser(char *uid) | |||
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | const char *dirs[] = { | 239 | const char *dirs[] = { |
| 240 | "followers", "following", "local", "muted", | 240 | "followers", "following", "local", "muted", "hidden", |
| 241 | "queue", "static", "timeline", "history", NULL }; | 241 | "queue", "static", "timeline", "history", NULL }; |
| 242 | int n; | 242 | int n; |
| 243 | 243 | ||