From 4425d8e985e35cee72acf7b22f50422c8e1ac2a3 Mon Sep 17 00:00:00 2001 From: grunfink Date: Sun, 12 Jul 2026 20:12:03 +0200 Subject: Added count of EmojiReacts to top_ten. --- data.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'data.c') diff --git a/data.c b/data.c index 52e4271..806938c 100644 --- a/data.c +++ b/data.c @@ -1051,6 +1051,14 @@ int object_announces_len(const char *id) } +int object_emojireacts_len(const char *id) +/* returns the number of emojireacts (without reading the index) */ +{ + xs *fn = _object_index_fn(id, "_e.idx"); + return index_len(fn); +} + + xs_list *object_children(const char *id) /* returns the list of an object's children */ { -- cgit From 71a83e6578f910c3baa251e4128208b201ce9e45 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 26 Aug 2026 07:59:23 +0200 Subject: Use snac_op in actor_failure(). --- activitypub.c | 10 +++++----- data.c | 11 +++++++---- html.c | 2 +- snac.h | 10 +++++++++- 4 files changed, 22 insertions(+), 11 deletions(-) (limited to 'data.c') diff --git a/activitypub.c b/activitypub.c index 92eb7f5..4de0be7 100644 --- a/activitypub.c +++ b/activitypub.c @@ -3054,7 +3054,7 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) followed_hashtag_distribute(a_msg); /* actor is [back] alive */ - actor_failure(who, 2); + actor_failure(who, OP_DEL); do_notify = 1; } @@ -3461,7 +3461,7 @@ void process_user_queue_item(snac *user, xs_dict *q_item) const char *actor = xs_dict_get(q_item, "actor"); double mtime = object_mtime(actor); - if (actor_failure(actor, 0) == -1) { + if (actor_failure(actor, OP_CHECK) == -1) { /* actor is broken beyond repair */ snac_debug(user, 1, xs_fmt("actor_refresh skipped broken actor %s", actor)); } @@ -3478,16 +3478,16 @@ void process_user_queue_item(snac *user, xs_dict *q_item) actor_add(actor, actor_o); /* mark actor and instance as working */ - actor_failure(actor, 2); + actor_failure(actor, OP_DEL); instance_failure(actor, 2); } else { if (status == HTTP_STATUS_GONE || status == HTTP_STATUS_NOT_FOUND) { - actor_failure(actor, 1); + actor_failure(actor, OP_ADD); snac_log(user, xs_fmt("actor_refresh marking actor %s as broken %d", actor, status)); } else { - actor_failure(actor, 2); + actor_failure(actor, OP_DEL); object_touch(actor); } } diff --git a/data.c b/data.c index 806938c..7a8f884 100644 --- a/data.c +++ b/data.c @@ -3233,7 +3233,7 @@ xs_list *content_search(snac *user, const char *regex, } -int actor_failure(const char *actor, int op) +int actor_failure(const char *actor, snac_op op) /* actor failure maintenance */ { int ret = 0; @@ -3242,13 +3242,13 @@ int actor_failure(const char *actor, int op) xs *fn = xs_fmt("%s/failure/%s", srv_basedir, md5); switch (op) { - case 0: /** check **/ + case OP_CHECK: /** check **/ if (mtime(fn)) ret = -1; break; - case 1: /** register a failure **/ + case OP_ADD: /** register a failure **/ if (mtime(fn) == 0.0) { FILE *f; @@ -3261,11 +3261,14 @@ int actor_failure(const char *actor, int op) break; - case 2: /** clear a failure **/ + case OP_DEL: /** clear a failure **/ /* called whenever a message comes from this instance */ unlink(fn); break; + + default: + break; } return ret; diff --git a/html.c b/html.c index 3f35040..f18e233 100644 --- a/html.c +++ b/html.c @@ -362,7 +362,7 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date, xs_html_raw("💔"))); } - if (actor_failure(actor_id, 0) == -1) { + if (actor_failure(actor_id, OP_CHECK) == -1) { xs_html_add(actor_icon, xs_html_text(" "), xs_html_tag("span", diff --git a/snac.h b/snac.h index 1644315..602fa0c 100644 --- a/snac.h +++ b/snac.h @@ -79,6 +79,14 @@ typedef struct { enum { THST_STOP, THST_WAIT, THST_IN, THST_QUEUE } th_state[MAX_THREADS]; } srv_state; +typedef enum { + OP_CHECK = 0, + OP_ADD = 1, + OP_DEL = 2, + OP_LIST = 3, + OP_FIND = 4 +} snac_op; + extern srv_state *p_state; enum { @@ -300,7 +308,7 @@ int content_match(const char *file, const xs_dict *msg); xs_list *content_search(snac *user, const char *regex, int priv, int skip, int show, int max_secs, int *timeout); -int actor_failure(const char *actor, int op); +int actor_failure(const char *actor, snac_op op); int instance_failure(const char *url, int op); int grave(const char *objid, int op); -- cgit From 48aba53ddbca75bfdbda7d224c6d2c315fcd282a Mon Sep 17 00:00:00 2001 From: default Date: Wed, 26 Aug 2026 08:02:41 +0200 Subject: Use snac_op in instance_failure(). --- activitypub.c | 10 +++++----- data.c | 11 +++++++---- rss.c | 2 +- snac.h | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) (limited to 'data.c') diff --git a/activitypub.c b/activitypub.c index 4de0be7..8155fe4 100644 --- a/activitypub.c +++ b/activitypub.c @@ -2594,7 +2594,7 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) } /* this instance is alive */ - instance_failure(actor, 2); + instance_failure(actor, OP_DEL); /* question votes may not have a type */ if (xs_is_null(type)) @@ -3029,7 +3029,7 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req) const char *who = get_atto(a_msg); /* got the admired object: instance is [back] online */ - instance_failure(object, 2); + instance_failure(object, OP_DEL); if (who && !is_muted(snac, who)) { /* bring the actor */ @@ -3479,7 +3479,7 @@ void process_user_queue_item(snac *user, xs_dict *q_item) /* mark actor and instance as working */ actor_failure(actor, OP_DEL); - instance_failure(actor, 2); + instance_failure(actor, OP_DEL); } else { if (status == HTTP_STATUS_GONE || status == HTTP_STATUS_NOT_FOUND) { @@ -3604,7 +3604,7 @@ void process_queue_item(xs_dict *q_item) return; } - if (instance_failure(inbox, 0)) { + if (instance_failure(inbox, OP_CHECK)) { srv_debug(1, xs_fmt("output message error: too many failures for instance %s", inbox)); return; } @@ -3621,7 +3621,7 @@ void process_queue_item(xs_dict *q_item) status = send_to_inbox_raw(keyid, seckey, inbox, msg, &payload, &p_size, timeout); /* register or clear a value for this instance */ - instance_failure(inbox, valid_status(status) ? 2 : 1); + instance_failure(inbox, valid_status(status) ? OP_DEL : OP_ADD); if (payload) { if (p_size > 1024) { diff --git a/data.c b/data.c index 7a8f884..3736bc9 100644 --- a/data.c +++ b/data.c @@ -3275,7 +3275,7 @@ int actor_failure(const char *actor, snac_op op) } -int instance_failure(const char *url, int op) +int instance_failure(const char *url, snac_op op) /* do some checks and accounting on instance failures */ { int ret = 0; @@ -3290,7 +3290,7 @@ int instance_failure(const char *url, int op) xs *fn = xs_fmt("%s/failure/%s", srv_basedir, md5); switch (op) { - case 0: /** check **/ + case OP_CHECK: /** check **/ if ((mt = mtime(fn)) != 0.0) { /* grace time */ double seconds_failing = xs_number_get(xs_dict_get_def(srv_config, "max_failing_days", "15")) @@ -3302,7 +3302,7 @@ int instance_failure(const char *url, int op) break; - case 1: /** register a failure **/ + case OP_ADD: /** register a failure **/ if (mtime(fn) == 0.0) { FILE *f; @@ -3315,11 +3315,14 @@ int instance_failure(const char *url, int op) break; - case 2: /** clear a failure **/ + case OP_DEL: /** clear a failure **/ /* called whenever a message comes from this instance */ unlink(fn); break; + + default: + break; } return ret; diff --git a/rss.c b/rss.c index 9b4ae65..5ec85cb 100644 --- a/rss.c +++ b/rss.c @@ -282,7 +282,7 @@ void rss_to_timeline(snac *user, const char *url) continue; /* the instance is [back] online */ - instance_failure(id, 2); + instance_failure(id, OP_DEL); if (timeline_here(user, id)) { snac_debug(user, 1, xs_fmt("RSS entry already in timeline (id) %s", id)); diff --git a/snac.h b/snac.h index 602fa0c..d21c7ad 100644 --- a/snac.h +++ b/snac.h @@ -309,7 +309,7 @@ xs_list *content_search(snac *user, const char *regex, int priv, int skip, int show, int max_secs, int *timeout); int actor_failure(const char *actor, snac_op op); -int instance_failure(const char *url, int op); +int instance_failure(const char *url, snac_op op); int grave(const char *objid, int op); -- cgit From d7fc3d950d4654a3291066fed667f1b7d48e70bb Mon Sep 17 00:00:00 2001 From: default Date: Wed, 26 Aug 2026 08:05:16 +0200 Subject: Use snac_op in grave(). --- activitypub.c | 4 ++-- data.c | 11 +++++++---- html.c | 2 +- snac.h | 2 +- utils.c | 4 ++-- 5 files changed, 13 insertions(+), 10 deletions(-) (limited to 'data.c') diff --git a/activitypub.c b/activitypub.c index 8155fe4..df319f0 100644 --- a/activitypub.c +++ b/activitypub.c @@ -3951,7 +3951,7 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path, uid = xs_list_get(l, 1); if (!user_open(&snac, uid)) { /* invalid user */ - status = grave(uid, 0) ? HTTP_STATUS_GONE : HTTP_STATUS_NOT_FOUND; + status = grave(uid, OP_CHECK) ? HTTP_STATUS_GONE : HTTP_STATUS_NOT_FOUND; srv_debug(1, xs_fmt("activitypub_get_handler bad user %s %d", uid, status)); return status; } @@ -4151,7 +4151,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path, const char *uid = xs_list_get(l, 1); if (!user_open(&snac, uid)) { /* invalid user */ - status = grave(uid, 0) ? HTTP_STATUS_GONE : HTTP_STATUS_NOT_FOUND; + status = grave(uid, OP_CHECK) ? HTTP_STATUS_GONE : HTTP_STATUS_NOT_FOUND; srv_debug(1, xs_fmt("activitypub_post_handler bad user %s %d", uid, status)); return status; } diff --git a/data.c b/data.c index 3736bc9..333ed31 100644 --- a/data.c +++ b/data.c @@ -3329,7 +3329,7 @@ int instance_failure(const char *url, snac_op op) } -int grave(const char *objid, int op) +int grave(const char *objid, snac_op op) /* the graveyeard of deleted objects */ { int ret = 0; @@ -3339,11 +3339,11 @@ int grave(const char *objid, int op) FILE *f; switch (op) { - case 0: /** check **/ + case OP_CHECK: /** check **/ ret = mtime(fn) > 0.0 ? 1 : 0; break; - case 1: /** add **/ + case OP_ADD: /** add **/ mkdirx(dir); if ((f = fopen(fn, "w")) != NULL) { @@ -3353,9 +3353,12 @@ int grave(const char *objid, int op) break; - case 2: /** del **/ + case OP_DEL: /** del **/ unlink(fn); break; + + default: + break; } return ret; diff --git a/html.c b/html.c index f18e233..8f177cc 100644 --- a/html.c +++ b/html.c @@ -4717,7 +4717,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, if (!uid || !user_open(&snac, uid)) { /* invalid user */ - status = grave(uid, 0) ? HTTP_STATUS_GONE : HTTP_STATUS_NOT_FOUND; + status = grave(uid, OP_CHECK) ? HTTP_STATUS_GONE : HTTP_STATUS_NOT_FOUND; srv_debug(2, xs_fmt("html_get_handler bad user '%s' %d", xs_or(uid, "(null)"), status)); return status; } diff --git a/snac.h b/snac.h index d21c7ad..84223e6 100644 --- a/snac.h +++ b/snac.h @@ -311,7 +311,7 @@ xs_list *content_search(snac *user, const char *regex, int actor_failure(const char *actor, snac_op op); int instance_failure(const char *url, snac_op op); -int grave(const char *objid, int op); +int grave(const char *objid, snac_op op); void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries); void enqueue_shared_input(const xs_dict *msg, const xs_dict *req, int retries); diff --git a/utils.c b/utils.c index 6941081..c1855b2 100644 --- a/utils.c +++ b/utils.c @@ -372,7 +372,7 @@ int adduser(const char *uid) } /* remove the grave */ - grave(uid, 2); + grave(uid, OP_DEL); printf("\nUser password is %s\n", pwd); @@ -467,7 +467,7 @@ int deluser(snac *user) } } - grave(user->uid, 1); + grave(user->uid, OP_ADD); rm_rf(user->basedir); -- cgit From 120308074813de49fea6728259b5d78a907ea9b2 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 26 Aug 2026 08:09:07 +0200 Subject: Use snac_op in list_members(). --- data.c | 8 ++++---- main.c | 6 +++--- mastoapi.c | 8 ++++---- snac.h | 2 +- utils.c | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index 333ed31..8be649d 100644 --- a/data.c +++ b/data.c @@ -2621,7 +2621,7 @@ xs_list *list_timeline(snac *user, const char *list, int skip, int show) } -xs_val *list_members(snac *user, const char *list, const char *actor_md5, int op) +xs_val *list_members(snac *user, const char *list, const char *actor_md5, snac_op op) /* list member management */ { xs_val *l = NULL; @@ -2635,12 +2635,12 @@ xs_val *list_members(snac *user, const char *list, const char *actor_md5, int op xs *fn = xs_fmt("%s/list/%s.lst", user->basedir, list); switch (op) { - case 0: /** list members **/ + case OP_LIST: /** list members **/ l = index_list(fn, XS_ALL); break; - case 1: /** append actor to list **/ + case OP_ADD: /** append actor to list **/ if (xs_is_string(actor_md5) && xs_is_hex(actor_md5)) { if (!index_in_md5(fn, actor_md5)) index_add_md5(fn, actor_md5); @@ -2648,7 +2648,7 @@ xs_val *list_members(snac *user, const char *list, const char *actor_md5, int op break; - case 2: /** delete actor from list **/ + case OP_DEL: /** delete actor from list **/ if (xs_is_string(actor_md5) && xs_is_hex(actor_md5)) index_del_md5(fn, actor_md5); diff --git a/main.c b/main.c index 9170761..dd224de 100644 --- a/main.c +++ b/main.c @@ -392,7 +392,7 @@ int main(int argc, char *argv[]) xs *lid = list_maint(&snac, url, 4); if (lid != NULL) { - xs *lcont = list_members(&snac, lid, NULL, 0); + xs *lcont = list_members(&snac, lid, NULL, OP_LIST); const char *md5; xs_list_foreach(lcont, md5) { @@ -448,7 +448,7 @@ int main(int argc, char *argv[]) if (valid_status(webfinger_request(account, &actor, &uid))) { xs *md5 = xs_md5_hex(actor, strlen(actor)); - list_members(&snac, lid, md5, 1); + list_members(&snac, lid, md5, OP_ADD); printf("Actor %s (%s) added to list '%s' (%s)\n", actor, uid, url, lid); } else @@ -471,7 +471,7 @@ int main(int argc, char *argv[]) if (lid != NULL) { xs *md5 = xs_md5_hex(account, strlen(account)); - list_members(&snac, lid, md5, 2); + list_members(&snac, lid, md5, OP_DEL); printf("Actor %s deleted from list '%s' (%s)\n", account, url, lid); } else diff --git a/mastoapi.c b/mastoapi.c index 027ec42..571d7cb 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1795,7 +1795,7 @@ xs_list *mastoapi_account_lists(snac *user, const char *uid) const char *list_id = xs_list_get(li, 0); const char *list_title = xs_list_get(li, 1); if (uid) { - xs *users = list_members(user, list_id, NULL, 0); + xs *users = list_members(user, list_id, NULL, OP_LIST); if (xs_list_in(users, actor_md5) == -1) continue; } @@ -2527,7 +2527,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, p = xs_list_get(l, -2); if (p && xs_is_hex(p)) { - xs *actors = list_members(&snac1, p, NULL, 0); + xs *actors = list_members(&snac1, p, NULL, OP_LIST); xs *out = xs_list_new(); int c = 0; const char *v; @@ -3843,7 +3843,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, const char *v; while (xs_list_next(accts, &v, &c)) { - list_members(&snac, id, v, 1); + list_members(&snac, id, v, OP_ADD); } xs *out = xs_dict_new(); @@ -4052,7 +4052,7 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path, const char *v; while (xs_list_next(accts, &v, &c)) { - list_members(&snac, p, v, 2); + list_members(&snac, p, v, OP_DEL); } } else { diff --git a/snac.h b/snac.h index 84223e6..0406a2e 100644 --- a/snac.h +++ b/snac.h @@ -262,7 +262,7 @@ xs_list *tag_search(const char *tag, int skip, int show); xs_val *list_maint(snac *user, const char *list, int op); xs_str *list_timeline_fn(snac *user, const char *list); xs_list *list_timeline(snac *user, const char *list, int skip, int show); -xs_val *list_members(snac *user, const char *list_id, const char *actor_md5, int op); +xs_val *list_members(snac *user, const char *list_id, const char *actor_md5, snac_op op); void list_distribute(snac *user, const char *who, const xs_dict *post); int actor_add(const char *actor, const xs_dict *msg); diff --git a/utils.c b/utils.c index c1855b2..6d202d8 100644 --- a/utils.c +++ b/utils.c @@ -705,7 +705,7 @@ void export_csv(snac *user) const char *lid = xs_list_get(li, 0); const char *ltitle = xs_list_get(li, 1); - xs *actors = list_members(user, lid, NULL, 0); + xs *actors = list_members(user, lid, NULL, OP_LIST); const char *md5; xs_list_foreach(actors, md5) { @@ -935,7 +935,7 @@ void import_list_csv(snac *user, const char *ifn) if (valid_status(webfinger_request(acct, &url, &uid))) { xs *actor_md5 = xs_md5_hex(url, strlen(url)); - list_members(user, list_id, actor_md5, 1); + list_members(user, list_id, actor_md5, OP_ADD); snac_log(user, xs_fmt("Added %s to list %s", url, lname)); if (!following_check(user, url)) { -- cgit From 319d5cae0e632e1891f442194afe5e36aa48e6c4 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 26 Aug 2026 08:17:03 +0200 Subject: Use snac_op in list_maint(). --- data.c | 19 +++++++++++-------- html.c | 4 ++-- main.c | 16 ++++++++-------- mastoapi.c | 8 ++++---- snac.h | 5 +++-- utils.c | 4 ++-- 6 files changed, 30 insertions(+), 26 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index 8be649d..6273800 100644 --- a/data.c +++ b/data.c @@ -2474,13 +2474,13 @@ xs_list *tag_search(const char *tag, int skip, int show) /** lists **/ -xs_val *list_maint(snac *user, const char *list, int op) +xs_val *list_maint(snac *user, const char *list, snac_op op) /* list maintenance */ { xs_val *l = NULL; switch (op) { - case 0: /** list of lists **/ + case OP_LIST: /** list of lists **/ { FILE *f; xs *spec = xs_fmt("%s/list/" "*.id", user->basedir); @@ -2509,9 +2509,9 @@ xs_val *list_maint(snac *user, const char *list, int op) break; - case 1: /** create new list (list is the name) **/ + case OP_ADD: /** create new list (list is the name) **/ { - xs *lol = list_maint(user, NULL, 0); + xs *lol = list_maint(user, NULL, OP_LIST); int c = 0; const xs_list *v; int add = 1; @@ -2546,7 +2546,7 @@ xs_val *list_maint(snac *user, const char *list, int op) break; - case 2: /** delete list (list is the id) **/ + case OP_DEL: /** delete list (list is the id) **/ { if (xs_is_hex(list)) { xs *fn = xs_fmt("%s/list/%s.id", user->basedir, list); @@ -2565,7 +2565,7 @@ xs_val *list_maint(snac *user, const char *list, int op) break; - case 3: /** get list name **/ + case OP_ID: /** get list name **/ if (xs_is_hex(list)) { FILE *f; xs *fn = xs_fmt("%s/list/%s.id", user->basedir, list); @@ -2578,9 +2578,9 @@ xs_val *list_maint(snac *user, const char *list, int op) break; - case 4: /** find list id by name **/ + case OP_FIND: /** find list id by name **/ if (xs_is_string(list)) { - xs *lol = list_maint(user, NULL, 0); + xs *lol = list_maint(user, NULL, OP_LIST); const xs_list *li; xs_list_foreach(lol, li) { @@ -2590,6 +2590,9 @@ xs_val *list_maint(snac *user, const char *list, int op) } } } + + default: + break; } return l; diff --git a/html.c b/html.c index 8f177cc..503539c 100644 --- a/html.c +++ b/html.c @@ -3534,7 +3534,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only, xs_html_attr("class", "snac-list-of-lists")); xs_html_add(body, lol); - xs *lists = list_maint(user, NULL, 0); /* get list of lists */ + xs *lists = list_maint(user, NULL, OP_LIST); /* get list of lists */ int ct = 0; const char *v; @@ -5179,7 +5179,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, xs *ttl = timeline_top_level(&snac, list); xs *base = xs_fmt("/list/%s", lid); - xs *name = list_maint(&snac, lid, 3); + xs *name = list_maint(&snac, lid, OP_ID); xs *title = xs_fmt(L("Showing timeline for list '%s'"), name); *body = html_timeline(&snac, ttl, 0, skip, show, diff --git a/main.c b/main.c index dd224de..433bfc2 100644 --- a/main.c +++ b/main.c @@ -332,7 +332,7 @@ int main(int argc, char *argv[]) } if (strcmp(cmd, "lists") == 0) { /** **/ - xs *lol = list_maint(&snac, NULL, 0); + xs *lol = list_maint(&snac, NULL, OP_LIST); const xs_list *l; xs_list_foreach(lol, l) { @@ -389,7 +389,7 @@ int main(int argc, char *argv[]) return usage(cmd); if (strcmp(cmd, "list_members") == 0) { /** **/ - xs *lid = list_maint(&snac, url, 4); + xs *lid = list_maint(&snac, url, OP_FIND); if (lid != NULL) { xs *lcont = list_members(&snac, lid, NULL, OP_LIST); @@ -410,10 +410,10 @@ int main(int argc, char *argv[]) } if (strcmp(cmd, "list_create") == 0) { /** **/ - xs *lid = list_maint(&snac, url, 4); + xs *lid = list_maint(&snac, url, OP_FIND); if (lid == NULL) { - xs *n_lid = list_maint(&snac, url, 1); + xs *n_lid = list_maint(&snac, url, OP_ADD); printf("New list named '%s' created (%s)\n", url, n_lid); } else @@ -423,10 +423,10 @@ int main(int argc, char *argv[]) } if (strcmp(cmd, "list_remove") == 0) { /** **/ - xs *lid = list_maint(&snac, url, 4); + xs *lid = list_maint(&snac, url, OP_FIND); if (lid != NULL) { - list_maint(&snac, lid, 2); + list_maint(&snac, lid, OP_DEL); printf("List '%s' (%s) deleted\n", url, lid); } else @@ -439,7 +439,7 @@ int main(int argc, char *argv[]) const char *account = GET_ARGV(); if (account != NULL) { - xs *lid = list_maint(&snac, url, 4); + xs *lid = list_maint(&snac, url, OP_FIND); if (lid != NULL) { xs *actor = NULL; @@ -466,7 +466,7 @@ int main(int argc, char *argv[]) const char *account = GET_ARGV(); if (account != NULL) { - xs *lid = list_maint(&snac, url, 4); + xs *lid = list_maint(&snac, url, OP_FIND); if (lid != NULL) { xs *md5 = xs_md5_hex(account, strlen(account)); diff --git a/mastoapi.c b/mastoapi.c index 571d7cb..81c9bf0 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1781,7 +1781,7 @@ xs_list *mastoapi_account_lists(snac *user, const char *uid) { xs_list *out = xs_list_new(); xs *actor_md5 = NULL; - xs *lol = list_maint(user, NULL, 0); + xs *lol = list_maint(user, NULL, OP_LIST); if (uid) { if (!xs_is_hex(uid)) @@ -2549,7 +2549,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, else if (xs_is_hex(p)) { xs *out = xs_list_new(); - xs *lol = list_maint(&snac1, NULL, 0); + xs *lol = list_maint(&snac1, NULL, OP_LIST); int c = 0; const xs_list *v; @@ -3803,7 +3803,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, if (xs_type(title) == XSTYPE_STRING) { /* add the list */ xs *out = xs_dict_new(); - xs *lid = list_maint(&snac, title, 1); + xs *lid = list_maint(&snac, title, OP_ADD); if (!xs_is_null(lid)) { out = xs_dict_append(out, "id", lid); @@ -4058,7 +4058,7 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path, else { /* delete list */ if (xs_is_hex(p)) { - list_maint(&snac, p, 2); + list_maint(&snac, p, OP_DEL); } } } diff --git a/snac.h b/snac.h index 0406a2e..a8dad16 100644 --- a/snac.h +++ b/snac.h @@ -84,7 +84,8 @@ typedef enum { OP_ADD = 1, OP_DEL = 2, OP_LIST = 3, - OP_FIND = 4 + OP_FIND = 4, + OP_ID = 5 } snac_op; extern srv_state *p_state; @@ -259,7 +260,7 @@ void tag_index(const char *id, const xs_dict *obj); xs_str *tag_fn(const char *tag); xs_list *tag_search(const char *tag, int skip, int show); -xs_val *list_maint(snac *user, const char *list, int op); +xs_val *list_maint(snac *user, const char *list, snac_op op); xs_str *list_timeline_fn(snac *user, const char *list); xs_list *list_timeline(snac *user, const char *list, int skip, int show); xs_val *list_members(snac *user, const char *list_id, const char *actor_md5, snac_op op); diff --git a/utils.c b/utils.c index 6d202d8..8780270 100644 --- a/utils.c +++ b/utils.c @@ -698,7 +698,7 @@ void export_csv(snac *user) if ((f = fopen(fn, "w")) != NULL) { snac_log(user, xs_fmt("Creating %s...", fn)); - xs *lol = list_maint(user, NULL, 0); + xs *lol = list_maint(user, NULL, OP_LIST); const xs_list *li; xs_list_foreach(lol, li) { @@ -927,7 +927,7 @@ void import_list_csv(snac *user, const char *ifn) if (lname && acct) { /* create the list */ - xs *list_id = list_maint(user, lname, 1); + xs *list_id = list_maint(user, lname, OP_ADD); xs *url = NULL; xs *uid = NULL; -- cgit From 03e9f05fa35329a81e9755bb247e246fd416859d Mon Sep 17 00:00:00 2001 From: default Date: Wed, 26 Aug 2026 09:02:30 +0200 Subject: Use snac_op in limited(). --- data.c | 13 ++++++++----- snac.h | 8 ++++---- utils.c | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index 6273800..04b9e6e 100644 --- a/data.c +++ b/data.c @@ -2355,7 +2355,7 @@ int actor_get_refresh(snac *user, const char *actor, xs_dict **data) /** user limiting (announce blocks) **/ -int limited(snac *user, const char *id, int cmd) +int limited(snac *user, const char *id, snac_op op) /* announce messages from a followed (0: check, 1: limit; 2: unlimit) */ { int ret = 0; @@ -2363,12 +2363,12 @@ int limited(snac *user, const char *id, int cmd) xs *md5 = xs_md5_hex(id, strlen(id)); xs *fn = xs_fmt("%s/%s", dir, md5); - switch (cmd) { - case 0: /** check **/ + switch (op) { + case OP_CHECK: /** check **/ ret = !!(mtime(fn) > 0.0); break; - case 1: /** limit **/ + case OP_ADD: /** limit **/ mkdirx(dir); if (mtime(fn) > 0.0) @@ -2385,12 +2385,15 @@ int limited(snac *user, const char *id, int cmd) } break; - case 2: /** unlimit **/ + case OP_DEL: /** unlimit **/ if (mtime(fn) > 0.0) ret = unlink(fn); else ret = -1; break; + + default: + break; } return ret; diff --git a/snac.h b/snac.h index a8dad16..318dbd3 100644 --- a/snac.h +++ b/snac.h @@ -247,10 +247,10 @@ void schedule_add(snac *user, const char *id, const xs_dict *msg); xs_list *scheduled_list(snac *user); void scheduled_process(snac *user); -int limited(snac *user, const char *id, int cmd); -#define is_limited(user, id) limited((user), (id), 0) -#define limit(user, id) limited((user), (id), 1) -#define unlimit(user, id) limited((user), (id), 2) +int limited(snac *user, const char *id, snac_op); +#define is_limited(user, id) limited((user), (id), OP_CHECK) +#define limit(user, id) limited((user), (id), OP_ADD) +#define unlimit(user, id) limited((user), (id), OP_DEL) void hide(snac *snac, const char *id); int is_hidden(snac *snac, const char *id); diff --git a/utils.c b/utils.c index 8780270..8fab2d2 100644 --- a/utils.c +++ b/utils.c @@ -744,7 +744,7 @@ void export_csv(snac *user) webfinger_request_fake(actor, NULL, &uid); if (xs_is_string(uid)) - fprintf(f, "%s,%s,false,\n", uid, limited(user, actor, 0) ? "false" : "true"); + fprintf(f, "%s,%s,false,\n", uid, limited(user, actor, OP_CHECK) ? "false" : "true"); } fclose(f); -- cgit From 61ef7a86183d7d8f5f6a5fcd6d945b91dcb68526 Mon Sep 17 00:00:00 2001 From: grunfink Date: Sun, 30 Aug 2026 16:38:58 +0200 Subject: Fixed error in notification filtering. --- data.c | 14 ++++++++++++-- html.c | 7 ++++--- snac.h | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index 04b9e6e..fd6c91f 100644 --- a/data.c +++ b/data.c @@ -3576,7 +3576,7 @@ xs_list *notify_list(snac *snac, int skip, int show) } -xs_list *notify_filter_list(snac *snac, xs_list *notifs) +xs_list *notify_filter_list(snac *snac, xs_list *notifs, int skip, int show) /* apply user-defined notification filter to IDs */ { const xs_dict *n_filter = xs_dict_get(snac->config, "notify_filter"); @@ -3633,7 +3633,17 @@ xs_list *notify_filter_list(snac *snac, xs_list *notifs) continue; if (strcmp(type, "Announce") == 0 && !n_ann_on) continue; + + if (skip) { + skip--; + continue; + } + flt = xs_list_append(flt, v); + show--; + + if (show == 0) + break; } return flt; } @@ -3644,7 +3654,7 @@ int notify_new_num(snac *snac) { xs *t = notify_check_time(snac, 0); xs *lst_unfilt = notify_list(snac, 0, XS_ALL); - xs *lst = notify_filter_list(snac, lst_unfilt); + xs *lst = notify_filter_list(snac, lst_unfilt, 0, XS_ALL); int cnt = 0; xs_list *p = lst; diff --git a/html.c b/html.c index 134cc87..b26c252 100644 --- a/html.c +++ b/html.c @@ -4267,7 +4267,7 @@ xs_str *html_notifications(snac *user, int skip, int show) if (xs_is_true(xs_dict_get(srv_config, "proxy_media"))) proxy = user->actor; - xs *n_list_unfilt = notify_list(user, skip, show); + xs *n_list_unfilt = notify_list(user, 0, XS_ALL); xs *n_time = notify_check_time(user, 0); xs_html *body = html_user_body(user, 0); @@ -4278,7 +4278,7 @@ xs_str *html_notifications(snac *user, int skip, int show) user->tz = xs_dict_get_def(user->config, "tz", "UTC"); // previous line invalidates user->tz n_filter = xs_dict_get(user->config, "notify_filter"); } - xs *n_list = notify_filter_list(user, n_list_unfilt); + xs *n_list = notify_filter_list(user, n_list_unfilt, skip, show); /* all filters are true by default */ const xs_val *n_def = xs_stock( XSTYPE_TRUE ); int n_likes_on = xs_is_true(xs_dict_get_def(n_filter, "likes", n_def)); @@ -4607,7 +4607,8 @@ xs_str *html_notifications(snac *user, int skip, int show) xs_html_text(L("None")))); /* add the navigation footer */ - xs *next_p = notify_list(user, skip + show, 1); + xs *next_p = notify_filter_list(user, n_list_unfilt, skip + show, 1); + if (xs_list_len(next_p)) { xs *url = xs_fmt("%s/notifications?skip=%d&show=%d", user->actor, skip + show, show); diff --git a/snac.h b/snac.h index 2acb1ec..80d2429 100644 --- a/snac.h +++ b/snac.h @@ -291,7 +291,7 @@ void notify_add(snac *snac, const char *type, const char *utype, xs_dict *notify_get(snac *snac, const char *id); int notify_new_num(snac *snac); xs_list *notify_list(snac *snac, int skip, int show); -xs_list *notify_filter_list(snac *snac, xs_list *ids); +xs_list *notify_filter_list(snac *snac, xs_list *ids, int skip, int show); void notify_clear(snac *snac); xs_dict *markers_get(snac *snac, const xs_list *markers); -- cgit From 8e521cce1f980edb6ce0bfd490e93e8ab5baa93a Mon Sep 17 00:00:00 2001 From: grunfink Date: Sun, 30 Aug 2026 16:46:38 +0200 Subject: Added notification filter for Webmentions. --- data.c | 3 +++ html.c | 4 ++++ 2 files changed, 7 insertions(+) (limited to 'data.c') diff --git a/data.c b/data.c index fd6c91f..c38a0b3 100644 --- a/data.c +++ b/data.c @@ -3593,6 +3593,7 @@ xs_list *notify_filter_list(snac *snac, xs_list *notifs, int skip, int show) int n_folreq_on = xs_is_true(xs_dict_get_def(n_filter, "folreqs", n_def)); int n_blocks_on = xs_is_true(xs_dict_get_def(n_filter, "blocks", n_def)); int n_polls_on = xs_is_true(xs_dict_get_def(n_filter, "polls", n_def)); + int n_webmen_on = xs_is_true(xs_dict_get_def(n_filter, "webmentions", n_def)); const xs_str *v; xs_list *flt = xs_list_new(); @@ -3633,6 +3634,8 @@ xs_list *notify_filter_list(snac *snac, xs_list *notifs, int skip, int show) continue; if (strcmp(type, "Announce") == 0 && !n_ann_on) continue; + if (strcmp(type, "Webmention") == 0 && !n_webmen_on) + continue; if (skip) { skip--; diff --git a/html.c b/html.c index b26c252..3ba48d7 100644 --- a/html.c +++ b/html.c @@ -4246,6 +4246,7 @@ void notify_filter(snac *user, const xs_dict *p_vars) int folreq_on = (v = xs_dict_get(p_vars, "folreqs_on")) ? strcmp(v, "on") == 0 : 0; int blocks_on = (v = xs_dict_get(p_vars, "blocks_on")) ? strcmp(v, "on") == 0 : 0; int polls_on = (v = xs_dict_get(p_vars, "polls_on")) ? strcmp(v, "on") == 0 : 0; + int webmen_on = (v = xs_dict_get(p_vars, "webmentions_on")) ? strcmp(v, "on") == 0 : 0; xs *filter = xs_dict_new(); filter = xs_dict_set(filter, "likes", xs_stock(likes_on ? XSTYPE_TRUE : XSTYPE_FALSE)); filter = xs_dict_set(filter, "reacts", xs_stock(reacts_on ? XSTYPE_TRUE : XSTYPE_FALSE)); @@ -4256,6 +4257,7 @@ void notify_filter(snac *user, const xs_dict *p_vars) filter = xs_dict_set(filter, "folreqs", xs_stock(folreq_on ? XSTYPE_TRUE : XSTYPE_FALSE)); filter = xs_dict_set(filter, "blocks", xs_stock(blocks_on ? XSTYPE_TRUE : XSTYPE_FALSE)); filter = xs_dict_set(filter, "polls", xs_stock(polls_on ? XSTYPE_TRUE : XSTYPE_FALSE)); + filter = xs_dict_set(filter, "webmentions", xs_stock(webmen_on ? XSTYPE_TRUE : XSTYPE_FALSE)); user->config = xs_dict_set(user->config, "notify_filter", filter); user->tz = xs_dict_get_def(user->config, "tz", "UTC"); // previous line invalidates user->tz } @@ -4290,6 +4292,7 @@ xs_str *html_notifications(snac *user, int skip, int show) int n_folreq_on = xs_is_true(xs_dict_get_def(n_filter, "folreqs", n_def)); int n_blocks_on = xs_is_true(xs_dict_get_def(n_filter, "blocks", n_def)); int n_polls_on = xs_is_true(xs_dict_get_def(n_filter, "polls", n_def)); + int n_webmen_on = xs_is_true(xs_dict_get_def(n_filter, "webmentions", n_def)); xs_html *html = xs_html_tag("html", html_user_head(user, NULL, NULL), @@ -4316,6 +4319,7 @@ xs_str *html_notifications(snac *user, int skip, int show) html_checkbox("folreqs_on", L("Follow requests"), n_folreq_on), html_checkbox("blocks_on", L("Blocks"), n_blocks_on), html_checkbox("polls_on", L("Polls"), n_polls_on), + html_checkbox("webmentions_on", L("Webmentions"), n_webmen_on), xs_html_sctag("input", xs_html_attr("type", "submit"), xs_html_attr("class", "button"), -- cgit From 5e74f4578816812f4f6ad47390e96dcfafee37d2 Mon Sep 17 00:00:00 2001 From: grunfink Date: Tue, 1 Sep 2026 08:46:42 +0200 Subject: Increased debug level for _load_raw_file(). --- data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'data.c') diff --git a/data.c b/data.c index c38a0b3..279f7af 100644 --- a/data.c +++ b/data.c @@ -2740,7 +2740,7 @@ static int _load_raw_file(const char *fn, xs_val **data, int *size, if (etag != NULL) *etag = xs_dup(e); - srv_debug(1, xs_fmt("_load_raw_file(): %s %d", fn, status)); + srv_debug(2, xs_fmt("_load_raw_file(): %s %d", fn, status)); } } -- cgit From 2085a9e91187e89a1eed83b1243521cd5038ca19 Mon Sep 17 00:00:00 2001 From: grunfink Date: Wed, 2 Sep 2026 09:49:02 +0200 Subject: Skip notification files that are too big. --- data.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index 279f7af..2529713 100644 --- a/data.c +++ b/data.c @@ -3529,12 +3529,18 @@ xs_dict *notify_get(snac *snac, const char *id) fn = xs_strip_i(fn); fn = xs_str_cat(fn, ".json"); - FILE *f; xs_dict *out = NULL; - if ((f = fopen(fn, "r")) != NULL) { - out = xs_json_load(f); - fclose(f); + struct stat st; + + if (stat(fn, &st) != -1) { + if (st.st_size < 100000) { + FILE *f; + if ((f = fopen(fn, "r")) != NULL) { + out = xs_json_load(f); + fclose(f); + } + } } return out; -- cgit