More work in lists.

This commit is contained in:
default 2024-04-29 10:15:04 +02:00
parent 7f322302e5
commit f1221808a8
2 changed files with 83 additions and 1 deletions

13
data.c
View file

@ -1855,6 +1855,15 @@ xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op
case 2: /** delete actor from list **/ case 2: /** delete actor from list **/
if (actor_md5 != NULL) if (actor_md5 != NULL)
index_del_md5(fn, actor_md5); index_del_md5(fn, actor_md5);
break;
case 3: /** list timeline **/
fn = xs_replace_i(fn, ".lst", ".idx");
l = index_list_desc(fn, 0, 2048);
break;
} }
return l; return l;
@ -1880,7 +1889,9 @@ void list_distribute(snac *user, const xs_dict *post)
if (index_in_md5(v, a_md5)) { if (index_in_md5(v, a_md5)) {
/* it is; add post md5 to its timeline */ /* it is; add post md5 to its timeline */
xs *idx = xs_replace(v, ".lst", ".idx"); xs *idx = xs_replace(v, ".lst", ".idx");
index_add(idx, i_md5); index_add_md5(idx, i_md5);
snac_debug(user, 1, xs_fmt("listed post %s in %s", id, idx));
} }
} }
} }

View file

@ -1647,6 +1647,77 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
status = 200; status = 200;
} }
else else
if (xs_startswith(cmd, "/v1/timelines/list/")) { /** **/
/* get the list id */
if (logged_in) {
xs *l = xs_split(cmd, "/");
char *list = xs_list_get(l, -1);
xs *timeline = list_content(&snac1, list, NULL, 3);
xs *out = xs_list_new();
int c = 0;
char *md5;
while (xs_list_next(timeline, &md5, &c)) {
xs *msg = NULL;
/* get the entry */
if (!valid_status(timeline_get_by_md5(&snac1, md5, &msg)))
continue;
/* discard non-Notes */
const char *id = xs_dict_get(msg, "id");
const char *type = xs_dict_get(msg, "type");
if (!xs_match(type, "Note|Question|Page|Article|Video"))
continue;
const char *from = NULL;
if (strcmp(type, "Page") == 0)
from = xs_dict_get(msg, "audience");
if (from == NULL)
from = get_atto(msg);
if (from == NULL)
continue;
/* is this message from a person we don't follow? */
if (strcmp(from, snac1.actor) && !following_check(&snac1, from)) {
/* discard if it was not boosted */
xs *idx = object_announces(id);
if (xs_list_len(idx) == 0)
continue;
}
/* discard notes from muted morons */
if (is_muted(&snac1, from))
continue;
/* discard hidden notes */
if (is_hidden(&snac1, id))
continue;
/* if it has a name and it's not a Page or a Video,
it's a poll vote, so discard it */
if (!xs_is_null(xs_dict_get(msg, "name")) && !xs_match(type, "Page|Video"))
continue;
/* convert the Note into a Mastodon status */
xs *st = mastoapi_status(&snac1, msg);
if (st != NULL)
out = xs_list_append(out, st);
}
*body = xs_json_dumps(out, 4);
*ctype = "application/json";
status = 200;
}
else
status = 421;
}
else
if (strcmp(cmd, "/v1/conversations") == 0) { /** **/ if (strcmp(cmd, "/v1/conversations") == 0) { /** **/
/* TBD */ /* TBD */
*body = xs_dup("[]"); *body = xs_dup("[]");