summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--html.c119
1 files changed, 64 insertions, 55 deletions
diff --git a/html.c b/html.c
index acda93d..cfa7ede 100644
--- a/html.c
+++ b/html.c
@@ -1018,82 +1018,98 @@ xs_str *build_mentions(snac *snac, const xs_dict *msg)
1018} 1018}
1019 1019
1020 1020
1021xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const char *md5) 1021xs_html *html_entry_controls(snac *snac, const xs_dict *msg, const char *md5)
1022{ 1022{
1023 const char *id = xs_dict_get(msg, "id"); 1023 char *id = xs_dict_get(msg, "id");
1024 const char *actor = xs_dict_get(msg, "attributedTo"); 1024 char *actor = xs_dict_get(msg, "attributedTo");
1025 const char *group = xs_dict_get(msg, "audience"); 1025 char *group = xs_dict_get(msg, "audience");
1026 1026
1027 xs *likes = object_likes(id); 1027 xs *likes = object_likes(id);
1028 xs *boosts = object_announces(id); 1028 xs *boosts = object_announces(id);
1029 1029
1030 xs *s = xs_str_new(NULL); 1030 xs *action = xs_fmt("%s/admin/action", snac->actor);
1031 1031 xs *redir = xs_fmt("%s_entry", md5);
1032 s = xs_str_cat(s, "<div class=\"snac-controls\">\n");
1033
1034 {
1035 xs *s1 = xs_fmt(
1036 "<form autocomplete=\"off\" method=\"post\" action=\"%s/admin/action\">\n"
1037 "<input type=\"hidden\" name=\"id\" value=\"%s\">\n"
1038 "<input type=\"hidden\" name=\"actor\" value=\"%s\">\n"
1039 "<input type=\"hidden\" name=\"group\" value=\"%s\">\n"
1040 "<input type=\"hidden\" name=\"redir\" value=\"%s_entry\">\n"
1041 "\n",
1042
1043 snac->actor, id, actor, group ? group : "", md5
1044 );
1045 1032
1046 s = xs_str_cat(s, s1); 1033 xs_html *form;
1047 } 1034 xs_html *controls = xs_html_tag("div",
1035 xs_html_attr("class", "snac-controls"),
1036 form = xs_html_tag("form",
1037 xs_html_attr("autocomplete", "off"),
1038 xs_html_attr("method", "post"),
1039 xs_html_attr("action", action),
1040 xs_html_sctag("input",
1041 xs_html_attr("type", "hidden"),
1042 xs_html_attr("name", "id"),
1043 xs_html_attr("value", id)),
1044 xs_html_sctag("input",
1045 xs_html_attr("type", "hidden"),
1046 xs_html_attr("name", "actor"),
1047 xs_html_attr("value", actor)),
1048 xs_html_sctag("input",
1049 xs_html_attr("type", "hidden"),
1050 xs_html_attr("name", "group"),
1051 xs_html_attr("value", xs_is_null(group) ? "" : group)),
1052 xs_html_sctag("input",
1053 xs_html_attr("type", "hidden"),
1054 xs_html_attr("name", "redir"),
1055 xs_html_attr("value", redir))));
1048 1056
1049 if (!xs_startswith(id, snac->actor)) { 1057 if (!xs_startswith(id, snac->actor)) {
1050 if (xs_list_in(likes, snac->md5) == -1) { 1058 if (xs_list_in(likes, snac->md5) == -1) {
1051 /* not already liked; add button */ 1059 /* not already liked; add button */
1052 s = html_button(s, "like", L("Like"), L("Say you like this post")); 1060 xs_html_add(form,
1061 html_button_2("like", L("Like"), L("Say you like this post")));
1053 } 1062 }
1054 } 1063 }
1055 else { 1064 else {
1056 if (is_pinned(snac, id)) 1065 if (is_pinned(snac, id))
1057 s = html_button(s, "unpin", L("Unpin"), L("Unpin this post from your timeline")); 1066 xs_html_add(form,
1067 html_button_2("unpin", L("Unpin"), L("Unpin this post from your timeline")));
1058 else 1068 else
1059 s = html_button(s, "pin", L("Pin"), L("Pin this post to the top of your timeline")); 1069 xs_html_add(form,
1070 html_button_2("pin", L("Pin"), L("Pin this post to the top of your timeline")));
1060 } 1071 }
1061 1072
1062 if (is_msg_public(msg)) { 1073 if (is_msg_public(msg)) {
1063 if (strcmp(actor, snac->actor) == 0 || xs_list_in(boosts, snac->md5) == -1) { 1074 if (strcmp(actor, snac->actor) == 0 || xs_list_in(boosts, snac->md5) == -1) {
1064 /* not already boosted or us; add button */ 1075 /* not already boosted or us; add button */
1065 s = html_button(s, "boost", L("Boost"), L("Announce this post to your followers")); 1076 xs_html_add(form,
1077 html_button_2("boost", L("Boost"), L("Announce this post to your followers")));
1066 } 1078 }
1067 } 1079 }
1068 1080
1069 if (strcmp(actor, snac->actor) != 0) { 1081 if (strcmp(actor, snac->actor) != 0) {
1070 /* controls for other actors than this one */ 1082 /* controls for other actors than this one */
1071 if (following_check(snac, actor)) { 1083 if (following_check(snac, actor)) {
1072 s = html_button(s, "unfollow", L("Unfollow"), L("Stop following this user's activity")); 1084 xs_html_add(form,
1085 html_button_2("unfollow", L("Unfollow"), L("Stop following this user's activity")));
1073 } 1086 }
1074 else { 1087 else {
1075 s = html_button(s, "follow", L("Follow"), L("Start following this user's activity")); 1088 xs_html_add(form,
1089 html_button_2("follow", L("Follow"), L("Start following this user's activity")));
1076 } 1090 }
1077 1091
1078 if (!xs_is_null(group)) { 1092 if (!xs_is_null(group)) {
1079 if (following_check(snac, group)) { 1093 if (following_check(snac, group)) {
1080 s = html_button(s, "unfollow", L("Unfollow Group"), 1094 xs_html_add(form,
1081 L("Stop following this group or channel")); 1095 html_button_2("unfollow", L("Unfollow Group"),
1096 L("Stop following this group or channel")));
1082 } 1097 }
1083 else { 1098 else {
1084 s = html_button(s, "follow", L("Follow Group"), 1099 xs_html_add(form,
1085 L("Start following this group or channel")); 1100 html_button_2("follow", L("Follow Group"),
1101 L("Start following this group or channel")));
1086 } 1102 }
1087 } 1103 }
1088 1104
1089 s = html_button(s, "mute", L("MUTE"), 1105 xs_html_add(form,
1090 L("Block any activity from this user forever")); 1106 html_button_2("mute", L("MUTE"),
1107 L("Block any activity from this user forever")));
1091 } 1108 }
1092 1109
1093 s = html_button(s, "delete", L("Delete"), L("Delete this post")); 1110 xs_html_add(form,
1094 s = html_button(s, "hide", L("Hide"), L("Hide this post and its children")); 1111 html_button_2("delete", L("Delete"), L("Delete this post")),
1095 1112 html_button_2("hide", L("Hide"), L("Hide this post and its children")));
1096 s = xs_str_cat(s, "</form>\n");
1097 1113
1098 char *prev_src = xs_dict_get(msg, "sourceContent"); 1114 char *prev_src = xs_dict_get(msg, "sourceContent");
1099 1115
@@ -1103,18 +1119,14 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
1103 xs *form_id = xs_fmt("%s_edit_form", md5); 1119 xs *form_id = xs_fmt("%s_edit_form", md5);
1104 xs *redir = xs_fmt("%s_entry", md5); 1120 xs *redir = xs_fmt("%s_entry", md5);
1105 1121
1106 xs_html *h = xs_html_tag("p", 1122 xs_html_add(controls, xs_html_tag("p",
1107 html_note(snac, L("Edit..."), 1123 html_note(snac, L("Edit..."),
1108 div_id, form_id, 1124 div_id, form_id,
1109 "", prev_src, 1125 "", prev_src,
1110 (char *)id, NULL, 1126 id, NULL,
1111 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"), 1127 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
1112 xs_stock_false, redir, 1128 xs_stock_false, redir,
1113 NULL, 0)); 1129 NULL, 0)));
1114
1115 xs *s1 = xs_html_render(h);
1116
1117 s = xs_str_cat(s, s1);
1118 } 1130 }
1119 1131
1120 { /** reply **/ 1132 { /** reply **/
@@ -1124,23 +1136,17 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
1124 xs *form_id = xs_fmt("%s_reply_form", md5); 1136 xs *form_id = xs_fmt("%s_reply_form", md5);
1125 xs *redir = xs_fmt("%s_entry", md5); 1137 xs *redir = xs_fmt("%s_entry", md5);
1126 1138
1127 xs_html *h = xs_html_tag("p", 1139 xs_html_add(controls, xs_html_tag("p",
1128 html_note(snac, L("Reply..."), 1140 html_note(snac, L("Reply..."),
1129 div_id, form_id, 1141 div_id, form_id,
1130 "", ct, 1142 "", ct,
1131 NULL, NULL, 1143 NULL, NULL,
1132 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"), 1144 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
1133 xs_stock_false, redir, 1145 xs_stock_false, redir,
1134 (char *)id, 0)); 1146 id, 0)));
1135
1136 xs *s1 = xs_html_render(h);
1137
1138 s = xs_str_cat(s, s1);
1139 } 1147 }
1140 1148
1141 s = xs_str_cat(s, "</div>\n"); 1149 return controls;
1142
1143 return xs_str_cat(os, s);
1144} 1150}
1145 1151
1146 1152
@@ -1604,8 +1610,11 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local,
1604 1610
1605 /** controls **/ 1611 /** controls **/
1606 1612
1607 if (!local && user) 1613 if (!local && user) {
1608 s = html_entry_controls(user, s, msg, md5); 1614 xs_html *h = html_entry_controls(user, msg, md5);
1615 xs *s1 = xs_html_render(h);
1616 s = xs_str_cat(s, s1);
1617 }
1609 1618
1610 /** children **/ 1619 /** children **/
1611 if (!hide_children) { 1620 if (!hide_children) {