summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
authorGravatar default2024-08-09 17:25:57 +0200
committerGravatar default2024-08-09 17:25:57 +0200
commit9457a7358a7b9e0fc5045a9906dd74d0cd6c6b27 (patch)
tree17868cd89a0334c1bcb309a855f35b37bc4cb15c /mastoapi.c
parentMore mastoapi_timeline() tweaks. (diff)
downloadpenes-snac2-9457a7358a7b9e0fc5045a9906dd74d0cd6c6b27.tar.gz
penes-snac2-9457a7358a7b9e0fc5045a9906dd74d0cd6c6b27.tar.xz
penes-snac2-9457a7358a7b9e0fc5045a9906dd74d0cd6c6b27.zip
Use mastoapi_timeline() also for the instance timeline and tags.
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c86
1 files changed, 7 insertions, 79 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 1e3788d..67f8016 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -1382,9 +1382,11 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn
1382 } while (cnt < limit && index_desc_next(f, md5)); 1382 } while (cnt < limit && index_desc_next(f, md5));
1383 } 1383 }
1384 1384
1385 int more = index_desc_next(f, md5);
1386
1385 fclose(f); 1387 fclose(f);
1386 1388
1387 srv_debug(1, xs_fmt("mastoapi_timeline: %d %d", cnt, xs_list_len(out))); 1389 srv_debug(1, xs_fmt("mastoapi_timeline: %d %d %d", cnt, xs_list_len(out), more));
1388 1390
1389 return out; 1391 return out;
1390} 1392}
@@ -1664,50 +1666,12 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1664 else 1666 else
1665 if (strcmp(cmd, "/v1/timelines/public") == 0) { /** **/ 1667 if (strcmp(cmd, "/v1/timelines/public") == 0) { /** **/
1666 /* the instance public timeline (public timelines for all users) */ 1668 /* the instance public timeline (public timelines for all users) */
1667
1668 const char *limit_s = xs_dict_get(args, "limit");
1669 int limit = 0;
1670 int cnt = 0;
1671
1672 if (!xs_is_null(limit_s))
1673 limit = atoi(limit_s);
1674
1675 if (limit == 0)
1676 limit = 20;
1677
1678 xs *timeline = timeline_instance_list(0, limit);
1679 xs *out = xs_list_new();
1680 xs_list *p = timeline;
1681 const xs_str *md5;
1682
1683 snac *user = NULL; 1669 snac *user = NULL;
1684 if (logged_in) 1670 if (logged_in)
1685 user = &snac1; 1671 user = &snac1;
1686 1672
1687 while (xs_list_iter(&p, &md5) && cnt < limit) { 1673 xs *ifn = instance_index_fn();
1688 xs *msg = NULL; 1674 xs *out = mastoapi_timeline(user, args, ifn);
1689
1690 /* get the entry */
1691 if (!valid_status(object_get_by_md5(md5, &msg)))
1692 continue;
1693
1694 /* discard non-Notes */
1695 const char *type = xs_dict_get(msg, "type");
1696 if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0)
1697 continue;
1698
1699 /* discard messages from private users */
1700 if (is_msg_from_private_user(msg))
1701 continue;
1702
1703 /* convert the Note into a Mastodon status */
1704 xs *st = mastoapi_status(user, msg);
1705
1706 if (st != NULL) {
1707 out = xs_list_append(out, st);
1708 cnt++;
1709 }
1710 }
1711 1675
1712 *body = xs_json_dumps(out, 4); 1676 *body = xs_json_dumps(out, 4);
1713 *ctype = "application/json"; 1677 *ctype = "application/json";
@@ -1715,48 +1679,12 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1715 } 1679 }
1716 else 1680 else
1717 if (xs_startswith(cmd, "/v1/timelines/tag/")) { /** **/ 1681 if (xs_startswith(cmd, "/v1/timelines/tag/")) { /** **/
1718 const char *limit_s = xs_dict_get(args, "limit");
1719 int limit = 0;
1720 int cnt = 0;
1721
1722 if (!xs_is_null(limit_s))
1723 limit = atoi(limit_s);
1724
1725 if (limit == 0)
1726 limit = 20;
1727
1728 /* get the tag */ 1682 /* get the tag */
1729 xs *l = xs_split(cmd, "/"); 1683 xs *l = xs_split(cmd, "/");
1730 const char *tag = xs_list_get(l, -1); 1684 const char *tag = xs_list_get(l, -1);
1731 1685
1732 xs *timeline = tag_search(tag, 0, limit); 1686 xs *ifn = tag_fn(tag);
1733 xs *out = xs_list_new(); 1687 xs *out = mastoapi_timeline(NULL, args, ifn);
1734 xs_list *p = timeline;
1735 const xs_str *md5;
1736
1737 while (xs_list_iter(&p, &md5) && cnt < limit) {
1738 xs *msg = NULL;
1739
1740 /* get the entry */
1741 if (!valid_status(object_get_by_md5(md5, &msg)))
1742 continue;
1743
1744 /* skip non-public messages */
1745 if (!is_msg_public(msg))
1746 continue;
1747
1748 /* discard messages from private users */
1749 if (is_msg_from_private_user(msg))
1750 continue;
1751
1752 /* convert the Note into a Mastodon status */
1753 xs *st = mastoapi_status(NULL, msg);
1754
1755 if (st != NULL) {
1756 out = xs_list_append(out, st);
1757 cnt++;
1758 }
1759 }
1760 1688
1761 *body = xs_json_dumps(out, 4); 1689 *body = xs_json_dumps(out, 4);
1762 *ctype = "application/json"; 1690 *ctype = "application/json";