Browse Source

mastoapi: added bookmark list.

default 7 months ago
parent
commit
08de491395
3 changed files with 28 additions and 5 deletions
  1. 13 1
      data.c
  2. 14 4
      mastoapi.c
  3. 1 0
      snac.h

+ 13 - 1
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)

+ 14 - 4
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) { /** **/

+ 1 - 0
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);