The outbox returns now some entries.

This commit is contained in:
default 2022-09-28 04:48:23 +02:00
parent 94ef803701
commit 32661d2be7
3 changed files with 37 additions and 6 deletions

View file

@ -761,10 +761,24 @@ int activitypub_get_handler(d_char *req, char *q_path,
else else
if (strcmp(p_path, "outbox") == 0) { if (strcmp(p_path, "outbox") == 0) {
xs *id = xs_fmt("%s/outbox", snac.actor); xs *id = xs_fmt("%s/outbox", snac.actor);
xs *elems = local_list(&snac, 40);
xs *list = xs_list_new();
msg = msg_collection(&snac, id); msg = msg_collection(&snac, id);
char *p, *v;
p = elems;
while (xs_list_iter(&p, &v)) {
xs *i = timeline_get(&snac, v);
char *type = xs_dict_get(i, "type");
char *id = xs_dict_get(i, "id");
if (type && id && strcmp(type, "Note") == 0 && xs_startswith(id, snac.actor))
list = xs_list_append(list, i);
}
/* replace the 'orderedItems' with the latest posts */ /* replace the 'orderedItems' with the latest posts */
/* ... */ msg = xs_dict_set(msg, "orderedItems", list);
msg = xs_dict_set(msg, "totalItems", xs_number_new(xs_list_len(list)));
} }
else else
if (strcmp(p_path, "followers") == 0 || strcmp(p_path, "following") == 0) { if (strcmp(p_path, "followers") == 0 || strcmp(p_path, "following") == 0) {

23
data.c
View file

@ -357,16 +357,19 @@ d_char *timeline_get(snac *snac, char *fn)
} }
d_char *timeline_list(snac *snac) d_char *_timeline_list(snac *snac, char *directory, int max)
/* returns a list of the timeline filenames */ /* returns a list of the timeline filenames */
{ {
d_char *list; d_char *list;
xs *spec = xs_fmt("%s/timeline/" "*.json", snac->basedir); xs *spec = xs_fmt("%s/%s/" "*.json", snac->basedir, directory);
glob_t globbuf; glob_t globbuf;
int max; int c_max;
/* maximum number of items in the timeline */ /* maximum number of items in the timeline */
max = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries")); c_max = xs_number_get(xs_dict_get(srv_config, "max_timeline_entries"));
if (max > c_max)
max = c_max;
list = xs_list_new(); list = xs_list_new();
@ -390,6 +393,18 @@ d_char *timeline_list(snac *snac)
} }
d_char *timeline_list(snac *snac, int max)
{
return _timeline_list(snac, "timeline", max);
}
d_char *local_list(snac *snac, int max)
{
return _timeline_list(snac, "local", max);
}
d_char *_timeline_new_fn(snac *snac, char *id) d_char *_timeline_new_fn(snac *snac, char *id)
/* creates a new filename */ /* creates a new filename */
{ {

4
snac.h
View file

@ -59,10 +59,12 @@ int timeline_here(snac *snac, char *id);
d_char *timeline_find(snac *snac, char *id); d_char *timeline_find(snac *snac, char *id);
void timeline_del(snac *snac, char *id); void timeline_del(snac *snac, char *id);
d_char *timeline_get(snac *snac, char *fn); d_char *timeline_get(snac *snac, char *fn);
d_char *timeline_list(snac *snac); d_char *timeline_list(snac *snac, int max);
int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer); int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer);
void timeline_admire(snac *snac, char *id, char *admirer, int like); void timeline_admire(snac *snac, char *id, char *admirer, int like);
d_char *local_list(snac *snac, int max);
int following_add(snac *snac, char *actor, char *msg); int following_add(snac *snac, char *actor, char *msg);
int following_del(snac *snac, char *actor); int following_del(snac *snac, char *actor);
int following_check(snac *snac, char *actor); int following_check(snac *snac, char *actor);