commit 0577051
default
·
2024-03-20 04:45:32 +0000 UTC
parent 8f983d3
Editing a post doesn't lose the attachment and its alt text.
1 files changed,
+46,
-14
M
html.c
M
html.c
+46,
-14
1@@ -273,7 +273,8 @@ xs_html *html_note(snac *user, char *summary,
2 char *edit_id, char *actor_id,
3 xs_val *cw_yn, char *cw_text,
4 xs_val *mnt_only, char *redir,
5- char *in_reply_to, int poll)
6+ char *in_reply_to, int poll,
7+ char *att_file, char *att_alt_text)
8 {
9 xs *action = xs_fmt("%s/admin/note", user->actor);
10
11@@ -359,19 +360,36 @@ xs_html *html_note(snac *user, char *summary,
12 xs_html_attr("name", "edit_id"),
13 xs_html_attr("value", edit_id)));
14
15+ /* attachment controls */
16+ xs_html *att;
17+
18 xs_html_add(form,
19 xs_html_tag("p", NULL),
20- xs_html_tag("details",
21+ att = xs_html_tag("details",
22 xs_html_tag("summary",
23 xs_html_text(L("Attachment..."))),
24- xs_html_tag("p", NULL),
25- xs_html_sctag("input",
26- xs_html_attr("type", "file"),
27- xs_html_attr("name", "attach")),
28- xs_html_sctag("input",
29- xs_html_attr("type", "text"),
30- xs_html_attr("name", "alt_text"),
31- xs_html_attr("placeholder", L("Attachment description")))));
32+ xs_html_tag("p", NULL)));
33+
34+ if (att_file && *att_file)
35+ xs_html_add(att,
36+ xs_html_text(L("File:")),
37+ xs_html_sctag("input",
38+ xs_html_attr("type", "text"),
39+ xs_html_attr("name", "attach_url"),
40+ xs_html_attr("value", att_file)));
41+ else
42+ xs_html_add(att,
43+ xs_html_sctag("input",
44+ xs_html_attr("type", "file"),
45+ xs_html_attr("name", "attach")));
46+
47+ xs_html_add(att,
48+ xs_html_text(" "),
49+ xs_html_sctag("input",
50+ xs_html_attr("type", "text"),
51+ xs_html_attr("name", "alt_text"),
52+ xs_html_attr("value", att_alt_text),
53+ xs_html_attr("placeholder", L("Attachment description"))));
54
55 /* add poll controls */
56 if (poll) {
57@@ -854,7 +872,7 @@ xs_html *html_top_controls(snac *snac)
58 NULL, NULL,
59 xs_stock(XSTYPE_FALSE), "",
60 xs_stock(XSTYPE_FALSE), NULL,
61- NULL, 1),
62+ NULL, 1, "", ""),
63
64 /** operations **/
65 xs_html_tag("details",
66@@ -1278,6 +1296,20 @@ xs_html *html_entry_controls(snac *snac, char *actor, const xs_dict *msg, const
67 xs *form_id = xs_fmt("%s_edit_form", md5);
68 xs *redir = xs_fmt("%s_entry", md5);
69
70+ char *att_file = "";
71+ char *att_alt_text = "";
72+ xs_list *att_list = xs_dict_get(msg, "attachment");
73+
74+ /* does it have an attachment? */
75+ if (xs_type(att_list) == XSTYPE_LIST && xs_list_len(att_list)) {
76+ xs_dict *d = xs_list_get(att_list, 0);
77+
78+ if (xs_type(d) == XSTYPE_DICT) {
79+ att_file = xs_dict_get_def(d, "url", "");
80+ att_alt_text = xs_dict_get_def(d, "name", "");
81+ }
82+ }
83+
84 xs_html_add(controls, xs_html_tag("div",
85 xs_html_tag("p", NULL),
86 html_note(snac, L("Edit..."),
87@@ -1286,7 +1318,7 @@ xs_html *html_entry_controls(snac *snac, char *actor, const xs_dict *msg, const
88 id, NULL,
89 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
90 xs_stock(XSTYPE_FALSE), redir,
91- NULL, 0)),
92+ NULL, 0, att_file, att_alt_text)),
93 xs_html_tag("p", NULL));
94 }
95
96@@ -1305,7 +1337,7 @@ xs_html *html_entry_controls(snac *snac, char *actor, const xs_dict *msg, const
97 NULL, NULL,
98 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
99 xs_stock(XSTYPE_FALSE), redir,
100- id, 0)),
101+ id, 0, "", "")),
102 xs_html_tag("p", NULL));
103 }
104
105@@ -2201,7 +2233,7 @@ xs_html *html_people_list(snac *snac, xs_list *list, char *header, char *t)
106 NULL, actor_id,
107 xs_stock(XSTYPE_FALSE), "",
108 xs_stock(XSTYPE_FALSE), NULL,
109- NULL, 0),
110+ NULL, 0, "", ""),
111 xs_html_tag("p", NULL));
112
113 xs_html_add(snac_post, snac_controls);