From 1763e3347ed2921d9f8cd774e612578351e0719e Mon Sep 17 00:00:00 2001 From: default Date: Sun, 6 Aug 2023 18:40:50 +0200 Subject: [PATCH] Added support for limiting followed users. --- data.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ snac.h | 7 ++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/data.c b/data.c index d0ed7b9..61438b7 100644 --- a/data.c +++ b/data.c @@ -1500,6 +1500,50 @@ int actor_get(snac *snac1, const char *actor, xs_dict **data) } +/** user limiting (announce blocks) **/ + +int limited(snac *user, const char *id, int cmd) +/* announce messages from a followed (0: check, 1: limit; 2: unlimit) */ +{ + int ret = 0; + xs *fn = xs_fmt("%s/limited/", user->basedir); + mkdirx(fn); + + xs *md5 = xs_md5_hex(id, strlen(id)); + fn = xs_str_cat(fn, md5); + + switch (cmd) { + case 0: /** check **/ + ret = !!(mtime(fn) > 0.0); + break; + + case 1: /** limit **/ + if (mtime(fn) > 0.0) + ret = -1; + else { + FILE *f; + + if ((f = fopen(fn, "w")) != NULL) { + fprintf(f, "%s\n", id); + fclose(f); + } + else + ret = -2; + } + break; + + case 2: /** unlimit **/ + if (mtime(fn) > 0.0) + ret = unlink(fn); + else + ret = -1; + break; + } + + return ret; +} + + /** static data **/ xs_str *_static_fn(snac *snac, const char *id) diff --git a/snac.h b/snac.h index 2b60165..4652827 100644 --- a/snac.h +++ b/snac.h @@ -1,7 +1,7 @@ /* snac - A simple, minimalistic ActivityPub instance */ /* copyright (c) 2022 - 2023 grunfink et al. / MIT license */ -#define VERSION "2.39" +#define VERSION "2.40-dev" #define USER_AGENT "snac/" VERSION @@ -132,6 +132,11 @@ int unpin(snac *user, const char *id); int is_pinned(snac *user, const char *id); xs_list *pinned_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) +#define unlimit(user, id) limited((user), (id), 2) + void hide(snac *snac, const char *id); int is_hidden(snac *snac, const char *id);