commit d291bb1
default
·
2023-08-12 12:03:44 +0000 UTC
parent 72839e5
Allow a NULL snac struct in html_entry().
1 files changed,
+28,
-23
M
html.c
M
html.c
+28,
-23
1@@ -834,7 +834,7 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
2 }
3
4
5-xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
6+xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local,
7 int level, const char *md5, int hide_children)
8 {
9 char *id = xs_dict_get(msg, "id");
10@@ -849,7 +849,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
11 return os;
12
13 /* hidden? do nothing more for this conversation */
14- if (is_hidden(snac, id))
15+ if (user && is_hidden(user, id))
16 return os;
17
18 /* avoid too deep nesting, as it may be a loop */
19@@ -891,10 +891,11 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
20 return os;
21
22 /* ignore muted morons immediately */
23- if (is_muted(snac, actor))
24+ if (user && is_muted(user, actor))
25 return os;
26
27- if (strcmp(actor, snac->actor) != 0 && !valid_status(actor_get(actor, NULL)))
28+ if ((user == NULL || strcmp(actor, user->actor) != 0)
29+ && !valid_status(actor_get(actor, NULL)))
30 return os;
31
32 if (level == 0)
33@@ -904,7 +905,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
34
35 s = xs_str_cat(s, "<div class=\"snac-post-header\">\n<div class=\"snac-score\">"); /** **/
36
37- if (is_pinned(snac, id)) {
38+ if (user && is_pinned(user, id)) {
39 /* add a pin emoji */
40 xs *f = xs_fmt("<span title=\"%s\"> 📌 </span>", L("Pinned"));
41 s = xs_str_cat(s, f);
42@@ -915,15 +916,15 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
43 xs *f = xs_fmt("<span title=\"%s\"> 🗳 </span>", L("Poll"));
44 s = xs_str_cat(s, f);
45
46- if (was_question_voted(snac, id)) {
47+ if (user && was_question_voted(user, id)) {
48 /* add a check to show this poll was voted */
49 xs *f2 = xs_fmt("<span title=\"%s\"> ✓ </span>", L("Voted"));
50 s = xs_str_cat(s, f2);
51 }
52 }
53
54- /* if this is our post, add the score */
55- if (xs_startswith(id, snac->actor)) {
56+ /* if it's a user from this same instance, add the score */
57+ if (xs_startswith(id, srv_baseurl)) {
58 int n_likes = object_likes_len(id);
59 int n_boosts = object_announces_len(id);
60
61@@ -944,13 +945,13 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
62 char *p = xs_list_get(boosts, -1);
63 xs *actor_r = NULL;
64
65- if (xs_list_in(boosts, snac->md5) != -1) {
66+ if (user && xs_list_in(boosts, user->md5) != -1) {
67 /* we boosted this */
68- xs *es1 = encode_html(xs_dict_get(snac->config, "name"));
69+ xs *es1 = encode_html(xs_dict_get(user->config, "name"));
70 xs *s1 = xs_fmt(
71 "<div class=\"snac-origin\">"
72 "<a href=\"%s\">%s</a> %s</a></div>",
73- snac->actor, es1, L("boosted")
74+ user->actor, es1, L("boosted")
75 );
76
77 s = xs_str_cat(s, s1);
78@@ -978,7 +979,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
79 /* is the parent not here? */
80 char *parent = xs_dict_get(msg, "inReplyTo");
81
82- if (!xs_is_null(parent) && *parent && !timeline_here(snac, parent)) {
83+ if (user && !xs_is_null(parent) && *parent && !timeline_here(user, parent)) {
84 xs *s1 = xs_fmt(
85 "<div class=\"snac-origin\">%s "
86 "<a href=\"%s\">ยป</a></div>\n",
87@@ -1002,11 +1003,11 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
88 }
89
90 /* is it sensitive? */
91- if (!xs_is_null(v = xs_dict_get(msg, "sensitive")) && xs_type(v) == XSTYPE_TRUE) {
92+ if (user && xs_type(xs_dict_get(msg, "sensitive")) == XSTYPE_TRUE) {
93 if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0')
94 v = "...";
95 /* only show it when not in the public timeline and the config setting is "open" */
96- char *cw = xs_dict_get(snac->config, "cw");
97+ char *cw = xs_dict_get(user->config, "cw");
98 if (xs_is_null(cw) || local)
99 cw = "";
100 xs *es1 = encode_html(v);
101@@ -1085,16 +1086,16 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
102 if (xs_dict_get(msg, "closed"))
103 closed = 2;
104 else
105- if (xs_startswith(id, snac->actor))
106+ if (user && xs_startswith(id, user->actor))
107 closed = 1; /* we questioned; closed for us */
108 else
109- if (was_question_voted(snac, id))
110+ if (user && was_question_voted(user, id))
111 closed = 1; /* we already voted; closed for us */
112
113 /* get the appropriate list of options */
114 p = oo != NULL ? oo : ao;
115
116- if (closed) {
117+ if (closed || user == NULL) {
118 /* closed poll */
119 c = xs_str_cat(c, "<table class=\"snac-poll-result\">\n");
120
121@@ -1120,7 +1121,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
122 "method=\"post\" action=\"%s/admin/vote\">\n"
123 "<input type=\"hidden\" name=\"actor\" value= \"%s\">\n"
124 "<input type=\"hidden\" name=\"irt\" value=\"%s\">\n",
125- snac->actor, actor, id);
126+ user->actor, actor, id);
127
128 while (xs_list_iter(&p, &v)) {
129 const char *name = xs_dict_get(v, "name");
130@@ -1276,8 +1277,8 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
131
132 /** controls **/
133
134- if (!local)
135- s = html_entry_controls(snac, s, msg, md5);
136+ if (!local && user)
137+ s = html_entry_controls(user, s, msg, md5);
138
139 /** children **/
140 if (!hide_children) {
141@@ -1306,7 +1307,11 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
142 p = children;
143 while (xs_list_iter(&p, &cmd5)) {
144 xs *chd = NULL;
145- timeline_get_by_md5(snac, cmd5, &chd);
146+
147+ if (user)
148+ timeline_get_by_md5(user, cmd5, &chd);
149+ else
150+ object_get_by_md5(cmd5, &chd);
151
152 if (older_open && left <= 3) {
153 ss = xs_str_cat(ss, "</details>\n");
154@@ -1314,11 +1319,11 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
155 }
156
157 if (chd != NULL && xs_is_null(xs_dict_get(chd, "name"))) {
158- ss = html_entry(snac, ss, chd, local, level + 1, cmd5, hide_children);
159+ ss = html_entry(user, ss, chd, local, level + 1, cmd5, hide_children);
160 n_children++;
161 }
162 else
163- snac_debug(snac, 2, xs_fmt("cannot read from timeline child %s", cmd5));
164+ srv_debug(2, xs_fmt("cannot read child %s", cmd5));
165
166 left--;
167 }