summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c60
1 files changed, 53 insertions, 7 deletions
diff --git a/mastoapi.c b/mastoapi.c
index c9d71b9..990898b 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -171,7 +171,7 @@ const char *login_page = ""
171"<body><h1>%s OAuth identify</h1>\n" 171"<body><h1>%s OAuth identify</h1>\n"
172"<div style=\"background-color: red; color: white\">%s</div>\n" 172"<div style=\"background-color: red; color: white\">%s</div>\n"
173"<form method=\"post\" action=\"%s:/" "/%s/%s\">\n" 173"<form method=\"post\" action=\"%s:/" "/%s/%s\">\n"
174"<p>Login: <input type=\"text\" name=\"login\"></p>\n" 174"<p>Login: <input type=\"text\" name=\"login\" autocapitalize=\"off\"></p>\n"
175"<p>Password: <input type=\"password\" name=\"passwd\"></p>\n" 175"<p>Password: <input type=\"password\" name=\"passwd\"></p>\n"
176"<input type=\"hidden\" name=\"redir\" value=\"%s\">\n" 176"<input type=\"hidden\" name=\"redir\" value=\"%s\">\n"
177"<input type=\"hidden\" name=\"cid\" value=\"%s\">\n" 177"<input type=\"hidden\" name=\"cid\" value=\"%s\">\n"
@@ -663,6 +663,17 @@ xs_dict *mastoapi_account(snac *logged, const xs_dict *actor)
663 if (user_open(&user, prefu)) { 663 if (user_open(&user, prefu)) {
664 val_links = user.links; 664 val_links = user.links;
665 metadata = xs_dict_get_def(user.config, "metadata", xs_stock(XSTYPE_DICT)); 665 metadata = xs_dict_get_def(user.config, "metadata", xs_stock(XSTYPE_DICT));
666
667 /* does this user want to publish their contact metrics? */
668 if (xs_is_true(xs_dict_get(user.config, "show_contact_metrics"))) {
669 xs *fwing = following_list(&user);
670 xs *fwers = follower_list(&user);
671 xs *ni = xs_number_new(xs_list_len(fwing));
672 xs *ne = xs_number_new(xs_list_len(fwers));
673
674 acct = xs_dict_append(acct, "followers_count", ne);
675 acct = xs_dict_append(acct, "following_count", ni);
676 }
666 } 677 }
667 } 678 }
668 679
@@ -827,7 +838,16 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
827 st = xs_dict_append(st, "url", id); 838 st = xs_dict_append(st, "url", id);
828 st = xs_dict_append(st, "account", acct); 839 st = xs_dict_append(st, "account", acct);
829 840
830 xs *fd = mastoapi_date(xs_dict_get(msg, "published")); 841 const char *published = xs_dict_get(msg, "published");
842 xs *fd = NULL;
843
844 if (published)
845 fd = mastoapi_date(published);
846 else {
847 xs *p = xs_str_iso_date(0);
848 fd = mastoapi_date(p);
849 }
850
831 st = xs_dict_append(st, "created_at", fd); 851 st = xs_dict_append(st, "created_at", fd);
832 852
833 { 853 {
@@ -1024,7 +1044,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
1024 st = xs_dict_append(st, "in_reply_to_id", xs_stock(XSTYPE_NULL)); 1044 st = xs_dict_append(st, "in_reply_to_id", xs_stock(XSTYPE_NULL));
1025 st = xs_dict_append(st, "in_reply_to_account_id", xs_stock(XSTYPE_NULL)); 1045 st = xs_dict_append(st, "in_reply_to_account_id", xs_stock(XSTYPE_NULL));
1026 1046
1027 tmp = xs_dict_get(msg, "inReplyTo"); 1047 tmp = get_in_reply_to(msg);
1028 if (!xs_is_null(tmp)) { 1048 if (!xs_is_null(tmp)) {
1029 xs *irto = NULL; 1049 xs *irto = NULL;
1030 1050
@@ -1266,6 +1286,17 @@ void credentials_get(char **body, char **ctype, int *status, snac snac)
1266 acct = xs_dict_append(acct, "following_count", xs_stock(0)); 1286 acct = xs_dict_append(acct, "following_count", xs_stock(0));
1267 acct = xs_dict_append(acct, "statuses_count", xs_stock(0)); 1287 acct = xs_dict_append(acct, "statuses_count", xs_stock(0));
1268 1288
1289 /* does this user want to publish their contact metrics? */
1290 if (xs_is_true(xs_dict_get(snac.config, "show_contact_metrics"))) {
1291 xs *fwing = following_list(&snac);
1292 xs *fwers = follower_list(&snac);
1293 xs *ni = xs_number_new(xs_list_len(fwing));
1294 xs *ne = xs_number_new(xs_list_len(fwers));
1295
1296 acct = xs_dict_append(acct, "followers_count", ne);
1297 acct = xs_dict_append(acct, "following_count", ni);
1298 }
1299
1269 *body = xs_json_dumps(acct, 4); 1300 *body = xs_json_dumps(acct, 4);
1270 *ctype = "application/json"; 1301 *ctype = "application/json";
1271 *status = HTTP_STATUS_OK; 1302 *status = HTTP_STATUS_OK;
@@ -1340,6 +1371,9 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn
1340 if (!xs_match(type, POSTLIKE_OBJECT_TYPE)) 1371 if (!xs_match(type, POSTLIKE_OBJECT_TYPE))
1341 continue; 1372 continue;
1342 1373
1374 if (id && is_instance_blocked(id))
1375 continue;
1376
1343 const char *from = NULL; 1377 const char *from = NULL;
1344 if (strcmp(type, "Page") == 0) 1378 if (strcmp(type, "Page") == 0)
1345 from = xs_dict_get(msg, "audience"); 1379 from = xs_dict_get(msg, "audience");
@@ -1727,11 +1761,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1727 if (logged_in) { 1761 if (logged_in) {
1728 xs *l = notify_list(&snac1, 0, 64); 1762 xs *l = notify_list(&snac1, 0, 64);
1729 xs *out = xs_list_new(); 1763 xs *out = xs_list_new();
1730 xs_list *p = l;
1731 const xs_dict *v; 1764 const xs_dict *v;
1732 const xs_list *excl = xs_dict_get(args, "exclude_types[]"); 1765 const xs_list *excl = xs_dict_get(args, "exclude_types[]");
1766 const char *max_id = xs_dict_get(args, "max_id");
1733 1767
1734 while (xs_list_iter(&p, &v)) { 1768 xs_list_foreach(l, v) {
1735 xs *noti = notify_get(&snac1, v); 1769 xs *noti = notify_get(&snac1, v);
1736 1770
1737 if (noti == NULL) 1771 if (noti == NULL)
@@ -1740,6 +1774,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1740 const char *type = xs_dict_get(noti, "type"); 1774 const char *type = xs_dict_get(noti, "type");
1741 const char *utype = xs_dict_get(noti, "utype"); 1775 const char *utype = xs_dict_get(noti, "utype");
1742 const char *objid = xs_dict_get(noti, "objid"); 1776 const char *objid = xs_dict_get(noti, "objid");
1777 const char *id = xs_dict_get(noti, "id");
1778 xs *fid = xs_replace(id, ".", "");
1743 xs *actor = NULL; 1779 xs *actor = NULL;
1744 xs *entry = NULL; 1780 xs *entry = NULL;
1745 1781
@@ -1752,6 +1788,13 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1752 if (is_hidden(&snac1, objid)) 1788 if (is_hidden(&snac1, objid))
1753 continue; 1789 continue;
1754 1790
1791 if (max_id) {
1792 if (strcmp(fid, max_id) == 0)
1793 max_id = NULL;
1794
1795 continue;
1796 }
1797
1755 /* convert the type */ 1798 /* convert the type */
1756 if (strcmp(type, "Like") == 0 || strcmp(type, "EmojiReact") == 0) 1799 if (strcmp(type, "Like") == 0 || strcmp(type, "EmojiReact") == 0)
1757 type = "favourite"; 1800 type = "favourite";
@@ -1778,12 +1821,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1778 1821
1779 mn = xs_dict_append(mn, "type", type); 1822 mn = xs_dict_append(mn, "type", type);
1780 1823
1781 xs *id = xs_replace(xs_dict_get(noti, "id"), ".", ""); 1824 mn = xs_dict_append(mn, "id", fid);
1782 mn = xs_dict_append(mn, "id", id);
1783 1825
1784 mn = xs_dict_append(mn, "created_at", xs_dict_get(noti, "date")); 1826 mn = xs_dict_append(mn, "created_at", xs_dict_get(noti, "date"));
1785 1827
1786 xs *acct = mastoapi_account(&snac1, actor); 1828 xs *acct = mastoapi_account(&snac1, actor);
1829
1830 if (acct == NULL)
1831 continue;
1832
1787 mn = xs_dict_append(mn, "account", acct); 1833 mn = xs_dict_append(mn, "account", acct);
1788 1834
1789 if (strcmp(type, "follow") != 0 && !xs_is_null(objid)) { 1835 if (strcmp(type, "follow") != 0 && !xs_is_null(objid)) {