From 770062def6f3e10bf56eae48e274709796fa6df6 Mon Sep 17 00:00:00 2001 From: default Date: Sat, 22 Mar 2025 08:50:08 +0100 Subject: Filter out block instances from inbox_list(). --- data.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index ce040dd..a192830 100644 --- a/data.c +++ b/data.c @@ -2619,10 +2619,9 @@ xs_list *inbox_list(void) xs_list *ibl = xs_list_new(); xs *spec = xs_fmt("%s/inbox/" "*", srv_basedir); xs *files = xs_glob(spec, 0, 0); - xs_list *p = files; const xs_val *v; - while (xs_list_iter(&p, &v)) { + xs_list_foreach(files, v) { FILE *f; if ((f = fopen(v, "r")) != NULL) { @@ -2630,7 +2629,9 @@ xs_list *inbox_list(void) if (line && *line) { line = xs_strip_i(line); - ibl = xs_list_append(ibl, line); + + if (!is_instance_blocked(line)) + ibl = xs_list_append(ibl, line); } fclose(f); -- 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 'data.c') 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 'data.c') 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 'data.c') 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