commit 6a5ea97

default  ·  2025-01-10 08:52:20 +0000 UTC
parent 9fec8fc
If a post has a location, show it.
1 files changed,  +37, -0
M html.c
M html.c
+37, -0
 1@@ -2224,6 +2224,43 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
 2             au_tag);
 3     }
 4 
 5+    /* does it have a location? */
 6+    const xs_dict *location = xs_dict_get(msg, "location");
 7+    if (xs_type(location) == XSTYPE_DICT) {
 8+        const xs_number *latitude = xs_dict_get(location, "latitude");
 9+        const xs_number *longitude = xs_dict_get(location, "longitude");
10+        const char *name = xs_dict_get(location, "name");
11+        const char *address = xs_dict_get(location, "address");
12+        xs *label_list = xs_list_new();
13+
14+        if (xs_type(name) == XSTYPE_STRING)
15+            label_list = xs_list_append(label_list, name);
16+        if (xs_type(address) == XSTYPE_STRING)
17+            label_list = xs_list_append(label_list, address);
18+
19+        if (xs_list_len(label_list)) {
20+            xs *label = xs_join(label_list, ", ");
21+
22+            if (!xs_is_null(latitude) && !xs_is_null(longitude)) {
23+                xs *url = xs_fmt("https://openstreetmap.org/search/?query=%s,%s",
24+                    xs_number_str(latitude), xs_number_str(longitude));
25+
26+                xs_html_add(snac_content_wrap,
27+                    xs_html_tag("p",
28+                        xs_html_text(L("Location: ")),
29+                        xs_html_tag("a",
30+                            xs_html_attr("href", url),
31+                            xs_html_attr("target", "_blank"),
32+                            xs_html_text(label))));
33+            }
34+            else
35+                xs_html_add(snac_content_wrap,
36+                    xs_html_tag("p",
37+                        xs_html_text(L("Location: ")),
38+                        xs_html_text(label)));
39+        }
40+    }
41+
42     /* show all hashtags that has not been shown previously in the content */
43     const xs_list *tags = xs_dict_get(msg, "tag");
44     if (xs_type(tags) == XSTYPE_LIST && xs_list_len(tags)) {