From 92f44e07cf24a2a25421a0ee28b5dece10f6511a Mon Sep 17 00:00:00 2001 From: grunfink Date: Fri, 25 Jul 2025 18:44:04 +0200 Subject: New function delete_purged_posts(). --- data.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'data.c') diff --git a/data.c b/data.c index f26da49..e6b7333 100644 --- a/data.c +++ b/data.c @@ -3840,6 +3840,43 @@ void purge_server(void) } +void delete_purged_posts(snac *user, int days) +/* enqueues Delete activities for local purged messages */ +{ + if (days == 0) + return; + + time_t mt = time(NULL) - days * 24 * 3600; + xs *spec = xs_fmt("%s/public/" "*.json", user->basedir); + xs *list = xs_glob(spec, 0, 0); + const char *v; + + xs_list_foreach(list, v) { + if (mtime(v) < mt) { + /* to be purged; is it a Note by us? */ + FILE *f; + + if ((f = fopen(v, "r")) != NULL) { + xs *msg = xs_json_load(f); + fclose(f); + + if (xs_is_dict(msg)) { + const char *id = xs_dict_get(msg, "id"); + + if (xs_is_string(id) && xs_startswith(id, user->actor)) { + xs *d_msg = msg_delete(user, id); + + enqueue_message(user, d_msg); + + snac_log(user, xs_fmt("enqueued Delete for purged message %s", id)); + } + } + } + } + } +} + + void purge_user(snac *snac) /* do the purge for this user */ { @@ -3863,6 +3900,8 @@ void purge_user(snac *snac) pub_days = user_days; } + delete_purged_posts(snac, pub_days); + _purge_user_subdir(snac, "hidden", priv_days); _purge_user_subdir(snac, "private", priv_days); -- cgit v1.2.3