mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 14:35:04 +00:00
Added support for limiting followed users.
This commit is contained in:
parent
66e34b3a43
commit
1763e3347e
2 changed files with 50 additions and 1 deletions
44
data.c
44
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)
|
||||
|
|
7
snac.h
7
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue