summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-04-30 06:39:55 +0200
committerGravatar default2023-04-30 06:39:55 +0200
commitede4d6f2dc8f862337724054dcfeb31cbaa89bcc (patch)
tree2a3c0f5ee89a0825cc4902de1f2ace86873e8250
parentBumped version. (diff)
downloadpenes-snac2-ede4d6f2dc8f862337724054dcfeb31cbaa89bcc.tar.gz
penes-snac2-ede4d6f2dc8f862337724054dcfeb31cbaa89bcc.tar.xz
penes-snac2-ede4d6f2dc8f862337724054dcfeb31cbaa89bcc.zip
Some instance timeline work.
-rw-r--r--data.c13
-rw-r--r--mastoapi.c52
-rw-r--r--snac.h8
3 files changed, 38 insertions, 35 deletions
diff --git a/data.c b/data.c
index db42ece..60c4b26 100644
--- a/data.c
+++ b/data.c
@@ -1046,7 +1046,7 @@ xs_list *timeline_top_level(snac *snac, xs_list *list)
1046} 1046}
1047 1047
1048 1048
1049d_char *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show) 1049xs_list *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show)
1050/* returns a timeline (with all entries) */ 1050/* returns a timeline (with all entries) */
1051{ 1051{
1052 int c_max; 1052 int c_max;
@@ -1064,7 +1064,7 @@ d_char *timeline_simple_list(snac *snac, const char *idx_name, int skip, int sho
1064} 1064}
1065 1065
1066 1066
1067d_char *timeline_list(snac *snac, const char *idx_name, int skip, int show) 1067xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show)
1068/* returns a timeline (only top level entries) */ 1068/* returns a timeline (only top level entries) */
1069{ 1069{
1070 xs *list = timeline_simple_list(snac, idx_name, skip, show); 1070 xs *list = timeline_simple_list(snac, idx_name, skip, show);
@@ -1073,6 +1073,15 @@ d_char *timeline_list(snac *snac, const char *idx_name, int skip, int show)
1073} 1073}
1074 1074
1075 1075
1076xs_list *timeline_instance_list(int skip, int show)
1077/* returns the timeline for the full instance */
1078{
1079 xs *idx = xs_fmt("%s/public.idx", srv_basedir);
1080
1081 return index_list_desc(idx, skip, show);
1082}
1083
1084
1076/** following **/ 1085/** following **/
1077 1086
1078/* this needs special treatment and cannot use the object db as is, 1087/* this needs special treatment and cannot use the object db as is,
diff --git a/mastoapi.c b/mastoapi.c
index 001c0bc..92acd41 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -1038,9 +1038,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1038 if (strcmp(cmd, "/v1/timelines/public") == 0) { 1038 if (strcmp(cmd, "/v1/timelines/public") == 0) {
1039 /* the public timeline (public timelines for all users) */ 1039 /* the public timeline (public timelines for all users) */
1040 1040
1041 /* this is an ugly kludge: first users in the list get all the fame */ 1041 const char *limit_s = xs_dict_get(args, "limit");
1042
1043 const char *limit_s = xs_dict_get(args, "limit");
1044 int limit = 0; 1042 int limit = 0;
1045 int cnt = 0; 1043 int cnt = 0;
1046 1044
@@ -1050,44 +1048,40 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1050 if (limit == 0) 1048 if (limit == 0)
1051 limit = 20; 1049 limit = 20;
1052 1050
1053 xs *out = xs_list_new(); 1051 xs *timeline = timeline_instance_list(0, limit);
1054 xs *users = user_list(); 1052 xs *out = xs_list_new();
1055 xs_list *p = users; 1053 xs_list *p = timeline;
1056 xs_str *uid; 1054 xs_str *md5;
1057
1058 while (xs_list_iter(&p, &uid) && cnt < limit) {
1059 snac user;
1060 1055
1061 if (user_open(&user, uid)) { 1056 while (xs_list_iter(&p, &md5) && cnt < limit) {
1062 xs *timeline = timeline_simple_list(&user, "public", 0, 4); 1057 xs *msg = NULL;
1063 xs_list *p2 = timeline;
1064 xs_str *v;
1065 1058
1066 while (xs_list_iter(&p2, &v) && cnt < limit) { 1059 /* get the entry */
1067 xs *msg = NULL; 1060 if (!valid_status(object_get_by_md5(md5, &msg)))
1061 continue;
1068 1062
1069 /* get the entry */ 1063 /* discard non-Notes */
1070 if (!valid_status(timeline_get_by_md5(&user, v, &msg))) 1064 if (strcmp(xs_dict_get(msg, "type"), "Note") != 0)
1071 continue; 1065 continue;
1072 1066
1073 /* discard non-Notes */ 1067 /* get the uid */
1074 if (strcmp(xs_dict_get(msg, "type"), "Note") != 0) 1068 xs *l = xs_split(xs_dict_get(msg, "attributedTo"), "/");
1075 continue; 1069 const char *uid = xs_list_get(l, -1);
1076 1070
1077 /* discard entries not by this user */ 1071 if (!xs_is_null(uid)) {
1078 if (!xs_startswith(xs_dict_get(msg, "id"), user.actor)) 1072 snac user;
1079 continue;
1080 1073
1074 if (user_open(&user, uid)) {
1081 /* convert the Note into a Mastodon status */ 1075 /* convert the Note into a Mastodon status */
1082 xs *st = mastoapi_status(&user, msg); 1076 xs *st = mastoapi_status(&user, msg);
1083 1077
1084 if (st != NULL) { 1078 if (st != NULL)
1085 out = xs_list_append(out, st); 1079 out = xs_list_append(out, st);
1086 cnt++; 1080
1087 } 1081 user_free(&user);
1088 } 1082 }
1089 1083
1090 user_free(&user); 1084 cnt++;
1091 } 1085 }
1092 } 1086 }
1093 1087
diff --git a/snac.h b/snac.h
index a17d33f..5478933 100644
--- a/snac.h
+++ b/snac.h
@@ -105,14 +105,14 @@ int timeline_touch(snac *snac);
105int timeline_here(snac *snac, const char *md5); 105int timeline_here(snac *snac, const char *md5);
106int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg); 106int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg);
107int timeline_del(snac *snac, char *id); 107int timeline_del(snac *snac, char *id);
108d_char *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show); 108xs_list *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show);
109d_char *timeline_list(snac *snac, const char *idx_name, int skip, int show); 109xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show);
110int timeline_add(snac *snac, char *id, char *o_msg); 110int timeline_add(snac *snac, char *id, char *o_msg);
111void timeline_admire(snac *snac, char *id, char *admirer, int like); 111void timeline_admire(snac *snac, char *id, char *admirer, int like);
112 112
113xs_list *timeline_top_level(snac *snac, xs_list *list); 113xs_list *timeline_top_level(snac *snac, xs_list *list);
114 114xs_list *local_list(snac *snac, int max);
115d_char *local_list(snac *snac, int max); 115xs_list *timeline_instance_list(int skip, int show);
116 116
117int following_add(snac *snac, const char *actor, const xs_dict *msg); 117int following_add(snac *snac, const char *actor, const xs_dict *msg);
118int following_del(snac *snac, const char *actor); 118int following_del(snac *snac, const char *actor);