commit 2302d90

grunfink  ·  2026-10-01 07:07:30 +0000 UTC
parent c473905
mastoapi: reimplemented fix for alt text edition.
1 files changed,  +13, -9
+13, -9
 1@@ -4362,24 +4362,28 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path,
 2                         xs *n_att = xs_dup(xs_dict_get(msg, "attachment"));
 3 
 4                         if (xs_is_list(n_att)) {
 5-                            int num = xs_list_len(media_attrs);
 6-
 7-                            for (int n = 0; n < num; n++) {
 8-                                const xs_dict *d = xs_list_get(media_attrs, n);
 9+                            const xs_dict *d;
10 
11+                            xs_list_foreach(media_attrs, d) {
12                                 if (xs_is_dict(d)) {
13-                                    xs *na = xs_dup(xs_list_get(n_att, n));
14+                                    const char *id = xs_dict_get(d, "id");
15+                                    const char *desc = xs_dict_get(d, "description");
16+
17+                                    if (xs_is_string(id) && xs_is_string(desc)) {
18+                                        /* we build these ids with post name + _N,
19+                                           so split by _ and get the last item as index */
20+                                        xs *l = xs_split(id, "_");
21+                                        int n = atoi(xs_or(xs_list_get(l, -1), "0"));
22 
23-                                    if (xs_is_dict(na)) {
24-                                        const char *desc = xs_dict_get(d, "description");
25+                                        xs *na = xs_dup(xs_list_get(n_att, n));
26                                         na = xs_dict_set(na, "name", desc);
27                                         n_att = xs_list_set(n_att, n, na);
28                                     }
29                                 }
30                             }
31-                        }
32 
33-                        msg = xs_dict_set(msg, "attachment", n_att);
34+                            msg = xs_dict_set(msg, "attachment", n_att);
35+                        }
36                     }
37 
38                     /* overwrite object, not updating the indexes */