summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-08-12 14:03:44 +0200
committerGravatar default2023-08-12 14:03:44 +0200
commitd291bb16cab3ed3d7b969ee92893aa79fdd9d23b (patch)
tree4fffd844603fecb234afd00507a4b94a361b428e
parentmastoapi: fixed /api/timelines/public to not need a bearer token. (diff)
downloadsnac2-d291bb16cab3ed3d7b969ee92893aa79fdd9d23b.tar.gz
snac2-d291bb16cab3ed3d7b969ee92893aa79fdd9d23b.tar.xz
snac2-d291bb16cab3ed3d7b969ee92893aa79fdd9d23b.zip
Allow a NULL snac struct in html_entry().
-rw-r--r--html.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/html.c b/html.c
index 5c2c4d7..161292d 100644
--- a/html.c
+++ b/html.c
@@ -834,7 +834,7 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
834} 834}
835 835
836 836
837xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, 837xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local,
838 int level, const char *md5, int hide_children) 838 int level, const char *md5, int hide_children)
839{ 839{
840 char *id = xs_dict_get(msg, "id"); 840 char *id = xs_dict_get(msg, "id");
@@ -849,7 +849,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
849 return os; 849 return os;
850 850
851 /* hidden? do nothing more for this conversation */ 851 /* hidden? do nothing more for this conversation */
852 if (is_hidden(snac, id)) 852 if (user && is_hidden(user, id))
853 return os; 853 return os;
854 854
855 /* avoid too deep nesting, as it may be a loop */ 855 /* avoid too deep nesting, as it may be a loop */
@@ -891,10 +891,11 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
891 return os; 891 return os;
892 892
893 /* ignore muted morons immediately */ 893 /* ignore muted morons immediately */
894 if (is_muted(snac, actor)) 894 if (user && is_muted(user, actor))
895 return os; 895 return os;
896 896
897 if (strcmp(actor, snac->actor) != 0 && !valid_status(actor_get(actor, NULL))) 897 if ((user == NULL || strcmp(actor, user->actor) != 0)
898 && !valid_status(actor_get(actor, NULL)))
898 return os; 899 return os;
899 900
900 if (level == 0) 901 if (level == 0)
@@ -904,7 +905,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
904 905
905 s = xs_str_cat(s, "<div class=\"snac-post-header\">\n<div class=\"snac-score\">"); /** **/ 906 s = xs_str_cat(s, "<div class=\"snac-post-header\">\n<div class=\"snac-score\">"); /** **/
906 907
907 if (is_pinned(snac, id)) { 908 if (user && is_pinned(user, id)) {
908 /* add a pin emoji */ 909 /* add a pin emoji */
909 xs *f = xs_fmt("<span title=\"%s\"> &#128204; </span>", L("Pinned")); 910 xs *f = xs_fmt("<span title=\"%s\"> &#128204; </span>", L("Pinned"));
910 s = xs_str_cat(s, f); 911 s = xs_str_cat(s, f);
@@ -915,15 +916,15 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
915 xs *f = xs_fmt("<span title=\"%s\"> &#128499; </span>", L("Poll")); 916 xs *f = xs_fmt("<span title=\"%s\"> &#128499; </span>", L("Poll"));
916 s = xs_str_cat(s, f); 917 s = xs_str_cat(s, f);
917 918
918 if (was_question_voted(snac, id)) { 919 if (user && was_question_voted(user, id)) {
919 /* add a check to show this poll was voted */ 920 /* add a check to show this poll was voted */
920 xs *f2 = xs_fmt("<span title=\"%s\"> &#10003; </span>", L("Voted")); 921 xs *f2 = xs_fmt("<span title=\"%s\"> &#10003; </span>", L("Voted"));
921 s = xs_str_cat(s, f2); 922 s = xs_str_cat(s, f2);
922 } 923 }
923 } 924 }
924 925
925 /* if this is our post, add the score */ 926 /* if it's a user from this same instance, add the score */
926 if (xs_startswith(id, snac->actor)) { 927 if (xs_startswith(id, srv_baseurl)) {
927 int n_likes = object_likes_len(id); 928 int n_likes = object_likes_len(id);
928 int n_boosts = object_announces_len(id); 929 int n_boosts = object_announces_len(id);
929 930
@@ -944,13 +945,13 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
944 char *p = xs_list_get(boosts, -1); 945 char *p = xs_list_get(boosts, -1);
945 xs *actor_r = NULL; 946 xs *actor_r = NULL;
946 947
947 if (xs_list_in(boosts, snac->md5) != -1) { 948 if (user && xs_list_in(boosts, user->md5) != -1) {
948 /* we boosted this */ 949 /* we boosted this */
949 xs *es1 = encode_html(xs_dict_get(snac->config, "name")); 950 xs *es1 = encode_html(xs_dict_get(user->config, "name"));
950 xs *s1 = xs_fmt( 951 xs *s1 = xs_fmt(
951 "<div class=\"snac-origin\">" 952 "<div class=\"snac-origin\">"
952 "<a href=\"%s\">%s</a> %s</a></div>", 953 "<a href=\"%s\">%s</a> %s</a></div>",
953 snac->actor, es1, L("boosted") 954 user->actor, es1, L("boosted")
954 ); 955 );
955 956
956 s = xs_str_cat(s, s1); 957 s = xs_str_cat(s, s1);
@@ -978,7 +979,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
978 /* is the parent not here? */ 979 /* is the parent not here? */
979 char *parent = xs_dict_get(msg, "inReplyTo"); 980 char *parent = xs_dict_get(msg, "inReplyTo");
980 981
981 if (!xs_is_null(parent) && *parent && !timeline_here(snac, parent)) { 982 if (user && !xs_is_null(parent) && *parent && !timeline_here(user, parent)) {
982 xs *s1 = xs_fmt( 983 xs *s1 = xs_fmt(
983 "<div class=\"snac-origin\">%s " 984 "<div class=\"snac-origin\">%s "
984 "<a href=\"%s\">»</a></div>\n", 985 "<a href=\"%s\">»</a></div>\n",
@@ -1002,11 +1003,11 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
1002 } 1003 }
1003 1004
1004 /* is it sensitive? */ 1005 /* is it sensitive? */
1005 if (!xs_is_null(v = xs_dict_get(msg, "sensitive")) && xs_type(v) == XSTYPE_TRUE) { 1006 if (user && xs_type(xs_dict_get(msg, "sensitive")) == XSTYPE_TRUE) {
1006 if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0') 1007 if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0')
1007 v = "..."; 1008 v = "...";
1008 /* only show it when not in the public timeline and the config setting is "open" */ 1009 /* only show it when not in the public timeline and the config setting is "open" */
1009 char *cw = xs_dict_get(snac->config, "cw"); 1010 char *cw = xs_dict_get(user->config, "cw");
1010 if (xs_is_null(cw) || local) 1011 if (xs_is_null(cw) || local)
1011 cw = ""; 1012 cw = "";
1012 xs *es1 = encode_html(v); 1013 xs *es1 = encode_html(v);
@@ -1085,16 +1086,16 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
1085 if (xs_dict_get(msg, "closed")) 1086 if (xs_dict_get(msg, "closed"))
1086 closed = 2; 1087 closed = 2;
1087 else 1088 else
1088 if (xs_startswith(id, snac->actor)) 1089 if (user && xs_startswith(id, user->actor))
1089 closed = 1; /* we questioned; closed for us */ 1090 closed = 1; /* we questioned; closed for us */
1090 else 1091 else
1091 if (was_question_voted(snac, id)) 1092 if (user && was_question_voted(user, id))
1092 closed = 1; /* we already voted; closed for us */ 1093 closed = 1; /* we already voted; closed for us */
1093 1094
1094 /* get the appropriate list of options */ 1095 /* get the appropriate list of options */
1095 p = oo != NULL ? oo : ao; 1096 p = oo != NULL ? oo : ao;
1096 1097
1097 if (closed) { 1098 if (closed || user == NULL) {
1098 /* closed poll */ 1099 /* closed poll */
1099 c = xs_str_cat(c, "<table class=\"snac-poll-result\">\n"); 1100 c = xs_str_cat(c, "<table class=\"snac-poll-result\">\n");
1100 1101
@@ -1120,7 +1121,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
1120 "method=\"post\" action=\"%s/admin/vote\">\n" 1121 "method=\"post\" action=\"%s/admin/vote\">\n"
1121 "<input type=\"hidden\" name=\"actor\" value= \"%s\">\n" 1122 "<input type=\"hidden\" name=\"actor\" value= \"%s\">\n"
1122 "<input type=\"hidden\" name=\"irt\" value=\"%s\">\n", 1123 "<input type=\"hidden\" name=\"irt\" value=\"%s\">\n",
1123 snac->actor, actor, id); 1124 user->actor, actor, id);
1124 1125
1125 while (xs_list_iter(&p, &v)) { 1126 while (xs_list_iter(&p, &v)) {
1126 const char *name = xs_dict_get(v, "name"); 1127 const char *name = xs_dict_get(v, "name");
@@ -1276,8 +1277,8 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
1276 1277
1277 /** controls **/ 1278 /** controls **/
1278 1279
1279 if (!local) 1280 if (!local && user)
1280 s = html_entry_controls(snac, s, msg, md5); 1281 s = html_entry_controls(user, s, msg, md5);
1281 1282
1282 /** children **/ 1283 /** children **/
1283 if (!hide_children) { 1284 if (!hide_children) {
@@ -1306,7 +1307,11 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
1306 p = children; 1307 p = children;
1307 while (xs_list_iter(&p, &cmd5)) { 1308 while (xs_list_iter(&p, &cmd5)) {
1308 xs *chd = NULL; 1309 xs *chd = NULL;
1309 timeline_get_by_md5(snac, cmd5, &chd); 1310
1311 if (user)
1312 timeline_get_by_md5(user, cmd5, &chd);
1313 else
1314 object_get_by_md5(cmd5, &chd);
1310 1315
1311 if (older_open && left <= 3) { 1316 if (older_open && left <= 3) {
1312 ss = xs_str_cat(ss, "</details>\n"); 1317 ss = xs_str_cat(ss, "</details>\n");
@@ -1314,11 +1319,11 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
1314 } 1319 }
1315 1320
1316 if (chd != NULL && xs_is_null(xs_dict_get(chd, "name"))) { 1321 if (chd != NULL && xs_is_null(xs_dict_get(chd, "name"))) {
1317 ss = html_entry(snac, ss, chd, local, level + 1, cmd5, hide_children); 1322 ss = html_entry(user, ss, chd, local, level + 1, cmd5, hide_children);
1318 n_children++; 1323 n_children++;
1319 } 1324 }
1320 else 1325 else
1321 snac_debug(snac, 2, xs_fmt("cannot read from timeline child %s", cmd5)); 1326 srv_debug(2, xs_fmt("cannot read child %s", cmd5));
1322 1327
1323 left--; 1328 left--;
1324 } 1329 }