Ver Fonte

Added support for cool users.

grunfink há 1 semana atrás
pai
commit
74197248f6
3 ficheiros alterados com 73 adições e 0 exclusões
  1. 47 0
      data.c
  2. 24 0
      main.c
  3. 2 0
      snac.h

+ 47 - 0
data.c

@@ -2400,6 +2400,53 @@ int limited(snac *user, const char *id, snac_op op)
 }
 
 
+/** cool users **/
+
+int cool(snac *user, const char *id, snac_op op)
+/* cool users (those users whose posts are notified) */
+{
+    int ret = 0;
+    xs *dir = xs_fmt("%s/cool", user->basedir);
+    xs *md5 = xs_md5_hex(id, strlen(id));
+    xs *fn  = xs_fmt("%s/%s", dir, md5);
+
+    switch (op) {
+    case OP_CHECK: /** check **/
+        ret = !!(mtime(fn) > 0.0);
+        break;
+
+    case OP_ADD: /** limit **/
+        mkdirx(dir);
+
+        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 OP_DEL: /** unlimit **/
+        if (mtime(fn) > 0.0)
+            ret = unlink(fn);
+        else
+            ret = -1;
+        break;
+
+    default:
+        break;
+    }
+
+    return ret;
+}
+
+
 /** tag indexing **/
 
 void tag_index(const char *id, const xs_dict *obj)

+ 24 - 0
main.c

@@ -60,6 +60,8 @@ int usage(const char *cmd)
         "unblock {basedir} {instance_url}     Unblocks a full instance\n"
         "limit {basedir} {uid} {actor}        Limits an actor (drops their announces)\n"
         "unlimit {basedir} {uid} {actor}      Unlimits an actor\n"
+        "cool {basedir} {uid} {actor}         Mark an actor as cool (notify whenever they post)\n"
+        "uncool {basedir} {uid} {actor}       Actor is no longer cool\n"
         "muted {basedir} {uid}                Lists the muted actors\n"
         "unmute {basedir} {uid} {actor}       Unmutes a previously muted actor\n"
         "verify_links {basedir} {uid}         Verifies a user's links (in the metadata)\n"
@@ -637,6 +639,28 @@ int main(int argc, char *argv[])
         return 0;
     }
 
+    if (strcmp(cmd, "cool") == 0) { /** **/
+        int ret;
+
+        if ((ret = cool(&snac, url, OP_ADD)) == 0)
+            snac_log(&snac, xs_fmt("posts from actor %s will now be notified", url));
+        else
+            snac_log(&snac, xs_fmt("error marking actor %s as cool (%d)", url, ret));
+
+        return 0;
+    }
+
+    if (strcmp(cmd, "uncool") == 0) { /** **/
+        int ret;
+
+        if ((ret = cool(&snac, url, OP_DEL)) == 0)
+            snac_log(&snac, xs_fmt("posts from actor %s will no longer be notified", url));
+        else
+            snac_log(&snac, xs_fmt("error unmarking actor %s as cool (%d)", url, ret));
+
+        return 0;
+    }
+
     if (strcmp(cmd, "unmute") == 0) { /** **/
         if (is_muted(&snac, url)) {
             unmute(&snac, url);

+ 2 - 0
snac.h

@@ -252,6 +252,8 @@ int limited(snac *user, const char *id, snac_op);
 #define limit(user, id) limited((user), (id), OP_ADD)
 #define unlimit(user, id) limited((user), (id), OP_DEL)
 
+int cool(snac *user, const char *id, snac_op op);
+
 void hide(snac *snac, const char *id);
 int is_hidden(snac *snac, const char *id);
 int unhide(snac *user, const char *id);