diff options
author | default <nobody@localhost> | 2023-08-06 18:40:50 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2023-08-06 18:40:50 +0200 |
commit | 1763e3347ed2921d9f8cd774e612578351e0719e (patch) | |
tree | f12dc46a13962902bc5d8922971d730e1a7e7aea /data.c | |
parent | 66e34b3a4375cf25cb100592250042d8fa505f7b (diff) |
Added support for limiting followed users.
Diffstat (limited to 'data.c')
-rw-r--r-- | data.c | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -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) |