mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-12-26 01:03:37 +00:00
New pinning in data storage.
This commit is contained in:
parent
15684721c3
commit
3559a0f1f2
2 changed files with 55 additions and 0 deletions
50
data.c
50
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));
|
||||
|
|
5
snac.h
5
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue