diff options
| author | 2024-04-29 10:15:04 +0200 | |
|---|---|---|
| committer | 2024-04-29 10:15:04 +0200 | |
| commit | f1221808a858b0d205f3acdb028d58d362ef22e6 (patch) | |
| tree | afa34b04e1b66266744b46054f86f3432b5bb1a3 | |
| parent | New function list_distribute(). (diff) | |
| download | snac2-f1221808a858b0d205f3acdb028d58d362ef22e6.tar.gz snac2-f1221808a858b0d205f3acdb028d58d362ef22e6.tar.xz snac2-f1221808a858b0d205f3acdb028d58d362ef22e6.zip | |
More work in lists.
| -rw-r--r-- | data.c | 13 | ||||
| -rw-r--r-- | mastoapi.c | 71 |
2 files changed, 83 insertions, 1 deletions
| @@ -1855,6 +1855,15 @@ xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op | |||
| 1855 | case 2: /** delete actor from list **/ | 1855 | case 2: /** delete actor from list **/ |
| 1856 | if (actor_md5 != NULL) | 1856 | if (actor_md5 != NULL) |
| 1857 | index_del_md5(fn, actor_md5); | 1857 | index_del_md5(fn, actor_md5); |
| 1858 | |||
| 1859 | break; | ||
| 1860 | |||
| 1861 | case 3: /** list timeline **/ | ||
| 1862 | fn = xs_replace_i(fn, ".lst", ".idx"); | ||
| 1863 | |||
| 1864 | l = index_list_desc(fn, 0, 2048); | ||
| 1865 | |||
| 1866 | break; | ||
| 1858 | } | 1867 | } |
| 1859 | 1868 | ||
| 1860 | return l; | 1869 | return l; |
| @@ -1880,7 +1889,9 @@ void list_distribute(snac *user, const xs_dict *post) | |||
| 1880 | if (index_in_md5(v, a_md5)) { | 1889 | if (index_in_md5(v, a_md5)) { |
| 1881 | /* it is; add post md5 to its timeline */ | 1890 | /* it is; add post md5 to its timeline */ |
| 1882 | xs *idx = xs_replace(v, ".lst", ".idx"); | 1891 | xs *idx = xs_replace(v, ".lst", ".idx"); |
| 1883 | index_add(idx, i_md5); | 1892 | index_add_md5(idx, i_md5); |
| 1893 | |||
| 1894 | snac_debug(user, 1, xs_fmt("listed post %s in %s", id, idx)); | ||
| 1884 | } | 1895 | } |
| 1885 | } | 1896 | } |
| 1886 | } | 1897 | } |
| @@ -1647,6 +1647,77 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1647 | status = 200; | 1647 | status = 200; |
| 1648 | } | 1648 | } |
| 1649 | else | 1649 | else |
| 1650 | if (xs_startswith(cmd, "/v1/timelines/list/")) { /** **/ | ||
| 1651 | /* get the list id */ | ||
| 1652 | if (logged_in) { | ||
| 1653 | xs *l = xs_split(cmd, "/"); | ||
| 1654 | char *list = xs_list_get(l, -1); | ||
| 1655 | |||
| 1656 | xs *timeline = list_content(&snac1, list, NULL, 3); | ||
| 1657 | xs *out = xs_list_new(); | ||
| 1658 | int c = 0; | ||
| 1659 | char *md5; | ||
| 1660 | |||
| 1661 | while (xs_list_next(timeline, &md5, &c)) { | ||
| 1662 | xs *msg = NULL; | ||
| 1663 | |||
| 1664 | /* get the entry */ | ||
| 1665 | if (!valid_status(timeline_get_by_md5(&snac1, md5, &msg))) | ||
| 1666 | continue; | ||
| 1667 | |||
| 1668 | /* discard non-Notes */ | ||
| 1669 | const char *id = xs_dict_get(msg, "id"); | ||
| 1670 | const char *type = xs_dict_get(msg, "type"); | ||
| 1671 | if (!xs_match(type, "Note|Question|Page|Article|Video")) | ||
| 1672 | continue; | ||
| 1673 | |||
| 1674 | const char *from = NULL; | ||
| 1675 | if (strcmp(type, "Page") == 0) | ||
| 1676 | from = xs_dict_get(msg, "audience"); | ||
| 1677 | |||
| 1678 | if (from == NULL) | ||
| 1679 | from = get_atto(msg); | ||
| 1680 | |||
| 1681 | if (from == NULL) | ||
| 1682 | continue; | ||
| 1683 | |||
| 1684 | /* is this message from a person we don't follow? */ | ||
| 1685 | if (strcmp(from, snac1.actor) && !following_check(&snac1, from)) { | ||
| 1686 | /* discard if it was not boosted */ | ||
| 1687 | xs *idx = object_announces(id); | ||
| 1688 | |||
| 1689 | if (xs_list_len(idx) == 0) | ||
| 1690 | continue; | ||
| 1691 | } | ||
| 1692 | |||
| 1693 | /* discard notes from muted morons */ | ||
| 1694 | if (is_muted(&snac1, from)) | ||
| 1695 | continue; | ||
| 1696 | |||
| 1697 | /* discard hidden notes */ | ||
| 1698 | if (is_hidden(&snac1, id)) | ||
| 1699 | continue; | ||
| 1700 | |||
| 1701 | /* if it has a name and it's not a Page or a Video, | ||
| 1702 | it's a poll vote, so discard it */ | ||
| 1703 | if (!xs_is_null(xs_dict_get(msg, "name")) && !xs_match(type, "Page|Video")) | ||
| 1704 | continue; | ||
| 1705 | |||
| 1706 | /* convert the Note into a Mastodon status */ | ||
| 1707 | xs *st = mastoapi_status(&snac1, msg); | ||
| 1708 | |||
| 1709 | if (st != NULL) | ||
| 1710 | out = xs_list_append(out, st); | ||
| 1711 | } | ||
| 1712 | |||
| 1713 | *body = xs_json_dumps(out, 4); | ||
| 1714 | *ctype = "application/json"; | ||
| 1715 | status = 200; | ||
| 1716 | } | ||
| 1717 | else | ||
| 1718 | status = 421; | ||
| 1719 | } | ||
| 1720 | else | ||
| 1650 | if (strcmp(cmd, "/v1/conversations") == 0) { /** **/ | 1721 | if (strcmp(cmd, "/v1/conversations") == 0) { /** **/ |
| 1651 | /* TBD */ | 1722 | /* TBD */ |
| 1652 | *body = xs_dup("[]"); | 1723 | *body = xs_dup("[]"); |