From 455352850748dc0b1bba7884c3a164dfe3e59614 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 24 Nov 2022 09:39:16 +0100 Subject: [PATCH] New API for hidden threads. --- data.c | 31 +++++++++++++++++++++++++++++++ snac.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/data.c b/data.c index e147912..c1c616d 100644 --- a/data.c +++ b/data.c @@ -1106,6 +1106,37 @@ int is_muted(snac *snac, char *actor) } +d_char *_hidden_fn(snac *snac, const char *id) +{ + xs *md5 = xs_md5_hex(id, strlen(id)); + return xs_fmt("%s/hidden/%s.json", snac->basedir, md5); +} + + +void hide(snac *snac, const char *id) +/* hides a message tree */ +{ + xs *fn = _hidden_fn(snac, id); + FILE *f; + + if ((f = fopen(fn, "w")) != NULL) { + fprintf(f, "%s\n", id); + fclose(f); + + snac_debug(snac, 2, xs_fmt("hidden %s %s", id, fn)); + } +} + + +int is_hidden(snac *snac, const char *id) +/* check is id is hidden */ +{ + xs *fn = _hidden_fn(snac, id); + + return !!(mtime(fn) != 0.0); +} + + int actor_add(snac *snac, const char *actor, d_char *msg) /* adds an actor */ { diff --git a/snac.h b/snac.h index be0f6a3..565d357 100644 --- a/snac.h +++ b/snac.h @@ -85,6 +85,9 @@ void mute(snac *snac, char *actor); void unmute(snac *snac, char *actor); int is_muted(snac *snac, char *actor); +void hide(snac *snac, const char *id); +int is_hidden(snac *snac, const char *id); + int actor_add(snac *snac, const char *actor, d_char *msg); int actor_get(snac *snac, const char *actor, d_char **data);