summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
authorGravatar default2024-08-09 18:07:05 +0200
committerGravatar default2024-08-09 18:07:05 +0200
commit35503ed2b4b557d369ca887719c8b79fa4eff37e (patch)
treeb6021107be568d915cb5b45aec85d99e0ff1d5bb /mastoapi.c
parentUse mastoapi_timeline() also for the instance timeline and tags. (diff)
downloadpenes-snac2-35503ed2b4b557d369ca887719c8b79fa4eff37e.tar.gz
penes-snac2-35503ed2b4b557d369ca887719c8b79fa4eff37e.tar.xz
penes-snac2-35503ed2b4b557d369ca887719c8b79fa4eff37e.zip
mastoapi: also use mastoapi_timeline() with lists.
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c63
1 files changed, 5 insertions, 58 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 67f8016..f004587 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -1375,10 +1375,11 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn
1375 /* convert the Note into a Mastodon status */ 1375 /* convert the Note into a Mastodon status */
1376 xs *st = mastoapi_status(user, msg); 1376 xs *st = mastoapi_status(user, msg);
1377 1377
1378 if (st != NULL) 1378 if (st != NULL) {
1379 out = xs_list_append(out, st); 1379 out = xs_list_append(out, st);
1380 cnt++;
1381 }
1380 1382
1381 cnt++;
1382 } while (cnt < limit && index_desc_next(f, md5)); 1383 } while (cnt < limit && index_desc_next(f, md5));
1383 } 1384 }
1384 1385
@@ -1697,62 +1698,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1697 xs *l = xs_split(cmd, "/"); 1698 xs *l = xs_split(cmd, "/");
1698 const char *list = xs_list_get(l, -1); 1699 const char *list = xs_list_get(l, -1);
1699 1700
1700 xs *timeline = list_timeline(&snac1, list, 0, 2048); 1701 xs *ifn = list_timeline_fn(&snac1, list);
1701 xs *out = xs_list_new(); 1702 xs *out = mastoapi_timeline(NULL, args, ifn);
1702 int c = 0;
1703 const char *md5;
1704
1705 while (xs_list_next(timeline, &md5, &c)) {
1706 xs *msg = NULL;
1707
1708 /* get the entry */
1709 if (!valid_status(timeline_get_by_md5(&snac1, md5, &msg)))
1710 continue;
1711
1712 /* discard non-Notes */
1713 const char *id = xs_dict_get(msg, "id");
1714 const char *type = xs_dict_get(msg, "type");
1715 if (!xs_match(type, POSTLIKE_OBJECT_TYPE))
1716 continue;
1717
1718 const char *from = NULL;
1719 if (strcmp(type, "Page") == 0)
1720 from = xs_dict_get(msg, "audience");
1721
1722 if (from == NULL)
1723 from = get_atto(msg);
1724
1725 if (from == NULL)
1726 continue;
1727
1728 /* is this message from a person we don't follow? */
1729 if (strcmp(from, snac1.actor) && !following_check(&snac1, from)) {
1730 /* discard if it was not boosted */
1731 xs *idx = object_announces(id);
1732
1733 if (xs_list_len(idx) == 0)
1734 continue;
1735 }
1736
1737 /* discard notes from muted morons */
1738 if (is_muted(&snac1, from))
1739 continue;
1740
1741 /* discard hidden notes */
1742 if (is_hidden(&snac1, id))
1743 continue;
1744
1745 /* if it has a name and it's not a Page or a Video,
1746 it's a poll vote, so discard it */
1747 if (!xs_is_null(xs_dict_get(msg, "name")) && !xs_match(type, "Page|Video"))
1748 continue;
1749
1750 /* convert the Note into a Mastodon status */
1751 xs *st = mastoapi_status(&snac1, msg);
1752
1753 if (st != NULL)
1754 out = xs_list_append(out, st);
1755 }
1756 1703
1757 *body = xs_json_dumps(out, 4); 1704 *body = xs_json_dumps(out, 4);
1758 *ctype = "application/json"; 1705 *ctype = "application/json";