diff --git a/data.c b/data.c index 7121649..481ccbb 100644 --- a/data.c +++ b/data.c @@ -1347,6 +1347,56 @@ int is_muted(snac *snac, const char *actor) } +/** pinning **/ + +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); +} + + +int is_pinned(snac *user, const char *id) +/* returns true if this note is pinned */ +{ + xs *fn = _pinned_fn(user, id); + return !!(mtime(fn) != 0.0); +} + + +int pin(snac *user, const char *id) +/* pins a message */ +{ + int ret = 0; + + if (xs_startswith(id, user->actor)) { + /* 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; + } + + return ret; +} + + +void unpin(snac *user, const char *id) +/* unpin a message */ +{ + object_user_cache_del(user, id, "pinned"); +} + + +xs_list *pinned_list(snac *user) +/* return the lists of pinned posts */ +{ + return object_user_cache_list(user, "pinned", XS_ALL); +} + + xs_str *_hidden_fn(snac *snac, const char *id) { xs *md5 = xs_md5_hex(id, strlen(id)); diff --git a/snac.h b/snac.h index 71160e7..3a2b2a7 100644 --- a/snac.h +++ b/snac.h @@ -126,6 +126,11 @@ void mute(snac *snac, const char *actor); 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 is_pinned(snac *user, const char *id); +xs_list *pinned_list(snac *user); + void hide(snac *snac, const char *id); int is_hidden(snac *snac, const char *id);