diff options
| author | 2022-09-20 11:31:56 +0200 | |
|---|---|---|
| committer | 2022-09-20 11:31:56 +0200 | |
| commit | 591613a49e23af913aebcaa0a205ed425a987717 (patch) | |
| tree | ea7af24ab173ae8ed16a1cf11db4a51c1e170709 /data.c | |
| parent | More timeline work. (diff) | |
| download | snac2-591613a49e23af913aebcaa0a205ed425a987717.tar.gz snac2-591613a49e23af913aebcaa0a205ed425a987717.tar.xz snac2-591613a49e23af913aebcaa0a205ed425a987717.zip | |
Add following code.
Diffstat (limited to 'data.c')
| -rw-r--r-- | data.c | 51 |
1 files changed, 51 insertions, 0 deletions
| @@ -426,3 +426,54 @@ void timeline_add(snac *snac, char *id, char *msg, char *parent) | |||
| 426 | snac_debug(snac, 1, xs_fmt("timeline_add (local) %s %s", id, lfn)); | 426 | snac_debug(snac, 1, xs_fmt("timeline_add (local) %s %s", id, lfn)); |
| 427 | } | 427 | } |
| 428 | } | 428 | } |
| 429 | |||
| 430 | |||
| 431 | d_char *_following_fn(snac *snac, char *actor) | ||
| 432 | { | ||
| 433 | xs *md5 = xs_md5_hex(actor, strlen(actor)); | ||
| 434 | return xs_fmt("%s/following/%s.json", snac->basedir, md5); | ||
| 435 | } | ||
| 436 | |||
| 437 | |||
| 438 | int following_add(snac *snac, char *actor, char *msg) | ||
| 439 | /* adds to the following list */ | ||
| 440 | { | ||
| 441 | int ret = 201; /* created */ | ||
| 442 | xs *fn = _following_fn(snac, actor); | ||
| 443 | FILE *f; | ||
| 444 | |||
| 445 | if ((f = fopen(fn, "w")) != NULL) { | ||
| 446 | xs *j = xs_json_dumps_pp(msg, 4); | ||
| 447 | |||
| 448 | fwrite(j, 1, strlen(j), f); | ||
| 449 | fclose(f); | ||
| 450 | } | ||
| 451 | else | ||
| 452 | ret = 500; | ||
| 453 | |||
| 454 | snac_debug(snac, 2, xs_fmt("following_add %s %s", actor, fn)); | ||
| 455 | |||
| 456 | return ret; | ||
| 457 | } | ||
| 458 | |||
| 459 | |||
| 460 | int following_del(snac *snac, char *actor) | ||
| 461 | /* someone is no longer following us */ | ||
| 462 | { | ||
| 463 | xs *fn = _following_fn(snac, actor); | ||
| 464 | |||
| 465 | unlink(fn); | ||
| 466 | |||
| 467 | snac_debug(snac, 2, xs_fmt("following_del %s %s", actor, fn)); | ||
| 468 | |||
| 469 | return 200; | ||
| 470 | } | ||
| 471 | |||
| 472 | |||
| 473 | int following_check(snac *snac, char *actor) | ||
| 474 | /* checks if someone is following us */ | ||
| 475 | { | ||
| 476 | xs *fn = _following_fn(snac, actor); | ||
| 477 | |||
| 478 | return !!(mtime(fn) != 0.0); | ||
| 479 | } | ||