commit 2afcb4b

default  ·  2024-02-15 09:46:16 +0000 UTC
parent b4208bf
mastoapi: fill the verified_at fields in mastoapi_account() for local users.
1 files changed,  +26, -2
+26, -2
 1@@ -622,6 +622,22 @@ xs_dict *mastoapi_account(const xs_dict *actor)
 2     p = xs_dict_get(actor, "attachment");
 3     xs_dict *v;
 4 
 5+    /* dict of validated links */
 6+    xs_dict *val_links = NULL;
 7+
 8+    if (xs_startswith(id, srv_baseurl)) {
 9+        /* if it's a local user, open it and pick its validated links */
10+        snac user;
11+
12+        if (user_open(&user, prefu)) {
13+            val_links = xs_dict_get(user.config, "validated_links");
14+            user_free(&user);
15+        }
16+    }
17+
18+    if (xs_is_null(val_links))
19+        val_links = xs_stock_dict;
20+
21     while (xs_list_iter(&p, &v)) {
22         char *type  = xs_dict_get(v, "type");
23         char *name  = xs_dict_get(v, "name");
24@@ -629,11 +645,18 @@ xs_dict *mastoapi_account(const xs_dict *actor)
25 
26         if (!xs_is_null(type) && !xs_is_null(name) &&
27             !xs_is_null(value) && strcmp(type, "PropertyValue") == 0) {
28+            char *val_date = NULL;
29+
30+            if (xs_startswith(value, "https:/" "/"))
31+                val_date = xs_dict_get(val_links, value);
32+
33             xs *d = xs_dict_new();
34 
35             d = xs_dict_append(d, "name", name);
36             d = xs_dict_append(d, "value", value);
37-            d = xs_dict_append(d, "verified_at", xs_stock_null);
38+            d = xs_dict_append(d, "verified_at",
39+                xs_type(val_date) == XSTYPE_STRING && *val_date ?
40+                    val_date : xs_stock_null);
41 
42             fields = xs_list_append(fields, d);
43         }
44@@ -1149,7 +1172,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
45                     d = xs_dict_append(d, "name", k);
46                     d = xs_dict_append(d, "value", v);
47                     d = xs_dict_append(d, "verified_at",
48-                        xs_type(val_date) == XSTYPE_STRING ? val_date : xs_stock_null);
49+                        xs_type(val_date) == XSTYPE_STRING && *val_date ?
50+                            val_date : xs_stock_null);
51 
52                     fields = xs_list_append(fields, d);
53                 }