mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 05:15:04 +00:00
Some instance timeline work.
This commit is contained in:
parent
6b632e1ee9
commit
ede4d6f2dc
3 changed files with 38 additions and 35 deletions
13
data.c
13
data.c
|
@ -1046,7 +1046,7 @@ xs_list *timeline_top_level(snac *snac, xs_list *list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
d_char *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show)
|
xs_list *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show)
|
||||||
/* returns a timeline (with all entries) */
|
/* returns a timeline (with all entries) */
|
||||||
{
|
{
|
||||||
int c_max;
|
int c_max;
|
||||||
|
@ -1064,7 +1064,7 @@ d_char *timeline_simple_list(snac *snac, const char *idx_name, int skip, int sho
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
d_char *timeline_list(snac *snac, const char *idx_name, int skip, int show)
|
xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show)
|
||||||
/* returns a timeline (only top level entries) */
|
/* returns a timeline (only top level entries) */
|
||||||
{
|
{
|
||||||
xs *list = timeline_simple_list(snac, idx_name, skip, show);
|
xs *list = timeline_simple_list(snac, idx_name, skip, show);
|
||||||
|
@ -1073,6 +1073,15 @@ d_char *timeline_list(snac *snac, const char *idx_name, int skip, int show)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xs_list *timeline_instance_list(int skip, int show)
|
||||||
|
/* returns the timeline for the full instance */
|
||||||
|
{
|
||||||
|
xs *idx = xs_fmt("%s/public.idx", srv_basedir);
|
||||||
|
|
||||||
|
return index_list_desc(idx, skip, show);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** following **/
|
/** following **/
|
||||||
|
|
||||||
/* this needs special treatment and cannot use the object db as is,
|
/* this needs special treatment and cannot use the object db as is,
|
||||||
|
|
52
mastoapi.c
52
mastoapi.c
|
@ -1038,9 +1038,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
||||||
if (strcmp(cmd, "/v1/timelines/public") == 0) {
|
if (strcmp(cmd, "/v1/timelines/public") == 0) {
|
||||||
/* the public timeline (public timelines for all users) */
|
/* the public timeline (public timelines for all users) */
|
||||||
|
|
||||||
/* this is an ugly kludge: first users in the list get all the fame */
|
const char *limit_s = xs_dict_get(args, "limit");
|
||||||
|
|
||||||
const char *limit_s = xs_dict_get(args, "limit");
|
|
||||||
int limit = 0;
|
int limit = 0;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|
||||||
|
@ -1050,44 +1048,40 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
||||||
if (limit == 0)
|
if (limit == 0)
|
||||||
limit = 20;
|
limit = 20;
|
||||||
|
|
||||||
xs *out = xs_list_new();
|
xs *timeline = timeline_instance_list(0, limit);
|
||||||
xs *users = user_list();
|
xs *out = xs_list_new();
|
||||||
xs_list *p = users;
|
xs_list *p = timeline;
|
||||||
xs_str *uid;
|
xs_str *md5;
|
||||||
|
|
||||||
while (xs_list_iter(&p, &uid) && cnt < limit) {
|
while (xs_list_iter(&p, &md5) && cnt < limit) {
|
||||||
snac user;
|
xs *msg = NULL;
|
||||||
|
|
||||||
if (user_open(&user, uid)) {
|
/* get the entry */
|
||||||
xs *timeline = timeline_simple_list(&user, "public", 0, 4);
|
if (!valid_status(object_get_by_md5(md5, &msg)))
|
||||||
xs_list *p2 = timeline;
|
continue;
|
||||||
xs_str *v;
|
|
||||||
|
|
||||||
while (xs_list_iter(&p2, &v) && cnt < limit) {
|
/* discard non-Notes */
|
||||||
xs *msg = NULL;
|
if (strcmp(xs_dict_get(msg, "type"), "Note") != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
/* get the entry */
|
/* get the uid */
|
||||||
if (!valid_status(timeline_get_by_md5(&user, v, &msg)))
|
xs *l = xs_split(xs_dict_get(msg, "attributedTo"), "/");
|
||||||
continue;
|
const char *uid = xs_list_get(l, -1);
|
||||||
|
|
||||||
/* discard non-Notes */
|
if (!xs_is_null(uid)) {
|
||||||
if (strcmp(xs_dict_get(msg, "type"), "Note") != 0)
|
snac user;
|
||||||
continue;
|
|
||||||
|
|
||||||
/* discard entries not by this user */
|
|
||||||
if (!xs_startswith(xs_dict_get(msg, "id"), user.actor))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
|
if (user_open(&user, uid)) {
|
||||||
/* convert the Note into a Mastodon status */
|
/* convert the Note into a Mastodon status */
|
||||||
xs *st = mastoapi_status(&user, msg);
|
xs *st = mastoapi_status(&user, msg);
|
||||||
|
|
||||||
if (st != NULL) {
|
if (st != NULL)
|
||||||
out = xs_list_append(out, st);
|
out = xs_list_append(out, st);
|
||||||
cnt++;
|
|
||||||
}
|
user_free(&user);
|
||||||
}
|
}
|
||||||
|
|
||||||
user_free(&user);
|
cnt++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
snac.h
8
snac.h
|
@ -105,14 +105,14 @@ int timeline_touch(snac *snac);
|
||||||
int timeline_here(snac *snac, const char *md5);
|
int timeline_here(snac *snac, const char *md5);
|
||||||
int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg);
|
int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg);
|
||||||
int timeline_del(snac *snac, char *id);
|
int timeline_del(snac *snac, char *id);
|
||||||
d_char *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show);
|
xs_list *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show);
|
||||||
d_char *timeline_list(snac *snac, const char *idx_name, int skip, int show);
|
xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show);
|
||||||
int timeline_add(snac *snac, char *id, char *o_msg);
|
int timeline_add(snac *snac, char *id, char *o_msg);
|
||||||
void timeline_admire(snac *snac, char *id, char *admirer, int like);
|
void timeline_admire(snac *snac, char *id, char *admirer, int like);
|
||||||
|
|
||||||
xs_list *timeline_top_level(snac *snac, xs_list *list);
|
xs_list *timeline_top_level(snac *snac, xs_list *list);
|
||||||
|
xs_list *local_list(snac *snac, int max);
|
||||||
d_char *local_list(snac *snac, int max);
|
xs_list *timeline_instance_list(int skip, int show);
|
||||||
|
|
||||||
int following_add(snac *snac, const char *actor, const xs_dict *msg);
|
int following_add(snac *snac, const char *actor, const xs_dict *msg);
|
||||||
int following_del(snac *snac, const char *actor);
|
int following_del(snac *snac, const char *actor);
|
||||||
|
|
Loading…
Reference in a new issue