summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
authorGravatar default2024-08-09 17:17:27 +0200
committerGravatar default2024-08-09 17:17:27 +0200
commit61d8b46782e420528694983bd5139579d7de9763 (patch)
treeba012230a80edb82d3e435fdbdb0c3ffa541ab53 /mastoapi.c
parentUse index_desc_first() / index_desc_next() in mastoapi_timeline(). (diff)
downloadsnac2-61d8b46782e420528694983bd5139579d7de9763.tar.gz
snac2-61d8b46782e420528694983bd5139579d7de9763.tar.xz
snac2-61d8b46782e420528694983bd5139579d7de9763.zip
More mastoapi_timeline() tweaks.
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c53
1 files changed, 35 insertions, 18 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 4d920de..1e3788d 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -1261,7 +1261,7 @@ void credentials_get(char **body, char **ctype, int *status, snac snac)
1261} 1261}
1262 1262
1263 1263
1264xs_list *mastoapi_timeline(snac *user, const xs_dict *args, int skip, const char *index_fn) 1264xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn)
1265{ 1265{
1266 xs_list *out = xs_list_new(); 1266 xs_list *out = xs_list_new();
1267 FILE *f; 1267 FILE *f;
@@ -1269,7 +1269,7 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, int skip, const char
1269 1269
1270 if (dbglevel) { 1270 if (dbglevel) {
1271 xs *js = xs_json_dumps(args, 0); 1271 xs *js = xs_json_dumps(args, 0);
1272 srv_log(xs_fmt("mastoapi_timeline args: %s", js)); 1272 srv_debug(1, xs_fmt("mastoapi_timeline args: %s", js));
1273 } 1273 }
1274 1274
1275 if ((f = fopen(index_fn, "r")) == NULL) 1275 if ((f = fopen(index_fn, "r")) == NULL)
@@ -1288,7 +1288,7 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, int skip, const char
1288 if (limit == 0) 1288 if (limit == 0)
1289 limit = 20; 1289 limit = 20;
1290 1290
1291 if (index_desc_first(f, md5, skip)) { 1291 if (index_desc_first(f, md5, 0)) {
1292 do { 1292 do {
1293 xs *msg = NULL; 1293 xs *msg = NULL;
1294 1294
@@ -1314,8 +1314,14 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, int skip, const char
1314 } 1314 }
1315 1315
1316 /* get the entry */ 1316 /* get the entry */
1317 if (!valid_status(timeline_get_by_md5(user, md5, &msg))) 1317 if (user) {
1318 continue; 1318 if (!valid_status(timeline_get_by_md5(user, md5, &msg)))
1319 continue;
1320 }
1321 else {
1322 if (!valid_status(object_get_by_md5(md5, &msg)))
1323 continue;
1324 }
1319 1325
1320 /* discard non-Notes */ 1326 /* discard non-Notes */
1321 const char *id = xs_dict_get(msg, "id"); 1327 const char *id = xs_dict_get(msg, "id");
@@ -1333,22 +1339,33 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, int skip, const char
1333 if (from == NULL) 1339 if (from == NULL)
1334 continue; 1340 continue;
1335 1341
1336 /* is this message from a person we don't follow? */ 1342 if (user) {
1337 if (strcmp(from, user->actor) && !following_check(user, from)) { 1343 /* is this message from a person we don't follow? */
1338 /* discard if it was not boosted */ 1344 if (strcmp(from, user->actor) && !following_check(user, from)) {
1339 xs *idx = object_announces(id); 1345 /* discard if it was not boosted */
1346 xs *idx = object_announces(id);
1347
1348 if (xs_list_len(idx) == 0)
1349 continue;
1350 }
1351
1352 /* discard notes from muted morons */
1353 if (is_muted(user, from))
1354 continue;
1340 1355
1341 if (xs_list_len(idx) == 0) 1356 /* discard hidden notes */
1357 if (is_hidden(user, id))
1342 continue; 1358 continue;
1343 } 1359 }
1360 else {
1361 /* skip non-public messages */
1362 if (!is_msg_public(msg))
1363 continue;
1344 1364
1345 /* discard notes from muted morons */ 1365 /* discard messages from private users */
1346 if (is_muted(user, from)) 1366 if (is_msg_from_private_user(msg))
1347 continue; 1367 continue;
1348 1368 }
1349 /* discard hidden notes */
1350 if (is_hidden(user, id))
1351 continue;
1352 1369
1353 /* if it has a name and it's not a Page or a Video, 1370 /* if it has a name and it's not a Page or a Video,
1354 it's a poll vote, so discard it */ 1371 it's a poll vote, so discard it */
@@ -1632,7 +1649,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1632 /* the private timeline */ 1649 /* the private timeline */
1633 if (logged_in) { 1650 if (logged_in) {
1634 xs *ifn = user_index_fn(&snac1, "private"); 1651 xs *ifn = user_index_fn(&snac1, "private");
1635 xs *out = mastoapi_timeline(&snac1, args, 0, ifn); 1652 xs *out = mastoapi_timeline(&snac1, args, ifn);
1636 1653
1637 *body = xs_json_dumps(out, 4); 1654 *body = xs_json_dumps(out, 4);
1638 *ctype = "application/json"; 1655 *ctype = "application/json";