snac2

Fork of https://codeberg.org/grunfink/snac2
git clone https://git.inz.fi/snac2
Log | Files | Refs | README | LICENSE

commit 08de4913955c6a4a31c13f72fbce2601bed215ba
parent 54520f0411658ae37d6115d69c056dd1af3b7fb9
Author: default <nobody@localhost>
Date:   Thu, 29 Aug 2024 08:30:09 +0200

mastoapi: added bookmark list.

Diffstat:
Mdata.c | 14+++++++++++++-
Mmastoapi.c | 18++++++++++++++----
Msnac.h | 1+
3 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/data.c b/data.c @@ -1026,12 +1026,18 @@ xs_str *object_user_cache_fn(snac *user, const char *id, const char *cachedir) } +xs_str *object_user_cache_index_fn(snac *user, const char *cachedir) +{ + return xs_fmt("%s/%s.idx", user->basedir, cachedir); +} + + int _object_user_cache(snac *user, const char *id, const char *cachedir, int del) /* adds or deletes from a user cache */ { xs *ofn = _object_fn(id); xs *cfn = object_user_cache_fn(user, id, cachedir); - xs *idx = xs_fmt("%s/%s.idx", user->basedir, cachedir); + xs *idx = object_user_cache_index_fn(user, cachedir); int ret; if (del) { @@ -1590,6 +1596,12 @@ xs_list *bookmark_list(snac *user) } +xs_str *bookmark_index_fn(snac *user) +{ + return object_user_cache_index_fn(user, "bookmark"); +} + + /** pinning **/ int is_pinned(snac *user, const char *id) diff --git a/mastoapi.c b/mastoapi.c @@ -1822,10 +1822,16 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, } else if (strcmp(cmd, "/v1/bookmarks") == 0) { /** **/ - /* snac does not support bookmarks */ - *body = xs_dup("[]"); - *ctype = "application/json"; - status = HTTP_STATUS_OK; + if (logged_in) { + xs *ifn = bookmark_index_fn(&snac1); + xs *out = mastoapi_timeline(&snac1, args, ifn); + + *body = xs_json_dumps(out, 4); + *ctype = "application/json"; + status = HTTP_STATUS_OK; + } + else + status = HTTP_STATUS_UNAUTHORIZED; } else if (strcmp(cmd, "/v1/lists") == 0) { /** list of lists **/ @@ -1850,6 +1856,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, *ctype = "application/json"; status = HTTP_STATUS_OK; } + else + status = HTTP_STATUS_UNAUTHORIZED; } else if (xs_startswith(cmd, "/v1/lists/")) { /** list information **/ @@ -1910,6 +1918,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, } } } + else + status = HTTP_STATUS_UNAUTHORIZED; } else if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/ diff --git a/snac.h b/snac.h @@ -170,6 +170,7 @@ int is_bookmarked(snac *user, const char *id); int bookmark(snac *user, const char *id); int unbookmark(snac *user, const char *id); xs_list *bookmark_list(snac *user); +xs_str *bookmark_index_fn(snac *user); int pin(snac *user, const char *id); int unpin(snac *user, const char *id);