commit a3b9ef5

default  ·  2024-02-20 05:10:42 +0000 UTC
parent d583a35
The link verification time is stored as a time_t.

This way, it will be easier in an eventual future to test if
a link verification is too old to be trusted.
3 files changed,  +33, -11
M html.c
M html.c
+13, -3
 1@@ -779,11 +779,21 @@ static xs_html *html_user_body(snac *user, int local)
 2 
 3                 if (xs_startswith(v, "https:/" "/")) {
 4                     /* is this link validated? */
 5-                    char *val_date = xs_dict_get(val_links, v);
 6+                    xs *verified_link = NULL;
 7+                    xs_number *val_time = xs_dict_get(val_links, v);
 8 
 9-                    if (!xs_is_null(val_date) && *val_date) {
10+                    if (xs_type(val_time) == XSTYPE_NUMBER) {
11+                        time_t t = xs_number_get(val_time);
12+
13+                        if (t > 0) {
14+                            xs *s1 = xs_str_utctime(t, ISO_DATE_SPEC);
15+                            verified_link = xs_fmt("%s (%s)", L("verified link"), s1);
16+                        }
17+                    }
18+
19+                    if (!xs_is_null(verified_link)) {
20                         value = xs_html_tag("span",
21-                            xs_html_attr("title", L("verified link")),
22+                            xs_html_attr("title", verified_link),
23                             xs_html_raw("✔ "),
24                             xs_html_tag("a",
25                                 xs_html_attr("href", v),
+18, -6
 1@@ -642,10 +642,17 @@ xs_dict *mastoapi_account(const xs_dict *actor)
 2 
 3         if (!xs_is_null(type) && !xs_is_null(name) &&
 4             !xs_is_null(value) && strcmp(type, "PropertyValue") == 0) {
 5-            char *val_date = NULL;
 6+            xs *val_date = NULL;
 7 
 8-            if (xs_startswith(value, "https:/" "/"))
 9-                val_date = xs_dict_get(val_links, value);
10+            if (xs_startswith(value, "https:/" "/")) {
11+                xs_number *verified_time = xs_dict_get(val_links, value);
12+                if (xs_type(verified_time) == XSTYPE_NUMBER) {
13+                    time_t t = xs_number_get(verified_time);
14+
15+                    if (t > 0)
16+                        val_date = xs_str_utctime(t, ISO_DATE_SPEC);
17+                }
18+            }
19 
20             xs *d = xs_dict_new();
21 
22@@ -1161,10 +1168,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
23                     val_links = xs_stock_dict;
24 
25                 while (xs_dict_iter(&metadata, &k, &v)) {
26-                    char *val_date = NULL;
27+                    xs *val_date = NULL;
28 
29-                    if (xs_startswith(v, "https:/" "/"))
30-                        val_date = xs_dict_get(val_links, v);
31+                    xs_number *verified_time = xs_dict_get(val_links, v);
32+                    if (xs_type(verified_time) == XSTYPE_NUMBER) {
33+                        time_t t = xs_number_get(verified_time);
34+
35+                        if (t > 0)
36+                            val_date = xs_str_utctime(t, ISO_DATE_SPEC);
37+                    }
38 
39                     xs *d = xs_dict_new();
40 
+2, -2
 1@@ -491,12 +491,12 @@ void verify_links(snac *user)
 2                 /* is it the same as the actor? */
 3                 if (strcmp(href, user->actor) == 0) {
 4                     /* got it! */
 5-                    xs *verified_at = xs_str_utctime(0, ISO_DATE_SPEC);
 6+                    xs *verified_time = xs_number_new((double)time(NULL));
 7 
 8                     if (user->links == NULL)
 9                         user->links = xs_dict_new();
10 
11-                    user->links = xs_dict_set(user->links, v, verified_at);
12+                    user->links = xs_dict_set(user->links, v, verified_time);
13 
14                     vfied = 1;
15                 }