diff options
| -rw-r--r-- | data.c | 8 | ||||
| -rw-r--r-- | mastoapi.c | 63 | ||||
| -rw-r--r-- | snac.h | 1 |
3 files changed, 13 insertions, 59 deletions
| @@ -1944,6 +1944,12 @@ xs_val *list_maint(snac *user, const char *list, int op) | |||
| 1944 | } | 1944 | } |
| 1945 | 1945 | ||
| 1946 | 1946 | ||
| 1947 | xs_str *list_timeline_fn(snac *user, const char *list) | ||
| 1948 | { | ||
| 1949 | return xs_fmt("%s/list/%s.idx", user->basedir, list); | ||
| 1950 | } | ||
| 1951 | |||
| 1952 | |||
| 1947 | xs_list *list_timeline(snac *user, const char *list, int skip, int show) | 1953 | xs_list *list_timeline(snac *user, const char *list, int skip, int show) |
| 1948 | /* returns the timeline of a list */ | 1954 | /* returns the timeline of a list */ |
| 1949 | { | 1955 | { |
| @@ -1952,7 +1958,7 @@ xs_list *list_timeline(snac *user, const char *list, int skip, int show) | |||
| 1952 | if (!xs_is_hex(list)) | 1958 | if (!xs_is_hex(list)) |
| 1953 | return NULL; | 1959 | return NULL; |
| 1954 | 1960 | ||
| 1955 | xs *fn = xs_fmt("%s/list/%s.idx", user->basedir, list); | 1961 | xs *fn = list_timeline_fn(user, list); |
| 1956 | 1962 | ||
| 1957 | if (mtime(fn) > 0.0) | 1963 | if (mtime(fn) > 0.0) |
| 1958 | l = index_list_desc(fn, skip, show); | 1964 | l = index_list_desc(fn, skip, show); |
| @@ -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"; |
| @@ -185,6 +185,7 @@ xs_str *tag_fn(const char *tag); | |||
| 185 | xs_list *tag_search(const char *tag, int skip, int show); | 185 | xs_list *tag_search(const char *tag, int skip, int show); |
| 186 | 186 | ||
| 187 | xs_val *list_maint(snac *user, const char *list, int op); | 187 | xs_val *list_maint(snac *user, const char *list, int op); |
| 188 | xs_str *list_timeline_fn(snac *user, const char *list); | ||
| 188 | xs_list *list_timeline(snac *user, const char *list, int skip, int show); | 189 | xs_list *list_timeline(snac *user, const char *list, int skip, int show); |
| 189 | xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int op); | 190 | xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int op); |
| 190 | void list_distribute(snac *user, const char *who, const xs_dict *post); | 191 | void list_distribute(snac *user, const char *who, const xs_dict *post); |