commit 7419724

grunfink  ·  2026-09-10 13:38:08 +0000 UTC
parent e29f2d0
Added support for cool users.
3 files changed,  +73, -0
M data.c
M main.c
M snac.h
M data.c
+47, -0
 1@@ -2400,6 +2400,53 @@ int limited(snac *user, const char *id, snac_op op)
 2 }
 3 
 4 
 5+/** cool users **/
 6+
 7+int cool(snac *user, const char *id, snac_op op)
 8+/* cool users (those users whose posts are notified) */
 9+{
10+    int ret = 0;
11+    xs *dir = xs_fmt("%s/cool", user->basedir);
12+    xs *md5 = xs_md5_hex(id, strlen(id));
13+    xs *fn  = xs_fmt("%s/%s", dir, md5);
14+
15+    switch (op) {
16+    case OP_CHECK: /** check **/
17+        ret = !!(mtime(fn) > 0.0);
18+        break;
19+
20+    case OP_ADD: /** limit **/
21+        mkdirx(dir);
22+
23+        if (mtime(fn) > 0.0)
24+            ret = -1;
25+        else {
26+            FILE *f;
27+
28+            if ((f = fopen(fn, "w")) != NULL) {
29+                fprintf(f, "%s\n", id);
30+                fclose(f);
31+            }
32+            else
33+                ret = -2;
34+        }
35+        break;
36+
37+    case OP_DEL: /** unlimit **/
38+        if (mtime(fn) > 0.0)
39+            ret = unlink(fn);
40+        else
41+            ret = -1;
42+        break;
43+
44+    default:
45+        break;
46+    }
47+
48+    return ret;
49+}
50+
51+
52 /** tag indexing **/
53 
54 void tag_index(const char *id, const xs_dict *obj)
M main.c
+24, -0
 1@@ -60,6 +60,8 @@ int usage(const char *cmd)
 2         "unblock {basedir} {instance_url}     Unblocks a full instance\n"
 3         "limit {basedir} {uid} {actor}        Limits an actor (drops their announces)\n"
 4         "unlimit {basedir} {uid} {actor}      Unlimits an actor\n"
 5+        "cool {basedir} {uid} {actor}         Mark an actor as cool (notify whenever they post)\n"
 6+        "uncool {basedir} {uid} {actor}       Actor is no longer cool\n"
 7         "muted {basedir} {uid}                Lists the muted actors\n"
 8         "unmute {basedir} {uid} {actor}       Unmutes a previously muted actor\n"
 9         "verify_links {basedir} {uid}         Verifies a user's links (in the metadata)\n"
10@@ -637,6 +639,28 @@ int main(int argc, char *argv[])
11         return 0;
12     }
13 
14+    if (strcmp(cmd, "cool") == 0) { /** **/
15+        int ret;
16+
17+        if ((ret = cool(&snac, url, OP_ADD)) == 0)
18+            snac_log(&snac, xs_fmt("posts from actor %s will now be notified", url));
19+        else
20+            snac_log(&snac, xs_fmt("error marking actor %s as cool (%d)", url, ret));
21+
22+        return 0;
23+    }
24+
25+    if (strcmp(cmd, "uncool") == 0) { /** **/
26+        int ret;
27+
28+        if ((ret = cool(&snac, url, OP_DEL)) == 0)
29+            snac_log(&snac, xs_fmt("posts from actor %s will no longer be notified", url));
30+        else
31+            snac_log(&snac, xs_fmt("error unmarking actor %s as cool (%d)", url, ret));
32+
33+        return 0;
34+    }
35+
36     if (strcmp(cmd, "unmute") == 0) { /** **/
37         if (is_muted(&snac, url)) {
38             unmute(&snac, url);
M snac.h
+2, -0
1@@ -252,6 +252,8 @@ int limited(snac *user, const char *id, snac_op);
2 #define limit(user, id) limited((user), (id), OP_ADD)
3 #define unlimit(user, id) limited((user), (id), OP_DEL)
4 
5+int cool(snac *user, const char *id, snac_op op);
6+
7 void hide(snac *snac, const char *id);
8 int is_hidden(snac *snac, const char *id);
9 int unhide(snac *user, const char *id);