commit ede4d6f

default  ·  2023-04-30 04:39:55 +0000 UTC
parent 6b632e1
Some instance timeline work.
3 files changed,  +38, -35
M data.c
M snac.h
M data.c
+11, -2
 1@@ -1046,7 +1046,7 @@ xs_list *timeline_top_level(snac *snac, xs_list *list)
 2 }
 3 
 4 
 5-d_char *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show)
 6+xs_list *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show)
 7 /* returns a timeline (with all entries) */
 8 {
 9     int c_max;
10@@ -1064,7 +1064,7 @@ d_char *timeline_simple_list(snac *snac, const char *idx_name, int skip, int sho
11 }
12 
13 
14-d_char *timeline_list(snac *snac, const char *idx_name, int skip, int show)
15+xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show)
16 /* returns a timeline (only top level entries) */
17 {
18     xs *list = timeline_simple_list(snac, idx_name, skip, show);
19@@ -1073,6 +1073,15 @@ d_char *timeline_list(snac *snac, const char *idx_name, int skip, int show)
20 }
21 
22 
23+xs_list *timeline_instance_list(int skip, int show)
24+/* returns the timeline for the full instance */
25+{
26+    xs *idx = xs_fmt("%s/public.idx", srv_basedir);
27+
28+    return index_list_desc(idx, skip, show);
29+}
30+
31+
32 /** following **/
33 
34 /* this needs special treatment and cannot use the object db as is,
+23, -29
 1@@ -1038,9 +1038,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2     if (strcmp(cmd, "/v1/timelines/public") == 0) {
 3         /* the public timeline (public timelines for all users) */
 4 
 5-        /* this is an ugly kludge: first users in the list get all the fame */
 6-
 7-        const char *limit_s  = xs_dict_get(args, "limit");
 8+        const char *limit_s = xs_dict_get(args, "limit");
 9         int limit = 0;
10         int cnt   = 0;
11 
12@@ -1050,44 +1048,40 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
13         if (limit == 0)
14             limit = 20;
15 
16-        xs *out    = xs_list_new();
17-        xs *users  = user_list();
18-        xs_list *p = users;
19-        xs_str *uid;
20-
21-        while (xs_list_iter(&p, &uid) && cnt < limit) {
22-            snac user;
23+        xs *timeline = timeline_instance_list(0, limit);
24+        xs *out      = xs_list_new();
25+        xs_list *p   = timeline;
26+        xs_str *md5;
27 
28-            if (user_open(&user, uid)) {
29-                xs *timeline = timeline_simple_list(&user, "public", 0, 4);
30-                xs_list *p2  = timeline;
31-                xs_str *v;
32+        while (xs_list_iter(&p, &md5) && cnt < limit) {
33+            xs *msg = NULL;
34 
35-                while (xs_list_iter(&p2, &v) && cnt < limit) {
36-                    xs *msg = NULL;
37+            /* get the entry */
38+            if (!valid_status(object_get_by_md5(md5, &msg)))
39+                continue;
40 
41-                    /* get the entry */
42-                    if (!valid_status(timeline_get_by_md5(&user, v, &msg)))
43-                        continue;
44+            /* discard non-Notes */
45+            if (strcmp(xs_dict_get(msg, "type"), "Note") != 0)
46+                continue;
47 
48-                    /* discard non-Notes */
49-                    if (strcmp(xs_dict_get(msg, "type"), "Note") != 0)
50-                        continue;
51+            /* get the uid */
52+            xs *l = xs_split(xs_dict_get(msg, "attributedTo"), "/");
53+            const char *uid = xs_list_get(l, -1);
54 
55-                    /* discard entries not by this user */
56-                    if (!xs_startswith(xs_dict_get(msg, "id"), user.actor))
57-                        continue;
58+            if (!xs_is_null(uid)) {
59+                snac user;
60 
61+                if (user_open(&user, uid)) {
62                     /* convert the Note into a Mastodon status */
63                     xs *st = mastoapi_status(&user, msg);
64 
65-                    if (st != NULL) {
66+                    if (st != NULL)
67                         out = xs_list_append(out, st);
68-                        cnt++;
69-                    }
70+
71+                    user_free(&user);
72                 }
73 
74-                user_free(&user);
75+                cnt++;
76             }
77         }
78 
M snac.h
+4, -4
 1@@ -105,14 +105,14 @@ int timeline_touch(snac *snac);
 2 int timeline_here(snac *snac, const char *md5);
 3 int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg);
 4 int timeline_del(snac *snac, char *id);
 5-d_char *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show);
 6-d_char *timeline_list(snac *snac, const char *idx_name, int skip, int show);
 7+xs_list *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show);
 8+xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show);
 9 int timeline_add(snac *snac, char *id, char *o_msg);
10 void timeline_admire(snac *snac, char *id, char *admirer, int like);
11 
12 xs_list *timeline_top_level(snac *snac, xs_list *list);
13-
14-d_char *local_list(snac *snac, int max);
15+xs_list *local_list(snac *snac, int max);
16+xs_list *timeline_instance_list(int skip, int show);
17 
18 int following_add(snac *snac, const char *actor, const xs_dict *msg);
19 int following_del(snac *snac, const char *actor);