diff options
| author | 2023-07-05 14:06:21 +0200 | |
|---|---|---|
| committer | 2023-07-05 14:06:21 +0200 | |
| commit | eef3c419dd11f324e4817cda0282d727b18d41d3 (patch) | |
| tree | 38773040304d0469a2d4479e74ac8f7fd578caee | |
| parent | Pinned posts appear at the top of the public timeline. (diff) | |
| download | snac2-eef3c419dd11f324e4817cda0282d727b18d41d3.tar.gz snac2-eef3c419dd11f324e4817cda0282d727b18d41d3.tar.xz snac2-eef3c419dd11f324e4817cda0282d727b18d41d3.zip | |
Posts can be pinned/unpinned from the web interface.
| -rw-r--r-- | data.c | 8 | ||||
| -rw-r--r-- | html.c | 24 |
2 files changed, 25 insertions, 7 deletions
| @@ -901,11 +901,11 @@ int object_user_cache_in(snac *snac, const char *id, const char *cachedir) | |||
| 901 | } | 901 | } |
| 902 | 902 | ||
| 903 | 903 | ||
| 904 | xs_list *object_user_cache_list(snac *snac, const char *cachedir, int max) | 904 | xs_list *object_user_cache_list(snac *snac, const char *cachedir, int max, int inv) |
| 905 | /* returns the objects in a cache as a list */ | 905 | /* returns the objects in a cache as a list */ |
| 906 | { | 906 | { |
| 907 | xs *idx = xs_fmt("%s/%s.idx", snac->basedir, cachedir); | 907 | xs *idx = xs_fmt("%s/%s.idx", snac->basedir, cachedir); |
| 908 | return index_list(idx, max); | 908 | return inv ? index_list_desc(idx, 0, max) : index_list(idx, max); |
| 909 | } | 909 | } |
| 910 | 910 | ||
| 911 | 911 | ||
| @@ -945,7 +945,7 @@ int follower_check(snac *snac, const char *actor) | |||
| 945 | xs_list *follower_list(snac *snac) | 945 | xs_list *follower_list(snac *snac) |
| 946 | /* returns the list of followers */ | 946 | /* returns the list of followers */ |
| 947 | { | 947 | { |
| 948 | xs *list = object_user_cache_list(snac, "followers", XS_ALL); | 948 | xs *list = object_user_cache_list(snac, "followers", XS_ALL, 0); |
| 949 | xs_list *fwers = xs_list_new(); | 949 | xs_list *fwers = xs_list_new(); |
| 950 | char *p, *v; | 950 | char *p, *v; |
| 951 | 951 | ||
| @@ -1408,7 +1408,7 @@ int unpin(snac *user, const char *id) | |||
| 1408 | xs_list *pinned_list(snac *user) | 1408 | xs_list *pinned_list(snac *user) |
| 1409 | /* return the lists of pinned posts */ | 1409 | /* return the lists of pinned posts */ |
| 1410 | { | 1410 | { |
| 1411 | return object_user_cache_list(user, "pinned", XS_ALL); | 1411 | return object_user_cache_list(user, "pinned", XS_ALL, 1); |
| 1412 | } | 1412 | } |
| 1413 | 1413 | ||
| 1414 | 1414 | ||
| @@ -657,9 +657,17 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch | |||
| 657 | s = xs_str_cat(s, s1); | 657 | s = xs_str_cat(s, s1); |
| 658 | } | 658 | } |
| 659 | 659 | ||
| 660 | if (xs_list_in(likes, snac->md5) == -1) { | 660 | if (!xs_startswith(id, snac->actor)) { |
| 661 | /* not already liked; add button */ | 661 | if (xs_list_in(likes, snac->md5) == -1) { |
| 662 | s = html_button(s, "like", L("Like")); | 662 | /* not already liked; add button */ |
| 663 | s = html_button(s, "like", L("Like")); | ||
| 664 | } | ||
| 665 | } | ||
| 666 | else { | ||
| 667 | if (is_pinned(snac, id)) | ||
| 668 | s = html_button(s, "unpin", L("Unpin")); | ||
| 669 | else | ||
| 670 | s = html_button(s, "pin", L("Pin")); | ||
| 663 | } | 671 | } |
| 664 | 672 | ||
| 665 | if (is_msg_public(snac, msg)) { | 673 | if (is_msg_public(snac, msg)) { |
| @@ -2090,6 +2098,16 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 2090 | } | 2098 | } |
| 2091 | } | 2099 | } |
| 2092 | else | 2100 | else |
| 2101 | if (strcmp(action, L("Pin")) == 0) { /** **/ | ||
| 2102 | pin(&snac, id); | ||
| 2103 | timeline_touch(&snac); | ||
| 2104 | } | ||
| 2105 | else | ||
| 2106 | if (strcmp(action, L("Unpin")) == 0) { /** **/ | ||
| 2107 | unpin(&snac, id); | ||
| 2108 | timeline_touch(&snac); | ||
| 2109 | } | ||
| 2110 | else | ||
| 2093 | status = 404; | 2111 | status = 404; |
| 2094 | 2112 | ||
| 2095 | /* delete the cached timeline */ | 2113 | /* delete the cached timeline */ |