diff options
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 53 |
1 files changed, 52 insertions, 1 deletions
@@ -2041,7 +2041,7 @@ xs_str *_hidden_fn(snac *snac, const char *id) void hide(snac *snac, const char *id) -/* hides a message tree */ +/* hides an object and its children (if it's a post) */ { xs *fn = _hidden_fn(snac, id); FILE *f; @@ -2081,6 +2081,14 @@ int is_hidden(snac *snac, const char *id) } +int unhide(snac *user, const char *id) +/* unhides an object */ +{ + xs *fn = _hidden_fn(user, id); + return unlink(fn); +} + + int actor_add(const char *actor, const xs_dict *msg) /* adds an actor */ { @@ -2976,11 +2984,14 @@ xs_list *content_search(snac *user, const char *regex, xs *c = xs_str_new(NULL); const char *content = xs_dict_get(post, "content"); const char *name = xs_dict_get(post, "name"); + const char *atto = get_atto(post); if (!xs_is_null(content)) c = xs_str_cat(c, content); if (!xs_is_null(name)) c = xs_str_cat(c, " ", name); + if (!xs_is_null(atto)) + c = xs_str_cat(c, " ", atto); /* add alt-texts from attachments */ const xs_list *atts = xs_dict_get(post, "attachment"); @@ -3840,6 +3851,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 +3911,9 @@ void purge_user(snac *snac) pub_days = user_days; } + if (xs_is_true(xs_dict_get(srv_config, "propagate_local_purge"))) + delete_purged_posts(snac, pub_days); + _purge_user_subdir(snac, "hidden", priv_days); _purge_user_subdir(snac, "private", priv_days); |