Przeglądaj źródła

The instance timeline now works.

default 3 lat temu
rodzic
commit
cfa0df3ac5
2 zmienionych plików z 13 dodań i 20 usunięć
  1. 11 18
      mastoapi.c
  2. 2 2
      snac.h

+ 11 - 18
mastoapi.c

@@ -1036,7 +1036,12 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
     }
     }
     else
     else
     if (strcmp(cmd, "/v1/timelines/public") == 0) {
     if (strcmp(cmd, "/v1/timelines/public") == 0) {
-        /* the public timeline (public timelines for all users) */
+        /* the instance public timeline (public timelines for all users) */
+
+        /* NOTE: this api call needs no authorization; but,
+           I need a logged-in user in mastoapi_status() for
+           is_msg_public() and the liked/boosted flags,
+           so it will silently fail for pure public access */
 
 
         const char *limit_s = xs_dict_get(args, "limit");
         const char *limit_s = xs_dict_get(args, "limit");
         int limit = 0;
         int limit = 0;
@@ -1053,7 +1058,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
         xs_list *p   = timeline;
         xs_list *p   = timeline;
         xs_str *md5;
         xs_str *md5;
 
 
-        while (xs_list_iter(&p, &md5) && cnt < limit) {
+        while (logged_in && xs_list_iter(&p, &md5) && cnt < limit) {
             xs *msg = NULL;
             xs *msg = NULL;
 
 
             /* get the entry */
             /* get the entry */
@@ -1064,23 +1069,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
             if (strcmp(xs_dict_get(msg, "type"), "Note") != 0)
             if (strcmp(xs_dict_get(msg, "type"), "Note") != 0)
                 continue;
                 continue;
 
 
-            /* get the uid */
-            xs *l = xs_split(xs_dict_get(msg, "attributedTo"), "/");
-            const char *uid = xs_list_get(l, -1);
-
-            if (!xs_is_null(uid)) {
-                snac user;
-
-                if (user_open(&user, uid)) {
-                    /* convert the Note into a Mastodon status */
-                    xs *st = mastoapi_status(&user, msg);
-
-                    if (st != NULL)
-                        out = xs_list_append(out, st);
-
-                    user_free(&user);
-                }
+            /* convert the Note into a Mastodon status */
+            xs *st = mastoapi_status(&snac1, msg);
 
 
+            if (st != NULL) {
+                out = xs_list_append(out, st);
                 cnt++;
                 cnt++;
             }
             }
         }
         }

+ 2 - 2
snac.h

@@ -127,8 +127,8 @@ int is_muted(snac *snac, const char *actor);
 void hide(snac *snac, const char *id);
 void hide(snac *snac, const char *id);
 int is_hidden(snac *snac, const char *id);
 int is_hidden(snac *snac, const char *id);
 
 
-int actor_add(snac *snac, const char *actor, d_char *msg);
-int actor_get(snac *snac, const char *actor, d_char **data);
+int actor_add(snac *snac, const char *actor, xs_dict *msg);
+int actor_get(snac *snac, const char *actor, xs_dict **data);
 
 
 int static_get(snac *snac, const char *id, d_char **data, int *size);
 int static_get(snac *snac, const char *id, d_char **data, int *size);
 void static_put(snac *snac, const char *id, const char *data, int size);
 void static_put(snac *snac, const char *id, const char *data, int size);