Slon/Api/V1/Timelines: Implement public timeline
This commit is contained in:
parent
66074a5472
commit
d6c1b8dbfd
3 changed files with 90 additions and 6 deletions
|
@ -116,7 +116,9 @@ U0 @slon_api_v1_statuses_post(SlonHttpSession* session)
|
||||||
|
|
||||||
if (!idempotency_key_already_seen) {
|
if (!idempotency_key_already_seen) {
|
||||||
db->o("statuses")->a(account_id)->append(Json.CreateItem(status, JSON_OBJECT));
|
db->o("statuses")->a(account_id)->append(Json.CreateItem(status, JSON_OBJECT));
|
||||||
|
db->o("timelines")->a("public")->append(Json.CreateItem(status, JSON_OBJECT));
|
||||||
@slon_db_save_statuses_to_disk;
|
@slon_db_save_statuses_to_disk;
|
||||||
|
@slon_db_save_timelines_to_disk;
|
||||||
@slon_db_instance_increment_status_count;
|
@slon_db_instance_increment_status_count;
|
||||||
@slon_db_save_instance_to_disk;
|
@slon_db_save_instance_to_disk;
|
||||||
if (@slon_api_status_create_fedi) {
|
if (@slon_api_status_create_fedi) {
|
||||||
|
|
|
@ -79,20 +79,97 @@ U0 @slon_api_v1_timelines_home(SlonHttpSession* session, U8* account_id)
|
||||||
Json.Delete(statuses);
|
Json.Delete(statuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
U0 @slon_api_v1_timelines_public(SlonHttpSession* session)
|
||||||
|
{
|
||||||
|
SLON_SCRATCH_BUFFER_AND_REQUEST_JSON
|
||||||
|
no_warn scratch_buffer;
|
||||||
|
|
||||||
|
// Return the Public timeline
|
||||||
|
JsonArray* status_array = db->o("timelines")->a("public");
|
||||||
|
if (!status_array) {
|
||||||
|
session->send(SLON_EMPTY_JSON_ARRAY);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
I64 count = 0;
|
||||||
|
|
||||||
|
// FILTERS
|
||||||
|
I64 limit = 20; // default
|
||||||
|
U64 max_id = 0;
|
||||||
|
U64 min_id = 0;
|
||||||
|
Bool only_media = request_json->@("only_media");
|
||||||
|
Bool exclude_replies = request_json->@("exclude_replies");
|
||||||
|
Bool exclude_reblogs = request_json->@("exclude_reblogs");
|
||||||
|
no_warn exclude_reblogs, exclude_replies;
|
||||||
|
Bool pinned = request_json->@("pinned");
|
||||||
|
// FIXME: Implement "only_media", "exclude_reblogs", "tagged"
|
||||||
|
|
||||||
|
Bool exclude_status = FALSE;
|
||||||
|
U64 status_id = 0;
|
||||||
|
|
||||||
|
if (StrLen(request_json->@("limit")) > 0) {
|
||||||
|
// 40 = maximum per https://docs.joinmastodon.org/methods/accounts/#statuses
|
||||||
|
limit = MinI64(40, Str2I64(request_json->@("limit")));
|
||||||
|
}
|
||||||
|
if (StrLen(request_json->@("max_id")) > 0) {
|
||||||
|
max_id = Str2I64(request_json->@("max_id"));
|
||||||
|
}
|
||||||
|
if (StrLen(request_json->@("min_id")) > 0) {
|
||||||
|
min_id = Str2I64(request_json->@("min_id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArray* statuses = Json.CreateArray();
|
||||||
|
JsonObject* status = NULL;
|
||||||
|
|
||||||
|
if (status_array && status_array->length) {
|
||||||
|
I64 i;
|
||||||
|
for (i = status_array->length - 1; i > -1; i--) {
|
||||||
|
status = status_array->o(i);
|
||||||
|
status_id = Str2I64(status->@("id"));
|
||||||
|
exclude_status = FALSE;
|
||||||
|
if (status->@("deleted")) {
|
||||||
|
exclude_status = TRUE;
|
||||||
|
}
|
||||||
|
if (max_id > 0 && status_id >= max_id) {
|
||||||
|
exclude_status = TRUE;
|
||||||
|
}
|
||||||
|
if (min_id > 0 && status_id <= min_id) {
|
||||||
|
exclude_status = TRUE;
|
||||||
|
}
|
||||||
|
if (only_media && !Json.Get(status, "media_attachments")(JsonArray*)->length) {
|
||||||
|
exclude_status = TRUE;
|
||||||
|
}
|
||||||
|
if (pinned && !status->@("pinned")) {
|
||||||
|
exclude_status = TRUE;
|
||||||
|
}
|
||||||
|
if (!exclude_status) {
|
||||||
|
statuses->append(Json.CreateItem(status, JSON_OBJECT));
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
if (limit > 0 && count >= limit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
session->send(statuses);
|
||||||
|
|
||||||
|
Json.Delete(statuses);
|
||||||
|
}
|
||||||
|
|
||||||
U0 @slon_api_v1_timelines_get(SlonHttpSession* session)
|
U0 @slon_api_v1_timelines_get(SlonHttpSession* session)
|
||||||
{
|
{
|
||||||
|
U8* timeline = session->path(3);
|
||||||
|
if (!StrICmp("public", timeline)) {
|
||||||
|
@slon_api_v1_timelines_public(session);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (@slon_api_authorized(session)) {
|
if (@slon_api_authorized(session)) {
|
||||||
SLON_AUTH_ACCOUNT_ID
|
SLON_AUTH_ACCOUNT_ID
|
||||||
|
|
||||||
if (session->path_count() < 4) {
|
if (session->path_count() < 4) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
U8* timeline = session->path(3);
|
|
||||||
if (!StrICmp("public", timeline)) {
|
|
||||||
// FIXME: Implement this
|
|
||||||
session->send(SLON_EMPTY_JSON_ARRAY);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!StrICmp("tag", timeline)) {
|
if (!StrICmp("tag", timeline)) {
|
||||||
// FIXME: Implement this
|
// FIXME: Implement this
|
||||||
session->send(SLON_EMPTY_JSON_ARRAY);
|
session->send(SLON_EMPTY_JSON_ARRAY);
|
||||||
|
|
|
@ -126,6 +126,8 @@ U0 @slon_db_load_timelines_from_disk()
|
||||||
}
|
}
|
||||||
DirTreeDel(files);
|
DirTreeDel(files);
|
||||||
timelines->set("home", home_statuses, JSON_OBJECT);
|
timelines->set("home", home_statuses, JSON_OBJECT);
|
||||||
|
StrPrint(scratch_buffer, "%s/timelines/public.json", SLON_DB_PATH);
|
||||||
|
timelines->set("public", Json.ParseFile(scratch_buffer), JSON_ARRAY);
|
||||||
|
|
||||||
db->set("timelines", timelines, JSON_OBJECT);
|
db->set("timelines", timelines, JSON_OBJECT);
|
||||||
}
|
}
|
||||||
|
@ -214,6 +216,8 @@ U0 @slon_db_save_timelines_to_disk()
|
||||||
Json.DumpToFile(scratch_buffer, key->value);
|
Json.DumpToFile(scratch_buffer, key->value);
|
||||||
key = key->next;
|
key = key->next;
|
||||||
}
|
}
|
||||||
|
StrPrint(scratch_buffer, "%s/timelines/public.json", SLON_DB_PATH);
|
||||||
|
Json.DumpToFile(scratch_buffer, db->o("timelines")->a("public"));
|
||||||
}
|
}
|
||||||
|
|
||||||
U0 @slon_db_save_to_disk()
|
U0 @slon_db_save_to_disk()
|
||||||
|
@ -245,6 +249,7 @@ U0 @slon_db_load_from_defaults()
|
||||||
db->set("statuses", Json.CreateObject(), JSON_OBJECT);
|
db->set("statuses", Json.CreateObject(), JSON_OBJECT);
|
||||||
db->set("timelines", Json.CreateObject(), JSON_OBJECT);
|
db->set("timelines", Json.CreateObject(), JSON_OBJECT);
|
||||||
db->o("timelines")->set("home", Json.CreateObject(), JSON_OBJECT);
|
db->o("timelines")->set("home", Json.CreateObject(), JSON_OBJECT);
|
||||||
|
db->o("timelines")->set("public", Json.CreateArray(), JSON_ARRAY);
|
||||||
JsonObject* oauth = Json.CreateObject();
|
JsonObject* oauth = Json.CreateObject();
|
||||||
oauth->set("codes", Json.CreateObject(), JSON_OBJECT);
|
oauth->set("codes", Json.CreateObject(), JSON_OBJECT);
|
||||||
oauth->set("requests", Json.CreateObject(), JSON_OBJECT);
|
oauth->set("requests", Json.CreateObject(), JSON_OBJECT);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue