diff options
-rw-r--r-- | RELEASE_NOTES.md | 2 | ||||
-rw-r--r-- | mastoapi.c | 57 |
2 files changed, 46 insertions, 13 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index b0d37f4..e3cefa4 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -10,7 +10,7 @@ The avatar and/or the header images can now be deleted (contributed by louis77). Code cleaning: HTTP status codes use names instead of hardcoded integers (contributed by louis77). -Mastodon API: some fixes for Mona and Tokodon apps, user credentials can now be edited from apps (contributed by louis77). +Mastodon API: fixed login problems with the official Mastodon API, IceCube and Toot! on iOS, some fixes for Mona and Tokodon apps, user credentials can now be edited from apps (contributed by louis77). The webfinger content-type response header is now RFC-compliant (contributed by steve-bate). @@ -152,6 +152,7 @@ const char *login_page = "" "<html>\n" "<head>\n" "<title>%s OAuth - Snac2</title>\n" +"<meta content=\"width=device-width, initial-scale=1, minimum-scale=1, user-scalable=no\" name=\"viewport\">" "<style>:root {color-scheme: light dark}</style>\n" "</head>\n" "<body><h1>%s OAuth identify</h1>\n" @@ -338,11 +339,7 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, const char *cid = xs_dict_get(args, "client_id"); const char *csec = xs_dict_get(args, "client_secret"); const char *ruri = xs_dict_get(args, "redirect_uri"); - /* FIXME: this 'scope' parameter is mandatory for the official Mastodon API, - but if it's enabled, it makes it crash after some more steps, which - is FAR WORSE */ - const char *scope = NULL; -// scope = xs_dict_get(args, "scope"); + const char *scope = xs_dict_get(args, "scope"); /* no client_secret? check if it's inside an authorization header (AndStatus does it this way) */ @@ -1164,8 +1161,10 @@ void credentials_get(char **body, char **ctype, int *status, snac snac) acct = xs_dict_append(acct, "url", snac.actor); acct = xs_dict_append(acct, "locked", xs_stock(XSTYPE_FALSE)); acct = xs_dict_append(acct, "bot", xs_dict_get(snac.config, "bot")); + acct = xs_dict_append(acct, "emojis", xs_stock(XSTYPE_LIST)); - xs *src = xs_json_loads("{\"privacy\":\"public\"," + xs *src = xs_json_loads("{\"privacy\":\"public\", \"language\":\"en\"," + "\"follow_requests_count\": 0," "\"sensitive\":false,\"fields\":[],\"note\":\"\"}"); /* some apps take the note from the source object */ src = xs_dict_set(src, "note", xs_dict_get(snac.config, "bio")); @@ -1447,9 +1446,27 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (strcmp(opt, "featured_tags") == 0) { /* snac doesn't have features tags, yet? */ /* implement empty response so apps like Tokodon don't show an error */ - *body = xs_dup("[]"); - *ctype = "application/json"; - status = HTTP_STATUS_OK; + out = xs_list_new(); + } + else + if (strcmp(opt, "following") == 0) { + xs *wing = following_list(&snac1); + out = xs_list_new(); + int c = 0; + const char *v; + + while (xs_list_next(wing, &v, &c)) { + xs *actor = NULL; + + if (valid_status(object_get(v, &actor))) { + xs *acct = mastoapi_account(actor); + out = xs_list_append(out, acct); + } + } + } + else + if (strcmp(opt, "followers") == 0) { + out = xs_list_new(); } user_free(&snac2); @@ -1470,9 +1487,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (strcmp(opt, "featured_tags") == 0) { /* snac doesn't have features tags, yet? */ /* implement empty response so apps like Tokodon don't show an error */ - *body = xs_dup("[]"); - *ctype = "application/json"; - status = HTTP_STATUS_OK; + out = xs_list_new(); } } } @@ -2408,6 +2423,14 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, const char *ruri = xs_dict_get(args, "redirect_uris"); const char *scope = xs_dict_get(args, "scope"); + /* Ice Cubes sends these values as query parameters, so try these */ + if (name == NULL && ruri == NULL && scope == NULL) { + args = xs_dup(xs_dict_get(req, "q_vars")); + name = xs_dict_get(args, "client_name"); + ruri = xs_dict_get(args, "redirect_uris"); + scope = xs_dict_get(args, "scope"); + } + if (xs_type(ruri) == XSTYPE_LIST) ruri = xs_dict_get(ruri, 0); @@ -2914,6 +2937,10 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (op && id && xs_is_hex(id)) { if (strcmp(op, "accounts") == 0) { const xs_list *accts = xs_dict_get(args, "account_ids[]"); + + if (xs_is_null(accts)) + accts = xs_dict_get(args, "account_ids"); + int c = 0; const char *v; @@ -2921,6 +2948,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, list_content(&snac, id, v, 1); } + *ctype = "application/json"; status = HTTP_STATUS_OK; } } @@ -2993,6 +3021,10 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path, /* delete account from list */ p = xs_list_get(l, -2); const xs_list *accts = xs_dict_get(args, "account_ids[]"); + + if (xs_is_null(accts)) + accts = xs_dict_get(args, "account_ids"); + int c = 0; const char *v; @@ -3008,6 +3040,7 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path, } } + *ctype = "application/json"; status = HTTP_STATUS_OK; } else |