commit 55d3ef5

default  ·  2023-11-08 08:20:34 +0000 UTC
parent 895cf82
Tags can now be searched for from the server base URL.
4 files changed,  +21, -5
M data.c
M html.c
M snac.h
M data.c
+2, -3
 1@@ -1575,7 +1575,6 @@ void tag_index(const char *id, const xs_dict *obj)
 2     xs_list *tags = xs_dict_get(obj, "tag");
 3 
 4     if (is_msg_public(obj) && xs_type(tags) == XSTYPE_LIST && xs_list_len(tags) > 0) {
 5-        xs *md5_id    = xs_md5_hex(id, strlen(id));
 6         xs *g_tag_dir = xs_fmt("%s/tag", srv_basedir);
 7 
 8         mkdirx(g_tag_dir);
 9@@ -1596,7 +1595,7 @@ void tag_index(const char *id, const xs_dict *obj)
10                 mkdirx(tag_dir);
11 
12                 xs *g_tag_idx = xs_fmt("%s/%s.idx", tag_dir, md5_tag);
13-                index_add(g_tag_idx, md5_id);
14+                index_add(g_tag_idx, id);
15 
16                 FILE *f;
17                 xs *g_tag_name = xs_replace(g_tag_idx, ".idx", ".tag");
18@@ -1605,7 +1604,7 @@ void tag_index(const char *id, const xs_dict *obj)
19                     fclose(f);
20                 }
21 
22-                srv_debug(0, xs_fmt("tagged %s #%s (%s #%s)", id, name, md5_id, md5_tag));
23+                srv_debug(0, xs_fmt("tagged %s #%s (#%s)", id, name, md5_tag));
24             }
25         }
26     }
M html.c
+1, -1
1@@ -1574,7 +1574,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int
2             continue;
3 
4         /* if it's an instance page, discard private users */
5-        if (user == NULL) {
6+        if (user == NULL && xs_startswith(xs_dict_get(msg, "id"), srv_baseurl)) {
7             const char *atto = xs_dict_get(msg, "attributedTo");
8             xs *l = xs_split(atto, "/");
9             const char *uid = xs_list_get(l, -1);
+15, -0
 1@@ -141,6 +141,21 @@ int server_get_handler(xs_dict *req, const char *q_path,
 2 
 3     /* is it the server root? */
 4     if (*q_path == '\0') {
 5+        xs_dict *q_vars = xs_dict_get(req, "q_vars");
 6+        char *t = NULL;
 7+
 8+        if (xs_type(q_vars) == XSTYPE_DICT && (t = xs_dict_get(q_vars, "t"))) {
 9+            /* tag search query */
10+            int skip = xs_number_get(xs_dict_get(q_vars, "skip"));
11+            int show = xs_number_get(xs_dict_get(q_vars, "show"));
12+
13+            if (show == 0)
14+                show = 64;
15+
16+            xs *tl = tag_search(t, skip, show);
17+            *body = html_timeline(NULL, tl, 0, skip, show, 0);
18+        }
19+        else
20         if (xs_type(xs_dict_get(srv_config, "show_instance_timeline")) == XSTYPE_TRUE) {
21             xs *tl = timeline_instance_list(0, 30);
22             *body = html_timeline(NULL, tl, 0, 0, 0, 0);
M snac.h
+3, -1
 1@@ -69,7 +69,8 @@ double mtime_nl(const char *fn, int *n_link);
 2 #define mtime(fn) mtime_nl(fn, NULL)
 3 double f_ctime(const char *fn);
 4 
 5-int index_add(const char *fn, const char *md5);
 6+int index_add_md5(const char *fn, const char *md5);
 7+int index_add(const char *fn, const char *id);
 8 int index_gc(const char *fn);
 9 int index_first(const char *fn, char *buf, int size);
10 int index_len(const char *fn);
11@@ -144,6 +145,7 @@ void hide(snac *snac, const char *id);
12 int is_hidden(snac *snac, const char *id);
13 
14 void tag_index(const char *id, const xs_dict *obj);
15+xs_list *tag_search(char *tag, int skip, int show);
16 
17 int actor_add(const char *actor, xs_dict *msg);
18 int actor_get(const char *actor, xs_dict **data);