summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-08-06 18:40:50 +0200
committerdefault <nobody@localhost>2023-08-06 18:40:50 +0200
commit1763e3347ed2921d9f8cd774e612578351e0719e (patch)
treef12dc46a13962902bc5d8922971d730e1a7e7aea
parent66e34b3a4375cf25cb100592250042d8fa505f7b (diff)
Added support for limiting followed users.
-rw-r--r--data.c44
-rw-r--r--snac.h7
2 files changed, 50 insertions, 1 deletions
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);