diff --git a/data.c b/data.c index 6436862..e3275cb 100644 --- a/data.c +++ b/data.c @@ -1352,7 +1352,7 @@ int is_muted(snac *snac, const char *actor) xs_str *_pinned_fn(snac *user, const char *id) { xs *md5 = xs_md5_hex(id, strlen(id)); - return xs_fmt("%s/pinned/%s", user->basedir, md5); + return xs_fmt("%s/pinned/%s.json", user->basedir, md5); } @@ -1367,26 +1367,28 @@ int is_pinned(snac *user, const char *id) int pin(snac *user, const char *id) /* pins a message */ { - int ret = 0; + int ret = -2; if (xs_startswith(id, user->actor)) { - /* create the subfolder, if it does not exist */ - xs *fn = xs_fmt("%s/pinned/", user->basedir); - mkdirx(fn); + if (is_pinned(user, id)) + ret = -3; + else { + /* create the subfolder, if it does not exist */ + xs *fn = xs_fmt("%s/pinned/", user->basedir); + mkdirx(fn); - object_user_cache_add(user, id, "pinned"); - - ret = 1; + ret = object_user_cache_add(user, id, "pinned"); + } } return ret; } -void unpin(snac *user, const char *id) +int unpin(snac *user, const char *id) /* unpin a message */ { - object_user_cache_del(user, id, "pinned"); + return object_user_cache_del(user, id, "pinned"); } diff --git a/main.c b/main.c index 97f47de..f33ad2f 100644 --- a/main.c +++ b/main.c @@ -31,6 +31,8 @@ int usage(void) printf("resetpwd {basedir} {uid} Resets the password of a user\n"); printf("ping {basedir} {uid} {actor} Pings an actor\n"); printf("webfinger_s {basedir} {uid} {actor} Queries about an actor (@user@host or actor url)\n"); + printf("pin {basedir} {uid} {msg_url} Pins a message\n"); + printf("unpin {basedir} {uid} {msg_url} Unpins a message\n"); /* printf("question {basedir} {uid} 'opts' Generates a poll (;-separated opts)\n");*/ return 1; @@ -269,6 +271,26 @@ int main(int argc, char *argv[]) return 0; } + if (strcmp(cmd, "pin") == 0) { /** **/ + int ret = pin(&snac, url); + if (ret < 0) { + fprintf(stderr, "error pinning %s %d\n", url, ret); + return 1; + } + + return 0; + } + + if (strcmp(cmd, "unpin") == 0) { /** **/ + int ret = unpin(&snac, url); + if (ret < 0) { + fprintf(stderr, "error unpinning %s %d\n", url, ret); + return 1; + } + + return 0; + } + if (strcmp(cmd, "question") == 0) { /** **/ int end_secs = 5 * 60; xs *opts = xs_split(url, ";"); diff --git a/snac.h b/snac.h index 3a2b2a7..5a26ec2 100644 --- a/snac.h +++ b/snac.h @@ -127,7 +127,7 @@ void unmute(snac *snac, const char *actor); int is_muted(snac *snac, const char *actor); int pin(snac *user, const char *id); -void unpin(snac *user, const char *id); +int unpin(snac *user, const char *id); int is_pinned(snac *user, const char *id); xs_list *pinned_list(snac *user);