summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
Diffstat (limited to 'html.c')
-rw-r--r--html.c142
1 files changed, 75 insertions, 67 deletions
diff --git a/html.c b/html.c
index 63b54c3..4c1ca79 100644
--- a/html.c
+++ b/html.c
@@ -386,7 +386,8 @@ d_char *html_entry_controls(snac *snac, d_char *os, char *msg, int num)
386{ 386{
387 char *id = xs_dict_get(msg, "id"); 387 char *id = xs_dict_get(msg, "id");
388 char *actor = xs_dict_get(msg, "attributedTo"); 388 char *actor = xs_dict_get(msg, "attributedTo");
389 char *meta = xs_dict_get(msg, "_snac"); 389 xs *likes = object_likes(id);
390 xs *boosts = object_announces(id);
390 391
391 xs *s = xs_str_new(NULL); 392 xs *s = xs_str_new(NULL);
392 xs *md5 = xs_md5_hex(id, strlen(id)); 393 xs *md5 = xs_md5_hex(id, strlen(id));
@@ -407,20 +408,14 @@ d_char *html_entry_controls(snac *snac, d_char *os, char *msg, int num)
407 s = xs_str_cat(s, s1); 408 s = xs_str_cat(s, s1);
408 } 409 }
409 410
410 { 411 if (xs_list_in(likes, snac->md5) == -1) {
411 char *l; 412 /* not already liked; add button */
412 413 s = html_button(s, "like", L("Like"));
413 l = xs_dict_get(meta, "liked_by"); 414 }
414 if (xs_list_in(l, snac->actor) == -1) {
415 /* not already liked; add button */
416 s = html_button(s, "like", L("Like"));
417 }
418 415
419 l = xs_dict_get(meta, "announced_by"); 416 if (strcmp(actor, snac->actor) == 0 || xs_list_in(boosts, snac->md5) == -1) {
420 if (strcmp(actor, snac->actor) == 0 || xs_list_in(l, snac->actor) == -1) { 417 /* not already boosted or us; add button */
421 /* not already boosted or us; add button */ 418 s = html_button(s, "boost", L("Boost"));
422 s = html_button(s, "boost", L("Boost"));
423 }
424 } 419 }
425 420
426 if (strcmp(actor, snac->actor) != 0) { 421 if (strcmp(actor, snac->actor) != 0) {
@@ -477,23 +472,20 @@ d_char *html_entry_controls(snac *snac, d_char *os, char *msg, int num)
477} 472}
478 473
479 474
480d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, int level, int *num) 475d_char *html_entry(snac *snac, d_char *os, char *msg, int local, int level, int *num)
481{ 476{
482 char *id = xs_dict_get(msg, "id"); 477 char *id = xs_dict_get(msg, "id");
483 char *type = xs_dict_get(msg, "type"); 478 char *type = xs_dict_get(msg, "type");
484 char *meta = xs_dict_get(msg, "_snac");
485 char *actor; 479 char *actor;
486 int sensitive = 0; 480 int sensitive = 0;
487 char *v; 481 char *v;
482 xs *likes = NULL;
483 xs *boosts = NULL;
488 484
489 /* do not show non-public messages in the public timeline */ 485 /* do not show non-public messages in the public timeline */
490 if (local && !is_msg_public(snac, msg)) 486 if (local && !is_msg_public(snac, msg))
491 return os; 487 return os;
492 488
493 /* return if already seen */
494 if (xs_set_add(seen, id) == 0)
495 return os;
496
497 xs *s = xs_str_new(NULL); 489 xs *s = xs_str_new(NULL);
498 490
499 /* top wrap */ 491 /* top wrap */
@@ -522,6 +514,14 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i
522 514
523 return xs_str_cat(os, s); 515 return xs_str_cat(os, s);
524 } 516 }
517 else
518 if (strcmp(type, "Note") != 0) {
519 s = xs_str_cat(s, "<div class=\"snac-post\">\n");
520
521 xs *s1 = xs_fmt("<p>%s</p>\n", type);
522
523 return xs_str_cat(os, s);
524 }
525 525
526 /* bring the main actor */ 526 /* bring the main actor */
527 if ((actor = xs_dict_get(msg, "attributedTo")) == NULL) 527 if ((actor = xs_dict_get(msg, "attributedTo")) == NULL)
@@ -536,14 +536,14 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i
536 536
537 /* if this is our post, add the score */ 537 /* if this is our post, add the score */
538 if (xs_startswith(id, snac->actor)) { 538 if (xs_startswith(id, snac->actor)) {
539 int likes = xs_list_len(xs_dict_get(meta, "liked_by")); 539 likes = object_likes(id);
540 int boosts = xs_list_len(xs_dict_get(meta, "announced_by")); 540 boosts = object_announces(id);
541 541
542 /* alternate emojis: %d &#128077; %d &#128257; */ 542 /* alternate emojis: %d &#128077; %d &#128257; */
543 543
544 xs *s1 = xs_fmt( 544 xs *s1 = xs_fmt(
545 "<div class=\"snac-score\">%d &#9733; %d &#8634;</div>\n", 545 "<div class=\"snac-score\">%d &#9733; %d &#8634;</div>\n",
546 likes, boosts); 546 xs_list_len(likes), xs_list_len(boosts));
547 547
548 s = xs_str_cat(s, s1); 548 s = xs_str_cat(s, s1);
549 } 549 }
@@ -553,28 +553,46 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i
553 553
554 s = xs_str_cat(s, "<div class=\"snac-post\">\n"); 554 s = xs_str_cat(s, "<div class=\"snac-post\">\n");
555 555
556 /* print the origin of the post, if any */ 556 if (boosts == NULL)
557 if (!xs_is_null(p = xs_dict_get(meta, "referrer"))) { 557 boosts = object_announces(id);
558
559 if (xs_list_len(boosts)) {
560 /* if somebody boosted this, show as origin */
561 p = xs_list_get(boosts, 0);
558 xs *actor_r = NULL; 562 xs *actor_r = NULL;
559 563
560 if (valid_status(actor_get(snac, p, &actor_r))) { 564 if (xs_list_in(boosts, snac->md5) != -1) {
565 /* we boosted this */
566 xs *s1 = xs_fmt(
567 "<div class=\"snac-origin\">"
568 "<a href=\"%s\">%s</a> %s</a></div>",
569 snac->actor, xs_dict_get(snac->config, "name"), L("boosted")
570 );
571
572 s = xs_str_cat(s, s1);
573 }
574 else
575 if (valid_status(object_get_by_md5(p, &actor_r, NULL))) {
561 char *name; 576 char *name;
562 577
563 if ((name = xs_dict_get(actor_r, "name")) == NULL) 578 if ((name = xs_dict_get(actor_r, "name")) == NULL)
564 name = xs_dict_get(actor_r, "preferredUsername"); 579 name = xs_dict_get(actor_r, "preferredUsername");
565 580
566 xs *s1 = xs_fmt( 581 if (!xs_is_null(name)) {
567 "<div class=\"snac-origin\">" 582 xs *s1 = xs_fmt(
568 "<a href=\"%s\">%s</a> %s</div>\n", 583 "<div class=\"snac-origin\">"
569 xs_dict_get(actor_r, "id"), 584 "<a href=\"%s\">%s</a> %s</div>\n",
570 name, 585 xs_dict_get(actor_r, "id"),
571 L("boosted") 586 name,
572 ); 587 L("boosted")
588 );
573 589
574 s = xs_str_cat(s, s1); 590 s = xs_str_cat(s, s1);
591 }
575 } 592 }
576 } 593 }
577 else 594
595#if 0
578 if (!xs_is_null((p = xs_dict_get(meta, "parent"))) && *p) { 596 if (!xs_is_null((p = xs_dict_get(meta, "parent"))) && *p) {
579 /* this may happen if any of the autor or the parent aren't here */ 597 /* this may happen if any of the autor or the parent aren't here */
580 xs *s1 = xs_fmt( 598 xs *s1 = xs_fmt(
@@ -586,18 +604,6 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i
586 s = xs_str_cat(s, s1); 604 s = xs_str_cat(s, s1);
587 } 605 }
588 else 606 else
589 if (!xs_is_null((p = xs_dict_get(meta, "announced_by"))) &&
590 xs_list_in(p, snac->actor) != -1) {
591 /* we boosted this */
592 xs *s1 = xs_fmt(
593 "<div class=\"snac-origin\">"
594 "<a href=\"%s\">%s</a> %s</a></div>",
595 snac->actor, xs_dict_get(snac->config, "name"), L("boosted")
596 );
597
598 s = xs_str_cat(s, s1);
599 }
600 else
601 if (!xs_is_null((p = xs_dict_get(meta, "liked_by"))) && 607 if (!xs_is_null((p = xs_dict_get(meta, "liked_by"))) &&
602 xs_list_in(p, snac->actor) != -1) { 608 xs_list_in(p, snac->actor) != -1) {
603 /* we liked this */ 609 /* we liked this */
@@ -609,6 +615,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i
609 615
610 s = xs_str_cat(s, s1); 616 s = xs_str_cat(s, s1);
611 } 617 }
618#endif
612 } 619 }
613 else 620 else
614 s = xs_str_cat(s, "<div class=\"snac-child\">\n"); 621 s = xs_str_cat(s, "<div class=\"snac-child\">\n");
@@ -717,12 +724,11 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i
717 s = html_entry_controls(snac, s, msg, *num); 724 s = html_entry_controls(snac, s, msg, *num);
718 725
719 /** children **/ 726 /** children **/
720 727 xs *children = object_children(id);
721 char *children = xs_dict_get(meta, "children"); 728 int left = xs_list_len(children);
722 int left = xs_list_len(children);
723 729
724 if (left) { 730 if (left) {
725 char *id; 731 char *p, *cmd5;
726 732
727 if (level < 4) 733 if (level < 4)
728 s = xs_str_cat(s, "<div class=\"snac-children\">\n"); 734 s = xs_str_cat(s, "<div class=\"snac-children\">\n");
@@ -732,16 +738,18 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i
732 if (left > 3) 738 if (left > 3)
733 s = xs_str_cat(s, "<details><summary>...</summary>\n"); 739 s = xs_str_cat(s, "<details><summary>...</summary>\n");
734 740
735 while (xs_list_iter(&children, &id)) { 741 p = children;
736 xs *chd = timeline_find(snac, id); 742 while (xs_list_iter(&p, &cmd5)) {
743 xs *chd = NULL;
744 object_get_by_md5(cmd5, &chd, NULL);
737 745
738 if (left == 3) 746 if (left == 3)
739 s = xs_str_cat(s, "</details>\n"); 747 s = xs_str_cat(s, "</details>\n");
740 748
741 if (chd != NULL) 749 if (chd != NULL)
742 s = html_entry(snac, s, chd, seen, local, level + 1, num); 750 s = html_entry(snac, s, chd, local, level + 1, num);
743 else 751 else
744 snac_debug(snac, 2, xs_fmt("cannot read from timeline child %s", id)); 752 snac_debug(snac, 2, xs_fmt("cannot read from timeline child %s", cmd5));
745 753
746 left--; 754 left--;
747 } 755 }
@@ -773,13 +781,10 @@ d_char *html_timeline(snac *snac, char *list, int local)
773/* returns the HTML for the timeline */ 781/* returns the HTML for the timeline */
774{ 782{
775 d_char *s = xs_str_new(NULL); 783 d_char *s = xs_str_new(NULL);
776 xs_set seen;
777 char *v; 784 char *v;
778 double t = ftime(); 785 double t = ftime();
779 int num = 0; 786 int num = 0;
780 787
781 xs_set_init(&seen);
782
783 s = html_user_header(snac, s, local); 788 s = html_user_header(snac, s, local);
784 789
785 if (!local) 790 if (!local)
@@ -789,9 +794,12 @@ d_char *html_timeline(snac *snac, char *list, int local)
789 s = xs_str_cat(s, "<div class=\"snac-posts\">\n"); 794 s = xs_str_cat(s, "<div class=\"snac-posts\">\n");
790 795
791 while (xs_list_iter(&list, &v)) { 796 while (xs_list_iter(&list, &v)) {
792 xs *msg = timeline_get(snac, v); 797 xs *msg = NULL;
798
799 if (!valid_status(object_get_by_md5(v, &msg, NULL)))
800 continue;
793 801
794 s = html_entry(snac, s, msg, &seen, local, 0, &num); 802 s = html_entry(snac, s, msg, local, 0, &num);
795 } 803 }
796 804
797 s = xs_str_cat(s, "</div>\n"); 805 s = xs_str_cat(s, "</div>\n");
@@ -830,8 +838,6 @@ d_char *html_timeline(snac *snac, char *list, int local)
830 838
831 s = xs_str_cat(s, "</body>\n</html>\n"); 839 s = xs_str_cat(s, "</body>\n</html>\n");
832 840
833 xs_set_free(&seen);
834
835 return s; 841 return s;
836} 842}
837 843
@@ -1007,7 +1013,7 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char *
1007 status = 200; 1013 status = 200;
1008 } 1014 }
1009 else { 1015 else {
1010 xs *list = local_list(&snac, XS_ALL); 1016 xs *list = timeline_list(&snac, "public", XS_ALL);
1011 1017
1012 *body = html_timeline(&snac, list, 1); 1018 *body = html_timeline(&snac, list, 1);
1013 *b_size = strlen(*body); 1019 *b_size = strlen(*body);
@@ -1033,7 +1039,9 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char *
1033 else { 1039 else {
1034 snac_debug(&snac, 1, xs_fmt("building timeline")); 1040 snac_debug(&snac, 1, xs_fmt("building timeline"));
1035 1041
1036 xs *list = timeline_list(&snac, XS_ALL); 1042 xs *list = timeline_list(&snac, "private", XS_ALL);
1043
1044 printf("--> %d\n", xs_list_len(list));
1037 1045
1038 *body = html_timeline(&snac, list, 0); 1046 *body = html_timeline(&snac, list, 0);
1039 *b_size = strlen(*body); 1047 *b_size = strlen(*body);
@@ -1098,7 +1106,7 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char *
1098 if (strcmp(p_path, ".rss") == 0) { 1106 if (strcmp(p_path, ".rss") == 0) {
1099 /* public timeline in RSS format */ 1107 /* public timeline in RSS format */
1100 d_char *rss; 1108 d_char *rss;
1101 xs *elems = local_list(&snac, 20); 1109 xs *elems = timeline_list(&snac, "public", 20);
1102 xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio")); 1110 xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"));
1103 char *p, *v; 1111 char *p, *v;
1104 1112
@@ -1281,13 +1289,13 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
1281 if (strcmp(action, L("Like")) == 0) { 1289 if (strcmp(action, L("Like")) == 0) {
1282 xs *msg = msg_admiration(&snac, id, "Like"); 1290 xs *msg = msg_admiration(&snac, id, "Like");
1283 post(&snac, msg); 1291 post(&snac, msg);
1284 timeline_admire(&snac, id, snac.actor, 1); 1292 timeline_admire(&snac, msg, id, snac.actor, 1);
1285 } 1293 }
1286 else 1294 else
1287 if (strcmp(action, L("Boost")) == 0) { 1295 if (strcmp(action, L("Boost")) == 0) {
1288 xs *msg = msg_admiration(&snac, id, "Announce"); 1296 xs *msg = msg_admiration(&snac, id, "Announce");
1289 post(&snac, msg); 1297 post(&snac, msg);
1290 timeline_admire(&snac, id, snac.actor, 0); 1298 timeline_admire(&snac, msg, id, snac.actor, 0);
1291 } 1299 }
1292 else 1300 else
1293 if (strcmp(action, L("MUTE")) == 0) { 1301 if (strcmp(action, L("MUTE")) == 0) {