|
@@ -1261,9 +1261,20 @@ void credentials_get(char **body, char **ctype, int *status, snac snac)
|
|
|
}
|
|
|
|
|
|
|
|
|
-xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index)
|
|
|
+xs_list *mastoapi_timeline(snac *user, const xs_dict *args, int skip, const char *index_fn)
|
|
|
{
|
|
|
- xs_list *out = xs_list_new();
|
|
|
+ xs_list *out = xs_list_new();
|
|
|
+ FILE *f;
|
|
|
+ char md5[MD5_HEX_SIZE];
|
|
|
+
|
|
|
+ if (dbglevel) {
|
|
|
+ xs *js = xs_json_dumps(args, 0);
|
|
|
+ srv_log(xs_fmt("mastoapi_timeline args: %s", js));
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((f = fopen(index_fn, "r")) == NULL)
|
|
|
+ return out;
|
|
|
+
|
|
|
const char *max_id = xs_dict_get(args, "max_id");
|
|
|
const char *since_id = xs_dict_get(args, "since_id");
|
|
|
const char *min_id = xs_dict_get(args, "min_id");
|
|
@@ -1277,85 +1288,86 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index)
|
|
|
if (limit == 0)
|
|
|
limit = 20;
|
|
|
|
|
|
- xs *timeline = timeline_simple_list(user, index, 0, 2048);
|
|
|
+ if (index_desc_first(f, md5, skip)) {
|
|
|
+ do {
|
|
|
+ xs *msg = NULL;
|
|
|
|
|
|
- xs_list *p = timeline;
|
|
|
- const xs_str *v;
|
|
|
+
|
|
|
+ if (max_id) {
|
|
|
+ if (strcmp(md5, MID_TO_MD5(max_id)) == 0)
|
|
|
+ max_id = NULL;
|
|
|
|
|
|
- while (xs_list_iter(&p, &v) && cnt < limit) {
|
|
|
- xs *msg = NULL;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- if (max_id) {
|
|
|
- if (strcmp(v, MID_TO_MD5(max_id)) == 0)
|
|
|
- max_id = NULL;
|
|
|
+
|
|
|
+ if (since_id) {
|
|
|
+ if (strcmp(md5, MID_TO_MD5(since_id)) == 0)
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- continue;
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+ if (min_id) {
|
|
|
+ if (strcmp(md5, MID_TO_MD5(min_id)) == 0)
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- if (since_id) {
|
|
|
- if (strcmp(v, MID_TO_MD5(since_id)) == 0)
|
|
|
- break;
|
|
|
- }
|
|
|
+
|
|
|
+ if (!valid_status(timeline_get_by_md5(user, md5, &msg)))
|
|
|
+ continue;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- if (min_id) {
|
|
|
- if (strcmp(v, MID_TO_MD5(min_id)) == 0)
|
|
|
- break;
|
|
|
- }
|
|
|
+
|
|
|
+ const char *id = xs_dict_get(msg, "id");
|
|
|
+ const char *type = xs_dict_get(msg, "type");
|
|
|
+ if (!xs_match(type, POSTLIKE_OBJECT_TYPE))
|
|
|
+ continue;
|
|
|
|
|
|
-
|
|
|
- if (!valid_status(timeline_get_by_md5(user, v, &msg)))
|
|
|
- continue;
|
|
|
+ const char *from = NULL;
|
|
|
+ if (strcmp(type, "Page") == 0)
|
|
|
+ from = xs_dict_get(msg, "audience");
|
|
|
|
|
|
-
|
|
|
- const char *id = xs_dict_get(msg, "id");
|
|
|
- const char *type = xs_dict_get(msg, "type");
|
|
|
- if (!xs_match(type, POSTLIKE_OBJECT_TYPE))
|
|
|
- continue;
|
|
|
+ if (from == NULL)
|
|
|
+ from = get_atto(msg);
|
|
|
|
|
|
- const char *from = NULL;
|
|
|
- if (strcmp(type, "Page") == 0)
|
|
|
- from = xs_dict_get(msg, "audience");
|
|
|
+ if (from == NULL)
|
|
|
+ continue;
|
|
|
|
|
|
- if (from == NULL)
|
|
|
- from = get_atto(msg);
|
|
|
+
|
|
|
+ if (strcmp(from, user->actor) && !following_check(user, from)) {
|
|
|
+
|
|
|
+ xs *idx = object_announces(id);
|
|
|
|
|
|
- if (from == NULL)
|
|
|
- continue;
|
|
|
+ if (xs_list_len(idx) == 0)
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
- if (strcmp(from, user->actor) && !following_check(user, from)) {
|
|
|
-
|
|
|
- xs *idx = object_announces(id);
|
|
|
+
|
|
|
+ if (is_muted(user, from))
|
|
|
+ continue;
|
|
|
|
|
|
- if (xs_list_len(idx) == 0)
|
|
|
+
|
|
|
+ if (is_hidden(user, id))
|
|
|
continue;
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- if (is_muted(user, from))
|
|
|
- continue;
|
|
|
+
|
|
|
+ it's a poll vote, so discard it */
|
|
|
+ if (!xs_is_null(xs_dict_get(msg, "name")) && !xs_match(type, "Page|Video"))
|
|
|
+ continue;
|
|
|
|
|
|
-
|
|
|
- if (is_hidden(user, id))
|
|
|
- continue;
|
|
|
+
|
|
|
+ xs *st = mastoapi_status(user, msg);
|
|
|
|
|
|
-
|
|
|
- it's a poll vote, so discard it */
|
|
|
- if (!xs_is_null(xs_dict_get(msg, "name")) && !xs_match(type, "Page|Video"))
|
|
|
- continue;
|
|
|
+ if (st != NULL)
|
|
|
+ out = xs_list_append(out, st);
|
|
|
|
|
|
-
|
|
|
- xs *st = mastoapi_status(user, msg);
|
|
|
+ cnt++;
|
|
|
+ } while (cnt < limit && index_desc_next(f, md5));
|
|
|
+ }
|
|
|
|
|
|
- if (st != NULL)
|
|
|
- out = xs_list_append(out, st);
|
|
|
+ fclose(f);
|
|
|
|
|
|
- cnt++;
|
|
|
- }
|
|
|
+ srv_debug(1, xs_fmt("mastoapi_timeline: %d %d", cnt, xs_list_len(out)));
|
|
|
|
|
|
return out;
|
|
|
}
|
|
@@ -1619,7 +1631,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|
|
if (strcmp(cmd, "/v1/timelines/home") == 0) {
|
|
|
|
|
|
if (logged_in) {
|
|
|
- xs *out = mastoapi_timeline(&snac1, args, "private");
|
|
|
+ xs *ifn = user_index_fn(&snac1, "private");
|
|
|
+ xs *out = mastoapi_timeline(&snac1, args, 0, ifn);
|
|
|
|
|
|
*body = xs_json_dumps(out, 4);
|
|
|
*ctype = "application/json";
|