mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-12-26 01:03:37 +00:00
Added some error control to pinning.
This commit is contained in:
parent
394240b9ba
commit
af180685bd
3 changed files with 35 additions and 11 deletions
22
data.c
22
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");
|
||||
}
|
||||
|
||||
|
||||
|
|
22
main.c
22
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, ";");
|
||||
|
|
2
snac.h
2
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue