commit f122180

default  ·  2024-04-29 08:15:04 +0000 UTC
parent 7f32230
More work in lists.
2 files changed,  +83, -1
M data.c
M data.c
+12, -1
 1@@ -1855,6 +1855,15 @@ xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op
 2     case 2: /** delete actor from list **/
 3         if (actor_md5 != NULL)
 4             index_del_md5(fn, actor_md5);
 5+
 6+        break;
 7+
 8+    case 3: /** list timeline **/
 9+        fn = xs_replace_i(fn, ".lst", ".idx");
10+
11+        l = index_list_desc(fn, 0, 2048);
12+
13+        break;
14     }
15 
16     return l;
17@@ -1880,7 +1889,9 @@ void list_distribute(snac *user, const xs_dict *post)
18             if (index_in_md5(v, a_md5)) {
19                 /* it is; add post md5 to its timeline */
20                 xs *idx = xs_replace(v, ".lst", ".idx");
21-                index_add(idx, i_md5);
22+                index_add_md5(idx, i_md5);
23+
24+                snac_debug(user, 1, xs_fmt("listed post %s in %s", id, idx));
25             }
26         }
27     }
+71, -0
 1@@ -1647,6 +1647,77 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2         status = 200;
 3     }
 4     else
 5+    if (xs_startswith(cmd, "/v1/timelines/list/")) { /** **/
 6+        /* get the list id */
 7+        if (logged_in) {
 8+            xs *l = xs_split(cmd, "/");
 9+            char *list = xs_list_get(l, -1);
10+
11+            xs *timeline = list_content(&snac1, list, NULL, 3);
12+            xs *out      = xs_list_new();
13+            int c = 0;
14+            char *md5;
15+
16+            while (xs_list_next(timeline, &md5, &c)) {
17+                xs *msg = NULL;
18+
19+                /* get the entry */
20+                if (!valid_status(timeline_get_by_md5(&snac1, md5, &msg)))
21+                    continue;
22+
23+                /* discard non-Notes */
24+                const char *id   = xs_dict_get(msg, "id");
25+                const char *type = xs_dict_get(msg, "type");
26+                if (!xs_match(type, "Note|Question|Page|Article|Video"))
27+                    continue;
28+
29+                const char *from = NULL;
30+                if (strcmp(type, "Page") == 0)
31+                    from = xs_dict_get(msg, "audience");
32+
33+                if (from == NULL)
34+                    from = get_atto(msg);
35+
36+                if (from == NULL)
37+                    continue;
38+
39+                /* is this message from a person we don't follow? */
40+                if (strcmp(from, snac1.actor) && !following_check(&snac1, from)) {
41+                    /* discard if it was not boosted */
42+                    xs *idx = object_announces(id);
43+
44+                    if (xs_list_len(idx) == 0)
45+                        continue;
46+                }
47+
48+                /* discard notes from muted morons */
49+                if (is_muted(&snac1, from))
50+                    continue;
51+
52+                /* discard hidden notes */
53+                if (is_hidden(&snac1, id))
54+                    continue;
55+
56+                /* if it has a name and it's not a Page or a Video,
57+                   it's a poll vote, so discard it */
58+                if (!xs_is_null(xs_dict_get(msg, "name")) && !xs_match(type, "Page|Video"))
59+                    continue;
60+
61+                /* convert the Note into a Mastodon status */
62+                xs *st = mastoapi_status(&snac1, msg);
63+
64+                if (st != NULL)
65+                    out = xs_list_append(out, st);
66+            }
67+
68+            *body  = xs_json_dumps(out, 4);
69+            *ctype = "application/json";
70+            status = 200;
71+        }
72+        else
73+            status = 421;
74+    }
75+    else
76     if (strcmp(cmd, "/v1/conversations") == 0) { /** **/
77         /* TBD */
78         *body  = xs_dup("[]");