summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
authorgrunfink <grunfink@noreply.codeberg.org>2024-05-31 09:09:54 +0000
committergrunfink <grunfink@noreply.codeberg.org>2024-05-31 09:09:54 +0000
commitfe52b7612e4a96d491f925dfcbbbaa6251654ca4 (patch)
tree40fb16a0f78b0988dd8167c101554d8425d2a875 /html.c
parenta5e331c05e79a6cd0904b23ab9c71724cd628d16 (diff)
parentac3b5dcbd472b533ec543331692921b804fd02e4 (diff)
Merge pull request 'Implement instance announcements' (#173) from louis77/snac2:announcements into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/173
Diffstat (limited to 'html.c')
-rw-r--r--html.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/html.c b/html.c
index c3a2efe..2274f74 100644
--- a/html.c
+++ b/html.c
@@ -786,6 +786,24 @@ static xs_html *html_user_body(snac *user, int read_only)
xs_html_attr("class", "snac-top-user-id"),
xs_html_text(handle)));
+ /** instance announcement **/
+
+ double la = 0.0;
+ xs *user_la = xs_dup(xs_dict_get(user->config, "last_announcement"));
+ if (user_la != NULL)
+ la = xs_number_get(user_la);
+
+ const t_announcement *an = announcement(la);
+ if (an != NULL && (an->text != NULL)) {
+ xs_html_add(top_user, xs_html_tag("div",
+ xs_html_attr("class", "snac-announcement"),
+ xs_html_text(an->text),
+ xs_html_text(" "),
+ xs_html_sctag("a",
+ xs_html_attr("href", xs_dup(xs_fmt("?da=%.0f", an->timestamp)))),
+ xs_html_text("Dismiss")));
+ }
+
if (read_only) {
xs *es1 = encode_html(xs_dict_get(user->config, "bio"));
xs *bio1 = not_really_markdown(es1, NULL, NULL);
@@ -2606,6 +2624,16 @@ int html_get_handler(const xs_dict *req, const char *q_path,
skip = atoi(v), cache = 0, save = 0;
if ((v = xs_dict_get(q_vars, "show")) != NULL)
show = atoi(v), cache = 0, save = 0;
+ if ((v = xs_dict_get(q_vars, "da")) != NULL) {
+ /* user dismissed an announcement */
+ if (login(&snac, req)) {
+ double ts = atof(v);
+ xs *timestamp = xs_number_new(ts);
+ srv_log(xs_fmt("user dismissed announcements until %d", ts));
+ snac.config = xs_dict_set(snac.config, "last_announcement", timestamp);
+ user_persist(&snac);
+ }
+ }
if (p_path == NULL) { /** public timeline **/
xs *h = xs_str_localtime(0, "%Y-%m.html");