diff options
| author | 2022-11-16 17:28:20 +0100 | |
|---|---|---|
| committer | 2022-11-16 17:28:20 +0100 | |
| commit | 789aec5d7fb040b0ff398375243f9ab4099d348f (patch) | |
| tree | 8f94d075d1d63f5eb7d941e8666e25348f565e4e | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | penes-snac2-789aec5d7fb040b0ff398375243f9ab4099d348f.tar.gz penes-snac2-789aec5d7fb040b0ff398375243f9ab4099d348f.tar.xz penes-snac2-789aec5d7fb040b0ff398375243f9ab4099d348f.zip | |
Drop incoming messages that has their parent hidden.
| -rw-r--r-- | data.c | 61 |
1 files changed, 38 insertions, 23 deletions
| @@ -420,12 +420,40 @@ d_char *_timeline_new_fn(snac *snac, char *id) | |||
| 420 | } | 420 | } |
| 421 | 421 | ||
| 422 | 422 | ||
| 423 | void _timeline_write(snac *snac, char *id, char *msg, char *parent, char *referrer) | 423 | int _timeline_write(snac *snac, char *id, char *msg, char *parent, char *referrer) |
| 424 | /* writes a timeline entry and refreshes the ancestors */ | 424 | /* writes a timeline entry and refreshes the ancestors */ |
| 425 | { | 425 | { |
| 426 | xs *fn = _timeline_new_fn(snac, id); | 426 | xs *fn = _timeline_new_fn(snac, id); |
| 427 | xs *pfn = NULL; | ||
| 428 | xs *p_msg = NULL; | ||
| 427 | FILE *f; | 429 | FILE *f; |
| 428 | 430 | ||
| 431 | if (!xs_is_null(parent)) { | ||
| 432 | /* get the parent */ | ||
| 433 | pfn = _timeline_find_fn(snac, parent); | ||
| 434 | |||
| 435 | if (pfn != NULL && (f = fopen(pfn, "r")) != NULL) { | ||
| 436 | xs *j; | ||
| 437 | char *v; | ||
| 438 | |||
| 439 | j = xs_readall(f); | ||
| 440 | fclose(f); | ||
| 441 | |||
| 442 | p_msg = xs_json_loads(j); | ||
| 443 | |||
| 444 | if ((v = xs_dict_get(p_msg, "_snac")) != NULL) { | ||
| 445 | /* is parent hidden? */ | ||
| 446 | if ((v = xs_dict_get(v, "hidden")) && xs_type(v) == XSTYPE_TRUE) { | ||
| 447 | snac_debug(snac, 1, | ||
| 448 | xs_fmt("_timeline_write dropping child of hidden parent %s", id)); | ||
| 449 | |||
| 450 | return 0; | ||
| 451 | } | ||
| 452 | } | ||
| 453 | } | ||
| 454 | } | ||
| 455 | |||
| 456 | /* write the message */ | ||
| 429 | if ((f = fopen(fn, "w")) != NULL) { | 457 | if ((f = fopen(fn, "w")) != NULL) { |
| 430 | xs *j = xs_json_dumps_pp(msg, 4); | 458 | xs *j = xs_json_dumps_pp(msg, 4); |
| 431 | 459 | ||
| @@ -445,23 +473,8 @@ void _timeline_write(snac *snac, char *id, char *msg, char *parent, char *referr | |||
| 445 | snac_debug(snac, 1, xs_fmt("_timeline_write (local) %s %s", id, lfn)); | 473 | snac_debug(snac, 1, xs_fmt("_timeline_write (local) %s %s", id, lfn)); |
| 446 | } | 474 | } |
| 447 | 475 | ||
| 448 | if (!xs_is_null(parent)) { | 476 | if (p_msg != NULL) { |
| 449 | /* update the parent, adding this id to its children list */ | 477 | /* update the parent, adding this id to its children list */ |
| 450 | xs *pfn = _timeline_find_fn(snac, parent); | ||
| 451 | xs *p_msg = NULL; | ||
| 452 | |||
| 453 | if (pfn != NULL && (f = fopen(pfn, "r")) != NULL) { | ||
| 454 | xs *j; | ||
| 455 | |||
| 456 | j = xs_readall(f); | ||
| 457 | fclose(f); | ||
| 458 | |||
| 459 | p_msg = xs_json_loads(j); | ||
| 460 | } | ||
| 461 | |||
| 462 | if (p_msg == NULL) | ||
| 463 | return; | ||
| 464 | |||
| 465 | xs *meta = xs_dup(xs_dict_get(p_msg, "_snac")); | 478 | xs *meta = xs_dup(xs_dict_get(p_msg, "_snac")); |
| 466 | xs *children = xs_dup(xs_dict_get(meta, "children")); | 479 | xs *children = xs_dup(xs_dict_get(meta, "children")); |
| 467 | 480 | ||
| @@ -499,7 +512,7 @@ void _timeline_write(snac *snac, char *id, char *msg, char *parent, char *referr | |||
| 499 | } | 512 | } |
| 500 | } | 513 | } |
| 501 | else | 514 | else |
| 502 | return; | 515 | return 0; |
| 503 | 516 | ||
| 504 | /* now iterate all parents up, just renaming the files */ | 517 | /* now iterate all parents up, just renaming the files */ |
| 505 | xs *grampa = xs_dup(xs_dict_get(meta, "parent")); | 518 | xs *grampa = xs_dup(xs_dict_get(meta, "parent")); |
| @@ -544,6 +557,8 @@ void _timeline_write(snac *snac, char *id, char *msg, char *parent, char *referr | |||
| 544 | } | 557 | } |
| 545 | } | 558 | } |
| 546 | } | 559 | } |
| 560 | |||
| 561 | return 1; | ||
| 547 | } | 562 | } |
| 548 | 563 | ||
| 549 | 564 | ||
| @@ -551,6 +566,7 @@ int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer | |||
| 551 | /* adds a message to the timeline */ | 566 | /* adds a message to the timeline */ |
| 552 | { | 567 | { |
| 553 | xs *pfn = _timeline_find_fn(snac, id); | 568 | xs *pfn = _timeline_find_fn(snac, id); |
| 569 | int ret = 0; | ||
| 554 | 570 | ||
| 555 | if (pfn != NULL) { | 571 | if (pfn != NULL) { |
| 556 | snac_log(snac, xs_fmt("timeline_add refusing rewrite %s %s", id, pfn)); | 572 | snac_log(snac, xs_fmt("timeline_add refusing rewrite %s %s", id, pfn)); |
| @@ -578,15 +594,14 @@ int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer | |||
| 578 | 594 | ||
| 579 | msg = xs_dict_set(msg, "_snac", md); | 595 | msg = xs_dict_set(msg, "_snac", md); |
| 580 | 596 | ||
| 581 | _timeline_write(snac, id, msg, parent, referrer); | 597 | ret = _timeline_write(snac, id, msg, parent, referrer); |
| 582 | 598 | ||
| 583 | snac_debug(snac, 1, xs_fmt("timeline_add %s", id)); | 599 | snac_debug(snac, 1, xs_fmt("timeline_add %s %d", id, ret)); |
| 584 | 600 | ||
| 585 | return 1; | 601 | return ret; |
| 586 | } | 602 | } |
| 587 | 603 | ||
| 588 | 604 | ||
| 589 | |||
| 590 | void timeline_admire(snac *snac, char *id, char *admirer, int like) | 605 | void timeline_admire(snac *snac, char *id, char *admirer, int like) |
| 591 | /* updates a timeline entry with a new admiration */ | 606 | /* updates a timeline entry with a new admiration */ |
| 592 | { | 607 | { |