diff options
author | default <nobody@localhost> | 2023-06-28 20:26:59 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2023-06-28 20:26:59 +0200 |
commit | 3559a0f1f2dd7fc3cb8c430e53a197ac94e6a51a (patch) | |
tree | 5c06ae94a983edef040d61df7d7ba6178e3c0cba /data.c | |
parent | 15684721c36d36b2dfd57a2dabbf19a8e53850b7 (diff) |
New pinning in data storage.
Diffstat (limited to 'data.c')
-rw-r--r-- | data.c | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -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)); |