From 442b46abc0afeedfeffba7f5317fa5b350ef9c56 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 17 Nov 2024 10:53:47 +0100 Subject: mastoapi: added more checks in the notifications code. --- mastoapi.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index c9d71b9..f80c730 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1784,6 +1784,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, mn = xs_dict_append(mn, "created_at", xs_dict_get(noti, "date")); xs *acct = mastoapi_account(&snac1, actor); + + if (acct == NULL) + continue; + mn = xs_dict_append(mn, "account", acct); if (strcmp(type, "follow") != 0 && !xs_is_null(objid)) { -- cgit v1.2.3 From 437829a83376b9094689469d7d4c30eab48f556e Mon Sep 17 00:00:00 2001 From: default Date: Sun, 17 Nov 2024 11:08:25 +0100 Subject: mastoapi: more tweaks to notifications code. --- mastoapi.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index f80c730..73b9a8b 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1727,11 +1727,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (logged_in) { xs *l = notify_list(&snac1, 0, 64); xs *out = xs_list_new(); - xs_list *p = l; const xs_dict *v; const xs_list *excl = xs_dict_get(args, "exclude_types[]"); + const char *max_id = xs_dict_get(args, "max_id"); - while (xs_list_iter(&p, &v)) { + xs_list_foreach(l, v) { xs *noti = notify_get(&snac1, v); if (noti == NULL) @@ -1740,6 +1740,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, const char *type = xs_dict_get(noti, "type"); const char *utype = xs_dict_get(noti, "utype"); const char *objid = xs_dict_get(noti, "objid"); + const char *id = xs_dict_get(noti, "id"); + xs *fid = xs_replace(id, ".", ""); xs *actor = NULL; xs *entry = NULL; @@ -1752,6 +1754,13 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (is_hidden(&snac1, objid)) continue; + if (max_id) { + if (strcmp(fid, max_id) == 0) + max_id = NULL; + + continue; + } + /* convert the type */ if (strcmp(type, "Like") == 0 || strcmp(type, "EmojiReact") == 0) type = "favourite"; @@ -1778,8 +1787,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, mn = xs_dict_append(mn, "type", type); - xs *id = xs_replace(xs_dict_get(noti, "id"), ".", ""); - mn = xs_dict_append(mn, "id", id); + mn = xs_dict_append(mn, "id", fid); mn = xs_dict_append(mn, "created_at", xs_dict_get(noti, "date")); -- cgit v1.2.3 From a7974cbaa7037292c8883271fc2d0983698882a6 Mon Sep 17 00:00:00 2001 From: François Kooman Date: Mon, 18 Nov 2024 11:46:14 +0100 Subject: do not autocapitalize "Login: " masto api field on Chrome/Safari the Mastodon API OAuth login page auto capitalizes the first char of the "Login: " field. This disabled that. --- mastoapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index c9d71b9..076f8aa 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -171,7 +171,7 @@ const char *login_page = "" "

%s OAuth identify

\n" "
%s
\n" "
\n" -"

Login:

\n" +"

Login:

\n" "

Password:

\n" "\n" "\n" -- cgit v1.2.3 From 085caa7747a3bbebbd2ec09b3264dc6fcc5a7624 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 19 Nov 2024 06:46:14 +0100 Subject: New function get_in_reply_to(). --- mastoapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 825f207..1dd91dc 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1024,7 +1024,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) st = xs_dict_append(st, "in_reply_to_id", xs_stock(XSTYPE_NULL)); st = xs_dict_append(st, "in_reply_to_account_id", xs_stock(XSTYPE_NULL)); - tmp = xs_dict_get(msg, "inReplyTo"); + tmp = get_in_reply_to(msg); if (!xs_is_null(tmp)) { xs *irto = NULL; -- cgit v1.2.3 From 781c0edcc67b317fbba147a22da614dc3599c0d2 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 20 Nov 2024 15:59:36 +0100 Subject: mastoapi: fixed crash in posts without 'published' field. --- mastoapi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 1dd91dc..a529990 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -827,7 +827,16 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) st = xs_dict_append(st, "url", id); st = xs_dict_append(st, "account", acct); - xs *fd = mastoapi_date(xs_dict_get(msg, "published")); + const char *published = xs_dict_get(msg, "published"); + xs *fd = NULL; + + if (published) + fd = mastoapi_date(published); + else { + xs *p = xs_str_iso_date(0); + fd = mastoapi_date(p); + } + st = xs_dict_append(st, "created_at", fd); { -- cgit v1.2.3 From 203db3b09e3ebf8677f75e83e5470b99c74de470 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 4 Dec 2024 05:51:17 +0100 Subject: Fixed bug in blocked instance rejection. --- mastoapi.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index a529990..0332629 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1349,6 +1349,9 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn if (!xs_match(type, POSTLIKE_OBJECT_TYPE)) continue; + if (is_instance_blocked(id)) + continue; + const char *from = NULL; if (strcmp(type, "Page") == 0) from = xs_dict_get(msg, "audience"); -- cgit v1.2.3 From e0ba66a53e8cd89b900b895675588c29d5bb7a2d Mon Sep 17 00:00:00 2001 From: default Date: Wed, 4 Dec 2024 05:53:12 +0100 Subject: Check for existing id. --- mastoapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 0332629..ee9ecec 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1349,7 +1349,7 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn if (!xs_match(type, POSTLIKE_OBJECT_TYPE)) continue; - if (is_instance_blocked(id)) + if (id && is_instance_blocked(id)) continue; const char *from = NULL; -- cgit v1.2.3 From 2edce5e0ec5d098a7b879df20496cd636fa6d192 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 4 Dec 2024 21:45:49 +0100 Subject: mastoapi: show contact metrics if the user want. --- mastoapi.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index ee9ecec..4efe182 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -663,6 +663,17 @@ xs_dict *mastoapi_account(snac *logged, const xs_dict *actor) if (user_open(&user, prefu)) { val_links = user.links; metadata = xs_dict_get_def(user.config, "metadata", xs_stock(XSTYPE_DICT)); + + /* does this user want to publish their contact metrics? */ + if (xs_is_true(xs_dict_get(user.config, "show_contact_metrics"))) { + xs *fwing = following_list(&user); + xs *fwers = follower_list(&user); + xs *ni = xs_number_new(xs_list_len(fwing)); + xs *ne = xs_number_new(xs_list_len(fwers)); + + acct = xs_dict_append(acct, "followers_count", ne); + acct = xs_dict_append(acct, "following_count", ni); + } } } -- cgit v1.2.3 From e6d8cc26eaef1482b66acaf5f934536dde709109 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 4 Dec 2024 21:58:19 +0100 Subject: mastoapi: also fill metrics from credentials_get(). --- mastoapi.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 4efe182..990898b 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1286,6 +1286,17 @@ void credentials_get(char **body, char **ctype, int *status, snac snac) acct = xs_dict_append(acct, "following_count", xs_stock(0)); acct = xs_dict_append(acct, "statuses_count", xs_stock(0)); + /* does this user want to publish their contact metrics? */ + if (xs_is_true(xs_dict_get(snac.config, "show_contact_metrics"))) { + xs *fwing = following_list(&snac); + xs *fwers = follower_list(&snac); + xs *ni = xs_number_new(xs_list_len(fwing)); + xs *ne = xs_number_new(xs_list_len(fwers)); + + acct = xs_dict_append(acct, "followers_count", ne); + acct = xs_dict_append(acct, "following_count", ni); + } + *body = xs_json_dumps(acct, 4); *ctype = "application/json"; *status = HTTP_STATUS_OK; -- cgit v1.2.3