summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'data.c')
-rw-r--r--data.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/data.c b/data.c
index f26da49..70bd031 100644
--- a/data.c
+++ b/data.c
@@ -2041,7 +2041,7 @@ xs_str *_hidden_fn(snac *snac, const char *id)
2041 2041
2042 2042
2043void hide(snac *snac, const char *id) 2043void hide(snac *snac, const char *id)
2044/* hides a message tree */ 2044/* hides an object and its children (if it's a post) */
2045{ 2045{
2046 xs *fn = _hidden_fn(snac, id); 2046 xs *fn = _hidden_fn(snac, id);
2047 FILE *f; 2047 FILE *f;
@@ -2081,6 +2081,14 @@ int is_hidden(snac *snac, const char *id)
2081} 2081}
2082 2082
2083 2083
2084int unhide(snac *user, const char *id)
2085/* unhides an object */
2086{
2087 xs *fn = _hidden_fn(user, id);
2088 return unlink(fn);
2089}
2090
2091
2084int actor_add(const char *actor, const xs_dict *msg) 2092int actor_add(const char *actor, const xs_dict *msg)
2085/* adds an actor */ 2093/* adds an actor */
2086{ 2094{
@@ -2976,11 +2984,14 @@ xs_list *content_search(snac *user, const char *regex,
2976 xs *c = xs_str_new(NULL); 2984 xs *c = xs_str_new(NULL);
2977 const char *content = xs_dict_get(post, "content"); 2985 const char *content = xs_dict_get(post, "content");
2978 const char *name = xs_dict_get(post, "name"); 2986 const char *name = xs_dict_get(post, "name");
2987 const char *atto = get_atto(post);
2979 2988
2980 if (!xs_is_null(content)) 2989 if (!xs_is_null(content))
2981 c = xs_str_cat(c, content); 2990 c = xs_str_cat(c, content);
2982 if (!xs_is_null(name)) 2991 if (!xs_is_null(name))
2983 c = xs_str_cat(c, " ", name); 2992 c = xs_str_cat(c, " ", name);
2993 if (!xs_is_null(atto))
2994 c = xs_str_cat(c, " ", atto);
2984 2995
2985 /* add alt-texts from attachments */ 2996 /* add alt-texts from attachments */
2986 const xs_list *atts = xs_dict_get(post, "attachment"); 2997 const xs_list *atts = xs_dict_get(post, "attachment");
@@ -3840,6 +3851,43 @@ void purge_server(void)
3840} 3851}
3841 3852
3842 3853
3854void delete_purged_posts(snac *user, int days)
3855/* enqueues Delete activities for local purged messages */
3856{
3857 if (days == 0)
3858 return;
3859
3860 time_t mt = time(NULL) - days * 24 * 3600;
3861 xs *spec = xs_fmt("%s/public/" "*.json", user->basedir);
3862 xs *list = xs_glob(spec, 0, 0);
3863 const char *v;
3864
3865 xs_list_foreach(list, v) {
3866 if (mtime(v) < mt) {
3867 /* to be purged; is it a Note by us? */
3868 FILE *f;
3869
3870 if ((f = fopen(v, "r")) != NULL) {
3871 xs *msg = xs_json_load(f);
3872 fclose(f);
3873
3874 if (xs_is_dict(msg)) {
3875 const char *id = xs_dict_get(msg, "id");
3876
3877 if (xs_is_string(id) && xs_startswith(id, user->actor)) {
3878 xs *d_msg = msg_delete(user, id);
3879
3880 enqueue_message(user, d_msg);
3881
3882 snac_log(user, xs_fmt("enqueued Delete for purged message %s", id));
3883 }
3884 }
3885 }
3886 }
3887 }
3888}
3889
3890
3843void purge_user(snac *snac) 3891void purge_user(snac *snac)
3844/* do the purge for this user */ 3892/* do the purge for this user */
3845{ 3893{
@@ -3863,6 +3911,9 @@ void purge_user(snac *snac)
3863 pub_days = user_days; 3911 pub_days = user_days;
3864 } 3912 }
3865 3913
3914 if (xs_is_true(xs_dict_get(srv_config, "propagate_local_purge")))
3915 delete_purged_posts(snac, pub_days);
3916
3866 _purge_user_subdir(snac, "hidden", priv_days); 3917 _purge_user_subdir(snac, "hidden", priv_days);
3867 _purge_user_subdir(snac, "private", priv_days); 3918 _purge_user_subdir(snac, "private", priv_days);
3868 3919