commit eef3c41

default  ·  2023-07-05 12:06:21 +0000 UTC
parent 57ba1d5
Posts can be pinned/unpinned from the web interface.
2 files changed,  +25, -7
M data.c
M html.c
M data.c
+4, -4
 1@@ -901,11 +901,11 @@ int object_user_cache_in(snac *snac, const char *id, const char *cachedir)
 2 }
 3 
 4 
 5-xs_list *object_user_cache_list(snac *snac, const char *cachedir, int max)
 6+xs_list *object_user_cache_list(snac *snac, const char *cachedir, int max, int inv)
 7 /* returns the objects in a cache as a list */
 8 {
 9     xs *idx = xs_fmt("%s/%s.idx", snac->basedir, cachedir);
10-    return index_list(idx, max);
11+    return inv ? index_list_desc(idx, 0, max) : index_list(idx, max);
12 }
13 
14 
15@@ -945,7 +945,7 @@ int follower_check(snac *snac, const char *actor)
16 xs_list *follower_list(snac *snac)
17 /* returns the list of followers */
18 {
19-    xs *list       = object_user_cache_list(snac, "followers", XS_ALL);
20+    xs *list       = object_user_cache_list(snac, "followers", XS_ALL, 0);
21     xs_list *fwers = xs_list_new();
22     char *p, *v;
23 
24@@ -1408,7 +1408,7 @@ int unpin(snac *user, const char *id)
25 xs_list *pinned_list(snac *user)
26 /* return the lists of pinned posts */
27 {
28-    return object_user_cache_list(user, "pinned", XS_ALL);
29+    return object_user_cache_list(user, "pinned", XS_ALL, 1);
30 }
31 
32 
M html.c
+21, -3
 1@@ -657,9 +657,17 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
 2         s = xs_str_cat(s, s1);
 3     }
 4 
 5-    if (xs_list_in(likes, snac->md5) == -1) {
 6-        /* not already liked; add button */
 7-        s = html_button(s, "like", L("Like"));
 8+    if (!xs_startswith(id, snac->actor)) {
 9+        if (xs_list_in(likes, snac->md5) == -1) {
10+            /* not already liked; add button */
11+            s = html_button(s, "like", L("Like"));
12+        }
13+    }
14+    else {
15+        if (is_pinned(snac, id))
16+            s = html_button(s, "unpin", L("Unpin"));
17+        else
18+            s = html_button(s, "pin", L("Pin"));
19     }
20 
21     if (is_msg_public(snac, msg)) {
22@@ -2089,6 +2097,16 @@ int html_post_handler(const xs_dict *req, const char *q_path,
23                 snac_log(&snac, xs_fmt("deleted entry %s", id));
24             }
25         }
26+        else
27+        if (strcmp(action, L("Pin")) == 0) { /** **/
28+            pin(&snac, id);
29+            timeline_touch(&snac);
30+        }
31+        else
32+        if (strcmp(action, L("Unpin")) == 0) { /** **/
33+            unpin(&snac, id);
34+            timeline_touch(&snac);
35+        }
36         else
37             status = 404;
38