From 4c1a2d24d374d00c656c4489db7d28f80d64f9dc Mon Sep 17 00:00:00 2001 From: shtrophic Date: Mon, 20 Jan 2025 22:59:30 +0100 Subject: add port parsing for sandboxing --- snac.h | 1 + 1 file changed, 1 insertion(+) (limited to 'snac.h') diff --git a/snac.h b/snac.h index 65ece5d..3db7b63 100644 --- a/snac.h +++ b/snac.h @@ -417,6 +417,7 @@ void import_blocked_accounts_csv(snac *user, const char *fn); void import_following_accounts_csv(snac *user, const char *fn); void import_list_csv(snac *user, const char *fn); void import_csv(snac *user); +int parse_port(const char *url, const char **errstr); typedef enum { #define HTTP_STATUS(code, name, text) HTTP_STATUS_ ## name = code, -- cgit From 2ca7735779e79dbe6fe62f0111a12c145f428d8f Mon Sep 17 00:00:00 2001 From: shtrophic Date: Wed, 19 Feb 2025 08:56:14 +0100 Subject: fix ownership-problem of mailinfo --- activitypub.c | 2 +- data.c | 5 +++-- snac.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'snac.h') diff --git a/activitypub.c b/activitypub.c index e2519e6..a91821d 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1025,7 +1025,7 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor, "\n", from, email, subject); - xs *mailinfo = xs_dict_new(); + xs_dict *mailinfo = xs_dict_new(); xs_dict_append(mailinfo, "from", from); xs_dict_append(mailinfo, "to", email); xs_dict_append(mailinfo, "body", xs_fmt("%s%s", header, body)); diff --git a/data.c b/data.c index ae85aaf..d25a5d7 100644 --- a/data.c +++ b/data.c @@ -3174,7 +3174,7 @@ static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) } -static xs_dict *_new_qmsg(const char *type, const xs_val *msg, int retries) +static xs_dict *_new_qmsg(const char *type, xs_dict *msg, int retries) /* creates a queue message */ { int qrt = xs_number_get(xs_dict_get(srv_config, "queue_retry_minutes")); @@ -3276,9 +3276,10 @@ void enqueue_output_by_actor(snac *snac, const xs_dict *msg, } -void enqueue_email(const xs_dict *msg, int retries) +void enqueue_email(xs_dict *msg, int retries) /* enqueues an email message to be sent */ { + /* qmsg owns msg */ xs *qmsg = _new_qmsg("email", msg, retries); const char *ntid = xs_dict_get(qmsg, "ntid"); xs *fn = xs_fmt("%s/queue/%s.json", srv_basedir, ntid); diff --git a/snac.h b/snac.h index 92ffb3f..545df74 100644 --- a/snac.h +++ b/snac.h @@ -274,7 +274,7 @@ void enqueue_output(snac *snac, const xs_dict *msg, const xs_str *inbox, int retries, int p_status); void enqueue_output_by_actor(snac *snac, const xs_dict *msg, const xs_str *actor, int retries); -void enqueue_email(const xs_str *msg, int retries); +void enqueue_email(xs_dict *msg, int retries); void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id); void enqueue_ntfy(const xs_str *msg, const char *ntfy_server, const char *ntfy_token); void enqueue_message(snac *snac, const xs_dict *msg); -- cgit From 59a34a9646e28cc9a63194ff55547de0005d0110 Mon Sep 17 00:00:00 2001 From: shtrophic Date: Thu, 20 Feb 2025 17:13:12 +0100 Subject: Revert "fix ownership-problem of mailinfo" This reverts commit 2ca7735779e79dbe6fe62f0111a12c145f428d8f. --- activitypub.c | 2 +- data.c | 5 ++--- snac.h | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'snac.h') diff --git a/activitypub.c b/activitypub.c index a91821d..e2519e6 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1025,7 +1025,7 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor, "\n", from, email, subject); - xs_dict *mailinfo = xs_dict_new(); + xs *mailinfo = xs_dict_new(); xs_dict_append(mailinfo, "from", from); xs_dict_append(mailinfo, "to", email); xs_dict_append(mailinfo, "body", xs_fmt("%s%s", header, body)); diff --git a/data.c b/data.c index d25a5d7..ae85aaf 100644 --- a/data.c +++ b/data.c @@ -3174,7 +3174,7 @@ static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) } -static xs_dict *_new_qmsg(const char *type, xs_dict *msg, int retries) +static xs_dict *_new_qmsg(const char *type, const xs_val *msg, int retries) /* creates a queue message */ { int qrt = xs_number_get(xs_dict_get(srv_config, "queue_retry_minutes")); @@ -3276,10 +3276,9 @@ void enqueue_output_by_actor(snac *snac, const xs_dict *msg, } -void enqueue_email(xs_dict *msg, int retries) +void enqueue_email(const xs_dict *msg, int retries) /* enqueues an email message to be sent */ { - /* qmsg owns msg */ xs *qmsg = _new_qmsg("email", msg, retries); const char *ntid = xs_dict_get(qmsg, "ntid"); xs *fn = xs_fmt("%s/queue/%s.json", srv_basedir, ntid); diff --git a/snac.h b/snac.h index 545df74..92ffb3f 100644 --- a/snac.h +++ b/snac.h @@ -274,7 +274,7 @@ void enqueue_output(snac *snac, const xs_dict *msg, const xs_str *inbox, int retries, int p_status); void enqueue_output_by_actor(snac *snac, const xs_dict *msg, const xs_str *actor, int retries); -void enqueue_email(xs_dict *msg, int retries); +void enqueue_email(const xs_str *msg, int retries); void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id); void enqueue_ntfy(const xs_str *msg, const char *ntfy_server, const char *ntfy_token); void enqueue_message(snac *snac, const xs_dict *msg); -- cgit From 5090e4e77489d7e4e2d358c417c83be8f76307cb Mon Sep 17 00:00:00 2001 From: default Date: Tue, 1 Apr 2025 06:14:46 +0200 Subject: Added more scheduling code. --- data.c | 37 +++++++++++++++++++++++++++++++++++++ html.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- snac.h | 5 +++++ 3 files changed, 84 insertions(+), 2 deletions(-) (limited to 'snac.h') diff --git a/data.c b/data.c index a192830..8f68ee2 100644 --- a/data.c +++ b/data.c @@ -1929,6 +1929,43 @@ xs_list *draft_list(snac *user) } +/** scheduled posts **/ + +int is_scheduled(snac *user, const char *id) +/* returns true if this note is scheduled for future sending */ +{ + return object_user_cache_in(user, id, "sched"); +} + + +void schedule_del(snac *user, const char *id) +/* deletes an scheduled post */ +{ + object_user_cache_del(user, id, "sched"); +} + + +void schedule_add(snac *user, const char *id, const xs_dict *msg) +/* schedules this post for later */ +{ + /* delete from the index, in case it was already there */ + schedule_del(user, id); + + /* overwrite object */ + object_add_ow(id, msg); + + /* [re]add to the index */ + object_user_cache_add(user, id, "sched"); +} + + +xs_list *scheduled_list(snac *user) +/* return the list of scheduled posts */ +{ + return object_user_cache_list(user, "sched", XS_ALL, 1); +} + + /** hiding **/ xs_str *_hidden_fn(snac *snac, const char *id) diff --git a/html.c b/html.c index d4cbb35..bc8a645 100644 --- a/html.c +++ b/html.c @@ -2870,6 +2870,18 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only, xs_html_text(L("drafts"))))); } + { + /* show the list of scheduled posts */ + xs *url = xs_fmt("%s/sched", user->actor); + xs_html_add(lol, + xs_html_tag("li", + xs_html_tag("a", + xs_html_attr("href", url), + xs_html_attr("class", "snac-list-link"), + xs_html_attr("title", L("Scheduled posts")), + xs_html_text(L("scheduled posts"))))); + } + /* the list of followed hashtags */ const char *followed_hashtags = xs_dict_get(user->config, "followed_hashtags"); @@ -3919,6 +3931,21 @@ int html_get_handler(const xs_dict *req, const char *q_path, } } else + if (strcmp(p_path, "sched") == 0) { /** list of scheduled posts **/ + if (!login(&snac, req)) { + *body = xs_dup(uid); + status = HTTP_STATUS_UNAUTHORIZED; + } + else { + xs *list = scheduled_list(&snac); + + *body = html_timeline(&snac, list, 0, skip, show, + 0, L("Scheduled posts"), "", 0, error); + *b_size = strlen(*body); + status = HTTP_STATUS_OK; + } + } + else if (xs_startswith(p_path, "list/")) { /** list timelines **/ if (!login(&snac, req)) { *body = xs_dup(uid); @@ -4342,7 +4369,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, } else if (future_post) { - snac_log(&snac, xs_fmt("DUMMY scheduled post 1 %s", id)); + schedule_add(&snac, id, msg); } else { c_msg = msg_create(&snac, msg); @@ -4381,7 +4408,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, object_add_ow(edit_id, msg); if (future_post) { - snac_log(&snac, xs_fmt("DUMMY scheduled post 2 %s", edit_id)); + schedule_add(&snac, edit_id, msg); } else { c_msg = msg_create(&snac, msg); @@ -4390,7 +4417,15 @@ int html_post_handler(const xs_dict *req, const char *q_path, draft_del(&snac, edit_id); } + else + if (is_scheduled(&snac, edit_id)) { + /* editing an scheduled post; just update it */ + schedule_add(&snac, edit_id, msg); + } else { + /* ignore the (possibly changed) published date */ + msg = xs_dict_set(msg, "published", xs_dict_get(p_msg, "published")); + /* set the updated field */ xs *updated = xs_str_utctime(0, ISO_DATE_SPEC); msg = xs_dict_set(msg, "updated", updated); @@ -4474,6 +4509,9 @@ int html_post_handler(const xs_dict *req, const char *q_path, if (strcmp(action, L("Hide")) == 0) { /** **/ if (is_draft(&snac, id)) draft_del(&snac, id); + else + if (is_scheduled(&snac, id)) + schedule_del(&snac, id); else hide(&snac, id); } @@ -4570,6 +4608,8 @@ int html_post_handler(const xs_dict *req, const char *q_path, draft_del(&snac, id); + schedule_del(&snac, id); + snac_log(&snac, xs_fmt("deleted entry %s", id)); } } diff --git a/snac.h b/snac.h index 142ebc1..7e44039 100644 --- a/snac.h +++ b/snac.h @@ -205,6 +205,11 @@ void draft_del(snac *user, const char *id); void draft_add(snac *user, const char *id, const xs_dict *msg); xs_list *draft_list(snac *user); +int is_scheduled(snac *user, const char *id); +void schedule_del(snac *user, const char *id); +void schedule_add(snac *user, const char *id, const xs_dict *msg); +xs_list *scheduled_list(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) -- cgit From 9b2d0381ba734102c20d2111f0a2b64a3c438ef7 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 1 Apr 2025 06:32:53 +0200 Subject: More scheduled post code. --- activitypub.c | 2 ++ data.c | 29 ++++++++++++++++++++++++++++- snac.h | 3 ++- 3 files changed, 32 insertions(+), 2 deletions(-) (limited to 'snac.h') diff --git a/activitypub.c b/activitypub.c index c00c371..4c22c25 100644 --- a/activitypub.c +++ b/activitypub.c @@ -2759,6 +2759,8 @@ int process_user_queue(snac *snac) cnt++; } + scheduled_process(snac); + return cnt; } diff --git a/data.c b/data.c index 8f68ee2..6661472 100644 --- a/data.c +++ b/data.c @@ -1966,6 +1966,33 @@ xs_list *scheduled_list(snac *user) } +void scheduled_process(snac *user) +/* processes the scheduled list, sending those ready to be sent */ +{ + xs *posts = scheduled_list(user); + const char *md5; + xs *right_now = xs_str_utctime(0, ISO_DATE_SPEC); + + xs_list_foreach(posts, md5) { + xs *msg = NULL; + + if (valid_status(object_get_by_md5(md5, &msg))) { + if (strcmp(xs_dict_get(msg, "published"), right_now) < 0) { + /* due date! */ + const char *id = xs_dict_get(msg, "id"); + + timeline_add(user, id, msg); + + xs *c_msg = msg_create(user, msg); + enqueue_message(user, c_msg); + + schedule_del(user, id); + } + } + } +} + + /** hiding **/ xs_str *_hidden_fn(snac *snac, const char *id) @@ -3734,7 +3761,7 @@ void purge_user(snac *snac) _purge_user_subdir(snac, "public", pub_days); const char *idxs[] = { "followers.idx", "private.idx", "public.idx", - "pinned.idx", "bookmark.idx", "draft.idx", NULL }; + "pinned.idx", "bookmark.idx", "draft.idx", "sched.idx", NULL }; for (n = 0; idxs[n]; n++) { xs *idx = xs_fmt("%s/%s", snac->basedir, idxs[n]); diff --git a/snac.h b/snac.h index 7e44039..0d2aafe 100644 --- a/snac.h +++ b/snac.h @@ -1,7 +1,7 @@ /* snac - A simple, minimalistic ActivityPub instance */ /* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ -#define VERSION "2.74" +#define VERSION "2.75-dev" #define USER_AGENT "snac/" VERSION @@ -209,6 +209,7 @@ int is_scheduled(snac *user, const char *id); void schedule_del(snac *user, const char *id); 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) -- cgit From 848bd3e865fb2daf75d76cbb75a4a39f9b82b516 Mon Sep 17 00:00:00 2001 From: default Date: Sun, 13 Apr 2025 14:30:50 +0200 Subject: Cache the timezone inside the snac struct. --- data.c | 2 ++ html.c | 6 ++---- snac.h | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'snac.h') diff --git a/data.c b/data.c index 6661472..440e9df 100644 --- a/data.c +++ b/data.c @@ -282,6 +282,8 @@ int user_open(snac *user, const char *uid) } else srv_log(xs_fmt("error parsing '%s'", cfg_file)); + + user->tz = xs_dict_get_def(user->config, "tz", "UTC"); } else srv_debug(2, xs_fmt("error opening '%s' %d", cfg_file, errno)); diff --git a/html.c b/html.c index a6f79de..2e7f87c 100644 --- a/html.c +++ b/html.c @@ -455,7 +455,7 @@ xs_html *html_note(snac *user, const char *summary, } if (edit_id == NULL || is_draft || is_scheduled(user, edit_id)) { - xs *pdat = xs_fmt(L("Post date and time (timezone: %s):"), xs_dict_get_def(user->config, "tz", "UTC")); + xs *pdat = xs_fmt(L("Post date and time (timezone: %s):"), user->tz); xs_html_add(form, xs_html_tag("p", @@ -4367,9 +4367,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, time_t t = xs_parse_iso_date(post_pubdate, 0); if (t != 0) { - const char *tz = xs_dict_get_def(snac.config, "tz", "UTC"); - - t -= xs_tz_offset(tz); + t -= xs_tz_offset(snac.tz); xs *iso_date = xs_str_iso_date(t); msg = xs_dict_set(msg, "published", iso_date); diff --git a/snac.h b/snac.h index 0d2aafe..5a19467 100644 --- a/snac.h +++ b/snac.h @@ -61,6 +61,7 @@ typedef struct { xs_str *actor; /* actor url */ xs_str *md5; /* actor url md5 */ const xs_dict *lang;/* string translation dict */ + const char *tz; /* configured timezone */ } snac; typedef struct { -- cgit From 21a99e55081a58f1396d49fb70824f91a8e7c2ab Mon Sep 17 00:00:00 2001 From: green Date: Wed, 9 Apr 2025 03:09:53 +0200 Subject: emoji: refactor + emoji in display names on front page --- html.c | 39 +++++++++++++++++++++++++-------------- httpd.c | 4 +++- snac.h | 1 + 3 files changed, 29 insertions(+), 15 deletions(-) (limited to 'snac.h') diff --git a/html.c b/html.c index c8015a1..f3d5ee9 100644 --- a/html.c +++ b/html.c @@ -143,6 +143,26 @@ xs_str *actor_name(xs_dict *actor, const char *proxy) } +xs_str *format_text_with_emoji(snac *user, const char *text, int ems, const char *proxy) +/* needed when we have local text with no tags attached */ +{ + xs *tags = xs_list_new(); + xs *name1 = not_really_markdown(text, NULL, &tags); + + xs_str *name3; + if (user) { + xs *name2 = process_tags(user, name1, &tags); + name3 = sanitize(name2); + } + else { + name3 = sanitize(name1); + name3 = xs_replace_i(name3, "
", ""); + } + + return replace_shortnames(name3, tags, ems, proxy); +} + + xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date, const char *udate, const char *url, int priv, int in_people, const char *proxy, const char *lang, @@ -976,16 +996,12 @@ static xs_html *html_user_body(snac *user, int read_only) xs_dict_get(user->config, "uid"), xs_dict_get(srv_config, "host")); - // also try to make emojis render in local usernames, specifically in the user info thing in the web ui - xs *name_tags = xs_list_new(); - xs *name1 = not_really_markdown(xs_dict_get(user->config, "name"), NULL, &name_tags); - xs *name2 = sanitize(name1); - name2 = replace_shortnames(name2, name_tags, 1, proxy); + xs *display_name = format_text_with_emoji(NULL, xs_dict_get(user->config, "name"), 1, proxy); xs_html_add(top_user, xs_html_tag("p", xs_html_attr("class", "p-name snac-top-user-name"), - xs_html_raw(name2)), + xs_html_raw(display_name)), xs_html_tag("p", xs_html_attr("class", "snac-top-user-id"), xs_html_text(handle))); @@ -1013,16 +1029,11 @@ static xs_html *html_user_body(snac *user, int read_only) } if (read_only) { - xs *tags = xs_list_new(); - xs *bio1 = not_really_markdown(xs_dict_get(user->config, "bio"), NULL, &tags); - xs *bio2 = process_tags(user, bio1, &tags); - xs *bio3 = sanitize(bio2); - - bio3 = replace_shortnames(bio3, tags, 2, proxy); + xs *bio = format_text_with_emoji(user, xs_dict_get(user->config, "bio"), 2, proxy); xs_html *top_user_bio = xs_html_tag("div", xs_html_attr("class", "p-note snac-top-user-bio"), - xs_html_raw(bio3)); /* already sanitized */ + xs_html_raw(bio)); /* already sanitized */ xs_html_add(top_user, top_user_bio); @@ -3675,7 +3686,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, if (xs_is_true(xs_dict_get(srv_config, "strict_public_timelines"))) list = timeline_simple_list(&snac, "public", skip, show, &more); - else + else list = timeline_list(&snac, "public", skip, show, &more); xs *pins = pinned_list(&snac); diff --git a/httpd.c b/httpd.c index 22a148d..836c256 100644 --- a/httpd.c +++ b/httpd.c @@ -139,6 +139,8 @@ static xs_str *greeting_html(void) snac user; if (strcmp(uid, "relay") && user_open(&user, uid)) { + xs *formatted_name = format_text_with_emoji(NULL, xs_dict_get(user.config, "name"), 1, NULL); + xs_html_add(ul, xs_html_tag("li", xs_html_tag("a", @@ -148,7 +150,7 @@ static xs_str *greeting_html(void) xs_html_text("@"), xs_html_text(host), xs_html_text(" ("), - xs_html_text(xs_dict_get(user.config, "name")), + xs_html_raw(formatted_name), xs_html_text(")")))); user_free(&user); diff --git a/snac.h b/snac.h index 0d2aafe..90f8bd8 100644 --- a/snac.h +++ b/snac.h @@ -373,6 +373,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path, char **body, int *b_size, char **ctype); xs_dict *emojis(void); +xs_str *format_text_with_emoji(snac *user, const char *text, int ems, const char *proxy); xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag); xs_str *sanitize(const char *content); xs_str *encode_html(const char *str); -- cgit From 8fbc8a3e14da59b9aa0640e5cc70d7556cf27c8d Mon Sep 17 00:00:00 2001 From: default Date: Wed, 16 Apr 2025 09:40:13 +0200 Subject: Version 2.75 RELEASED. --- snac.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'snac.h') diff --git a/snac.h b/snac.h index 5a19467..9626c8b 100644 --- a/snac.h +++ b/snac.h @@ -1,7 +1,7 @@ /* snac - A simple, minimalistic ActivityPub instance */ /* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ -#define VERSION "2.75-dev" +#define VERSION "2.75" #define USER_AGENT "snac/" VERSION -- cgit From d8e640a4dac0dd83c15ba4bb4e314f8fd5e17357 Mon Sep 17 00:00:00 2001 From: grunfink Date: Mon, 28 Apr 2025 05:16:35 +0200 Subject: Bumped version. --- snac.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'snac.h') diff --git a/snac.h b/snac.h index c2e1507..06f9568 100644 --- a/snac.h +++ b/snac.h @@ -1,7 +1,7 @@ /* snac - A simple, minimalistic ActivityPub instance */ /* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ -#define VERSION "2.75" +#define VERSION "2.76-dev" #define USER_AGENT "snac/" VERSION -- cgit From 605b60c06ea882cd61df7f2d834c02cce6dd254d Mon Sep 17 00:00:00 2001 From: grunfink Date: Sat, 3 May 2025 19:16:21 +0200 Subject: New function enqueue_webmention(). The q_msg is queued, but nothing is done yet. --- data.c | 13 +++++++++++++ html.c | 4 +++- main.c | 1 + snac.h | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) (limited to 'snac.h') diff --git a/data.c b/data.c index 7d33f77..73332ef 100644 --- a/data.c +++ b/data.c @@ -3473,6 +3473,19 @@ void enqueue_actor_refresh(snac *user, const char *actor, int forward_secs) } +void enqueue_webmention(const xs_dict *msg) +/* enqueues a webmention for the post */ +{ + xs *qmsg = _new_qmsg("webmention", msg, 0); + const char *ntid = xs_dict_get(qmsg, "ntid"); + xs *fn = xs_fmt("%s/queue/%s.json", srv_basedir, ntid); + + qmsg = _enqueue_put(fn, qmsg); + + srv_debug(1, xs_fmt("enqueue_webmention")); +} + + int was_question_voted(snac *user, const char *id) /* returns true if the user voted in this poll */ { diff --git a/html.c b/html.c index 0652892..e114ea7 100644 --- a/html.c +++ b/html.c @@ -4488,8 +4488,10 @@ int html_post_handler(const xs_dict *req, const char *q_path, snac_log(&snac, xs_fmt("cannot get object '%s' for editing", edit_id)); } - if (c_msg != NULL) + if (c_msg != NULL) { enqueue_message(&snac, c_msg); + enqueue_webmention(msg); + } history_del(&snac, "timeline.html_"); } diff --git a/main.c b/main.c index a6fb6fd..80df2d0 100644 --- a/main.c +++ b/main.c @@ -830,6 +830,7 @@ int main(int argc, char *argv[]) } enqueue_message(&snac, c_msg); + enqueue_webmention(msg); timeline_add(&snac, xs_dict_get(msg, "id"), msg); diff --git a/snac.h b/snac.h index 06f9568..d9d0cfd 100644 --- a/snac.h +++ b/snac.h @@ -289,6 +289,7 @@ void enqueue_close_question(snac *user, const char *id, int end_secs); void enqueue_object_request(snac *user, const char *id, int forward_secs); void enqueue_verify_links(snac *user); void enqueue_actor_refresh(snac *user, const char *actor, int forward_secs); +void enqueue_webmention(const xs_dict *msg); int was_question_voted(snac *user, const char *id); xs_list *user_queue(snac *snac); -- cgit From 33647d2cb75077b7152a9727659b452a7727d42b Mon Sep 17 00:00:00 2001 From: grunfink Date: Fri, 9 May 2025 10:48:29 +0200 Subject: Version 2.76 RELEASED. --- snac.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'snac.h') diff --git a/snac.h b/snac.h index be5af07..e51fc18 100644 --- a/snac.h +++ b/snac.h @@ -1,7 +1,7 @@ /* snac - A simple, minimalistic ActivityPub instance */ /* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ -#define VERSION "2.76-dev" +#define VERSION "2.76" #define USER_AGENT "snac/" VERSION -- cgit From f321905d4bcdd4ae5b344f9b743ecdac35e3672f Mon Sep 17 00:00:00 2001 From: grunfink Date: Mon, 12 May 2025 09:43:11 +0200 Subject: Version 2.77 RELEASED. --- snac.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'snac.h') diff --git a/snac.h b/snac.h index e51fc18..64bc2bf 100644 --- a/snac.h +++ b/snac.h @@ -1,7 +1,7 @@ /* snac - A simple, minimalistic ActivityPub instance */ /* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ -#define VERSION "2.76" +#define VERSION "2.77" #define USER_AGENT "snac/" VERSION -- cgit From ee84140ecceb07dad8ea36cc5aa29b91bbb48a56 Mon Sep 17 00:00:00 2001 From: grunfink Date: Sun, 18 May 2025 08:23:48 +0200 Subject: Added a pending follow request count next to the "people" link. --- data.c | 10 ++++++++++ html.c | 12 ++++++++++++ snac.h | 1 + 3 files changed, 23 insertions(+) (limited to 'snac.h') diff --git a/data.c b/data.c index 73332ef..e3fa52d 100644 --- a/data.c +++ b/data.c @@ -1335,6 +1335,16 @@ xs_list *pending_list(snac *user) } +int pending_count(snac *user) +/* returns the number of pending follow confirmations */ +{ + xs *spec = xs_fmt("%s/pending/""*.json", user->basedir); + xs *l = xs_glob(spec, 0, 0); + + return xs_list_len(l); +} + + /** timeline **/ double timeline_mtime(snac *snac) diff --git a/html.c b/html.c index aec7d0a..6c7af51 100644 --- a/html.c +++ b/html.c @@ -923,7 +923,9 @@ static xs_html *html_user_body(snac *user, int read_only) } else { int n_len = notify_new_num(user); + int p_len = pending_count(user); xs_html *notify_count = NULL; + xs_html *pending_follow_count = NULL; /* show the number of new notifications, if there are any */ if (n_len) { @@ -935,6 +937,15 @@ static xs_html *html_user_body(snac *user, int read_only) else notify_count = xs_html_text(""); + if (p_len) { + xs *s = xs_fmt(" %d ", p_len); + pending_follow_count = xs_html_tag("sup", + xs_html_attr("style", "background-color: red; color: white;"), + xs_html_text(s)); + } + else + pending_follow_count = xs_html_text(""); + xs *admin_url = xs_fmt("%s/admin", user->actor); xs *notify_url = xs_fmt("%s/notifications", user->actor); xs *people_url = xs_fmt("%s/people", user->actor); @@ -957,6 +968,7 @@ static xs_html *html_user_body(snac *user, int read_only) xs_html_tag("a", xs_html_attr("href", people_url), xs_html_text(L("people"))), + pending_follow_count, xs_html_text(" - "), xs_html_tag("a", xs_html_attr("href", instance_url), diff --git a/snac.h b/snac.h index 64bc2bf..2ab9a67 100644 --- a/snac.h +++ b/snac.h @@ -159,6 +159,7 @@ int pending_check(snac *user, const char *actor); xs_dict *pending_get(snac *user, const char *actor); void pending_del(snac *user, const char *actor); xs_list *pending_list(snac *user); +int pending_count(snac *user); double timeline_mtime(snac *snac); int timeline_touch(snac *snac); -- cgit From 00fd1a1c3eb99c9e441276a7ce8697a1582152b7 Mon Sep 17 00:00:00 2001 From: green Date: Sat, 29 Mar 2025 01:27:46 +0100 Subject: performance: functions to get the number of followers --- data.c | 17 +++++++++++++++++ html.c | 12 ++---------- snac.h | 2 ++ 3 files changed, 21 insertions(+), 10 deletions(-) (limited to 'snac.h') diff --git a/data.c b/data.c index e3fa52d..482a29c 100644 --- a/data.c +++ b/data.c @@ -1215,6 +1215,14 @@ int follower_check(snac *snac, const char *actor) } +int follower_list_len(snac *snac) +/* returns the number followers */ +{ + xs *list = object_user_cache_list(snac, "followers", XS_ALL, 0); + return xs_list_len(list); +} + + xs_list *follower_list(snac *snac) /* returns the list of followers */ { @@ -1709,6 +1717,15 @@ int following_get(snac *snac, const char *actor, xs_dict **data) } +int following_list_len(snac *snac) +/* returns number of people being followed */ +{ + xs *spec = xs_fmt("%s/following/" "*_a.json", snac->basedir); + xs *glist = xs_glob(spec, 0, 0); + return xs_list_len(glist); +} + + xs_list *following_list(snac *snac) /* returns the list of people being followed */ { diff --git a/html.c b/html.c index b27db7a..4483dd7 100644 --- a/html.c +++ b/html.c @@ -821,11 +821,7 @@ xs_html *html_user_head(snac *user, const char *desc, const char *url) /* show metrics in og:description? */ if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) { - xs *fwers = follower_list(user); - xs *fwing = following_list(user); - - xs *s1 = xs_fmt(L("%d following, %d followers"), - xs_list_len(fwing), xs_list_len(fwers)); + xs *s1 = xs_fmt(L("%d following, %d followers"), following_list_len(user), follower_list_len(user)); s1 = xs_str_cat(s1, " ยท "); @@ -1166,11 +1162,7 @@ static xs_html *html_user_body(snac *user, int read_only) } if (xs_is_true(xs_dict_get(user->config, "show_contact_metrics"))) { - xs *fwers = follower_list(user); - xs *fwing = following_list(user); - - xs *s1 = xs_fmt(L("%d following, %d followers"), - xs_list_len(fwing), xs_list_len(fwers)); + xs *s1 = xs_fmt(L("%d following, %d followers"), following_list_len(user), follower_list_len(user)); xs_html_add(top_user, xs_html_tag("p", diff --git a/snac.h b/snac.h index 2ab9a67..256731f 100644 --- a/snac.h +++ b/snac.h @@ -153,6 +153,7 @@ int follower_add(snac *snac, const char *actor); int follower_del(snac *snac, const char *actor); int follower_check(snac *snac, const char *actor); xs_list *follower_list(snac *snac); +int follower_list_len(snac *snac); int pending_add(snac *user, const char *actor, const xs_dict *msg); int pending_check(snac *user, const char *actor); @@ -184,6 +185,7 @@ int following_del(snac *snac, const char *actor); int following_check(snac *snac, const char *actor); int following_get(snac *snac, const char *actor, xs_dict **data); xs_list *following_list(snac *snac); +int following_list_len(snac *snac); void mute(snac *snac, const char *actor); void unmute(snac *snac, const char *actor); -- cgit