diff options
| author | 2023-06-28 20:52:09 +0200 | |
|---|---|---|
| committer | 2023-06-28 20:52:09 +0200 | |
| commit | af180685bdb430e90e3c4057c87595520ee385b4 (patch) | |
| tree | 65db25c5b4d5f273224a61109e18554ede0997d2 | |
| parent | Also purge pinned.idx. (diff) | |
| download | snac2-af180685bdb430e90e3c4057c87595520ee385b4.tar.gz snac2-af180685bdb430e90e3c4057c87595520ee385b4.tar.xz snac2-af180685bdb430e90e3c4057c87595520ee385b4.zip | |
Added some error control to pinning.
| -rw-r--r-- | data.c | 22 | ||||
| -rw-r--r-- | main.c | 22 | ||||
| -rw-r--r-- | snac.h | 2 |
3 files changed, 35 insertions, 11 deletions
| @@ -1352,7 +1352,7 @@ int is_muted(snac *snac, const char *actor) | |||
| 1352 | xs_str *_pinned_fn(snac *user, const char *id) | 1352 | xs_str *_pinned_fn(snac *user, const char *id) |
| 1353 | { | 1353 | { |
| 1354 | xs *md5 = xs_md5_hex(id, strlen(id)); | 1354 | xs *md5 = xs_md5_hex(id, strlen(id)); |
| 1355 | return xs_fmt("%s/pinned/%s", user->basedir, md5); | 1355 | return xs_fmt("%s/pinned/%s.json", user->basedir, md5); |
| 1356 | } | 1356 | } |
| 1357 | 1357 | ||
| 1358 | 1358 | ||
| @@ -1367,26 +1367,28 @@ int is_pinned(snac *user, const char *id) | |||
| 1367 | int pin(snac *user, const char *id) | 1367 | int pin(snac *user, const char *id) |
| 1368 | /* pins a message */ | 1368 | /* pins a message */ |
| 1369 | { | 1369 | { |
| 1370 | int ret = 0; | 1370 | int ret = -2; |
| 1371 | 1371 | ||
| 1372 | if (xs_startswith(id, user->actor)) { | 1372 | if (xs_startswith(id, user->actor)) { |
| 1373 | /* create the subfolder, if it does not exist */ | 1373 | if (is_pinned(user, id)) |
| 1374 | xs *fn = xs_fmt("%s/pinned/", user->basedir); | 1374 | ret = -3; |
| 1375 | mkdirx(fn); | 1375 | else { |
| 1376 | 1376 | /* create the subfolder, if it does not exist */ | |
| 1377 | object_user_cache_add(user, id, "pinned"); | 1377 | xs *fn = xs_fmt("%s/pinned/", user->basedir); |
| 1378 | mkdirx(fn); | ||
| 1378 | 1379 | ||
| 1379 | ret = 1; | 1380 | ret = object_user_cache_add(user, id, "pinned"); |
| 1381 | } | ||
| 1380 | } | 1382 | } |
| 1381 | 1383 | ||
| 1382 | return ret; | 1384 | return ret; |
| 1383 | } | 1385 | } |
| 1384 | 1386 | ||
| 1385 | 1387 | ||
| 1386 | void unpin(snac *user, const char *id) | 1388 | int unpin(snac *user, const char *id) |
| 1387 | /* unpin a message */ | 1389 | /* unpin a message */ |
| 1388 | { | 1390 | { |
| 1389 | object_user_cache_del(user, id, "pinned"); | 1391 | return object_user_cache_del(user, id, "pinned"); |
| 1390 | } | 1392 | } |
| 1391 | 1393 | ||
| 1392 | 1394 | ||
| @@ -31,6 +31,8 @@ int usage(void) | |||
| 31 | printf("resetpwd {basedir} {uid} Resets the password of a user\n"); | 31 | printf("resetpwd {basedir} {uid} Resets the password of a user\n"); |
| 32 | printf("ping {basedir} {uid} {actor} Pings an actor\n"); | 32 | printf("ping {basedir} {uid} {actor} Pings an actor\n"); |
| 33 | printf("webfinger_s {basedir} {uid} {actor} Queries about an actor (@user@host or actor url)\n"); | 33 | printf("webfinger_s {basedir} {uid} {actor} Queries about an actor (@user@host or actor url)\n"); |
| 34 | printf("pin {basedir} {uid} {msg_url} Pins a message\n"); | ||
| 35 | printf("unpin {basedir} {uid} {msg_url} Unpins a message\n"); | ||
| 34 | /* printf("question {basedir} {uid} 'opts' Generates a poll (;-separated opts)\n");*/ | 36 | /* printf("question {basedir} {uid} 'opts' Generates a poll (;-separated opts)\n");*/ |
| 35 | 37 | ||
| 36 | return 1; | 38 | return 1; |
| @@ -269,6 +271,26 @@ int main(int argc, char *argv[]) | |||
| 269 | return 0; | 271 | return 0; |
| 270 | } | 272 | } |
| 271 | 273 | ||
| 274 | if (strcmp(cmd, "pin") == 0) { /** **/ | ||
| 275 | int ret = pin(&snac, url); | ||
| 276 | if (ret < 0) { | ||
| 277 | fprintf(stderr, "error pinning %s %d\n", url, ret); | ||
| 278 | return 1; | ||
| 279 | } | ||
| 280 | |||
| 281 | return 0; | ||
| 282 | } | ||
| 283 | |||
| 284 | if (strcmp(cmd, "unpin") == 0) { /** **/ | ||
| 285 | int ret = unpin(&snac, url); | ||
| 286 | if (ret < 0) { | ||
| 287 | fprintf(stderr, "error unpinning %s %d\n", url, ret); | ||
| 288 | return 1; | ||
| 289 | } | ||
| 290 | |||
| 291 | return 0; | ||
| 292 | } | ||
| 293 | |||
| 272 | if (strcmp(cmd, "question") == 0) { /** **/ | 294 | if (strcmp(cmd, "question") == 0) { /** **/ |
| 273 | int end_secs = 5 * 60; | 295 | int end_secs = 5 * 60; |
| 274 | xs *opts = xs_split(url, ";"); | 296 | xs *opts = xs_split(url, ";"); |
| @@ -127,7 +127,7 @@ void unmute(snac *snac, const char *actor); | |||
| 127 | int is_muted(snac *snac, const char *actor); | 127 | int is_muted(snac *snac, const char *actor); |
| 128 | 128 | ||
| 129 | int pin(snac *user, const char *id); | 129 | int pin(snac *user, const char *id); |
| 130 | void unpin(snac *user, const char *id); | 130 | int unpin(snac *user, const char *id); |
| 131 | int is_pinned(snac *user, const char *id); | 131 | int is_pinned(snac *user, const char *id); |
| 132 | xs_list *pinned_list(snac *user); | 132 | xs_list *pinned_list(snac *user); |
| 133 | 133 | ||