commit 35503ed

default  ·  2024-08-09 16:07:05 +0000 UTC
parent 9457a73
mastoapi: also use mastoapi_timeline() with lists.
3 files changed,  +13, -59
M data.c
M snac.h
M data.c
+7, -1
 1@@ -1944,6 +1944,12 @@ xs_val *list_maint(snac *user, const char *list, int op)
 2 }
 3 
 4 
 5+xs_str *list_timeline_fn(snac *user, const char *list)
 6+{
 7+    return xs_fmt("%s/list/%s.idx", user->basedir, list);
 8+}
 9+
10+
11 xs_list *list_timeline(snac *user, const char *list, int skip, int show)
12 /* returns the timeline of a list */
13 {
14@@ -1952,7 +1958,7 @@ xs_list *list_timeline(snac *user, const char *list, int skip, int show)
15     if (!xs_is_hex(list))
16         return NULL;
17 
18-    xs *fn = xs_fmt("%s/list/%s.idx", user->basedir, list);
19+    xs *fn = list_timeline_fn(user, list);
20 
21     if (mtime(fn) > 0.0)
22         l = index_list_desc(fn, skip, show);
+5, -58
 1@@ -1375,10 +1375,11 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn
 2             /* convert the Note into a Mastodon status */
 3             xs *st = mastoapi_status(user, msg);
 4 
 5-            if (st != NULL)
 6+            if (st != NULL) {
 7                 out = xs_list_append(out, st);
 8+                cnt++;
 9+            }
10 
11-            cnt++;
12         } while (cnt < limit && index_desc_next(f, md5));
13     }
14 
15@@ -1697,62 +1698,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
16             xs *l = xs_split(cmd, "/");
17             const char *list = xs_list_get(l, -1);
18 
19-            xs *timeline = list_timeline(&snac1, list, 0, 2048);
20-            xs *out      = xs_list_new();
21-            int c = 0;
22-            const char *md5;
23-
24-            while (xs_list_next(timeline, &md5, &c)) {
25-                xs *msg = NULL;
26-
27-                /* get the entry */
28-                if (!valid_status(timeline_get_by_md5(&snac1, md5, &msg)))
29-                    continue;
30-
31-                /* discard non-Notes */
32-                const char *id   = xs_dict_get(msg, "id");
33-                const char *type = xs_dict_get(msg, "type");
34-                if (!xs_match(type, POSTLIKE_OBJECT_TYPE))
35-                    continue;
36-
37-                const char *from = NULL;
38-                if (strcmp(type, "Page") == 0)
39-                    from = xs_dict_get(msg, "audience");
40-
41-                if (from == NULL)
42-                    from = get_atto(msg);
43-
44-                if (from == NULL)
45-                    continue;
46-
47-                /* is this message from a person we don't follow? */
48-                if (strcmp(from, snac1.actor) && !following_check(&snac1, from)) {
49-                    /* discard if it was not boosted */
50-                    xs *idx = object_announces(id);
51-
52-                    if (xs_list_len(idx) == 0)
53-                        continue;
54-                }
55-
56-                /* discard notes from muted morons */
57-                if (is_muted(&snac1, from))
58-                    continue;
59-
60-                /* discard hidden notes */
61-                if (is_hidden(&snac1, id))
62-                    continue;
63-
64-                /* if it has a name and it's not a Page or a Video,
65-                   it's a poll vote, so discard it */
66-                if (!xs_is_null(xs_dict_get(msg, "name")) && !xs_match(type, "Page|Video"))
67-                    continue;
68-
69-                /* convert the Note into a Mastodon status */
70-                xs *st = mastoapi_status(&snac1, msg);
71-
72-                if (st != NULL)
73-                    out = xs_list_append(out, st);
74-            }
75+            xs *ifn = list_timeline_fn(&snac1, list);
76+            xs *out = mastoapi_timeline(NULL, args, ifn);
77 
78             *body  = xs_json_dumps(out, 4);
79             *ctype = "application/json";
M snac.h
+1, -0
1@@ -185,6 +185,7 @@ xs_str *tag_fn(const char *tag);
2 xs_list *tag_search(const char *tag, int skip, int show);
3 
4 xs_val *list_maint(snac *user, const char *list, int op);
5+xs_str *list_timeline_fn(snac *user, const char *list);
6 xs_list *list_timeline(snac *user, const char *list, int skip, int show);
7 xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int op);
8 void list_distribute(snac *user, const char *who, const xs_dict *post);