Tags can now be searched for from the server base URL.

This commit is contained in:
default 2023-11-08 09:20:34 +01:00
parent 895cf82a7d
commit 55d3ef5024
4 changed files with 21 additions and 5 deletions

5
data.c
View file

@ -1575,7 +1575,6 @@ void tag_index(const char *id, const xs_dict *obj)
xs_list *tags = xs_dict_get(obj, "tag"); xs_list *tags = xs_dict_get(obj, "tag");
if (is_msg_public(obj) && xs_type(tags) == XSTYPE_LIST && xs_list_len(tags) > 0) { if (is_msg_public(obj) && xs_type(tags) == XSTYPE_LIST && xs_list_len(tags) > 0) {
xs *md5_id = xs_md5_hex(id, strlen(id));
xs *g_tag_dir = xs_fmt("%s/tag", srv_basedir); xs *g_tag_dir = xs_fmt("%s/tag", srv_basedir);
mkdirx(g_tag_dir); mkdirx(g_tag_dir);
@ -1596,7 +1595,7 @@ void tag_index(const char *id, const xs_dict *obj)
mkdirx(tag_dir); mkdirx(tag_dir);
xs *g_tag_idx = xs_fmt("%s/%s.idx", tag_dir, md5_tag); xs *g_tag_idx = xs_fmt("%s/%s.idx", tag_dir, md5_tag);
index_add(g_tag_idx, md5_id); index_add(g_tag_idx, id);
FILE *f; FILE *f;
xs *g_tag_name = xs_replace(g_tag_idx, ".idx", ".tag"); xs *g_tag_name = xs_replace(g_tag_idx, ".idx", ".tag");
@ -1605,7 +1604,7 @@ void tag_index(const char *id, const xs_dict *obj)
fclose(f); fclose(f);
} }
srv_debug(0, xs_fmt("tagged %s #%s (%s #%s)", id, name, md5_id, md5_tag)); srv_debug(0, xs_fmt("tagged %s #%s (#%s)", id, name, md5_tag));
} }
} }
} }

2
html.c
View file

@ -1574,7 +1574,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int
continue; continue;
/* if it's an instance page, discard private users */ /* if it's an instance page, discard private users */
if (user == NULL) { if (user == NULL && xs_startswith(xs_dict_get(msg, "id"), srv_baseurl)) {
const char *atto = xs_dict_get(msg, "attributedTo"); const char *atto = xs_dict_get(msg, "attributedTo");
xs *l = xs_split(atto, "/"); xs *l = xs_split(atto, "/");
const char *uid = xs_list_get(l, -1); const char *uid = xs_list_get(l, -1);

15
httpd.c
View file

@ -141,6 +141,21 @@ int server_get_handler(xs_dict *req, const char *q_path,
/* is it the server root? */ /* is it the server root? */
if (*q_path == '\0') { if (*q_path == '\0') {
xs_dict *q_vars = xs_dict_get(req, "q_vars");
char *t = NULL;
if (xs_type(q_vars) == XSTYPE_DICT && (t = xs_dict_get(q_vars, "t"))) {
/* tag search query */
int skip = xs_number_get(xs_dict_get(q_vars, "skip"));
int show = xs_number_get(xs_dict_get(q_vars, "show"));
if (show == 0)
show = 64;
xs *tl = tag_search(t, skip, show);
*body = html_timeline(NULL, tl, 0, skip, show, 0);
}
else
if (xs_type(xs_dict_get(srv_config, "show_instance_timeline")) == XSTYPE_TRUE) { if (xs_type(xs_dict_get(srv_config, "show_instance_timeline")) == XSTYPE_TRUE) {
xs *tl = timeline_instance_list(0, 30); xs *tl = timeline_instance_list(0, 30);
*body = html_timeline(NULL, tl, 0, 0, 0, 0); *body = html_timeline(NULL, tl, 0, 0, 0, 0);

4
snac.h
View file

@ -69,7 +69,8 @@ double mtime_nl(const char *fn, int *n_link);
#define mtime(fn) mtime_nl(fn, NULL) #define mtime(fn) mtime_nl(fn, NULL)
double f_ctime(const char *fn); double f_ctime(const char *fn);
int index_add(const char *fn, const char *md5); int index_add_md5(const char *fn, const char *md5);
int index_add(const char *fn, const char *id);
int index_gc(const char *fn); int index_gc(const char *fn);
int index_first(const char *fn, char *buf, int size); int index_first(const char *fn, char *buf, int size);
int index_len(const char *fn); int index_len(const char *fn);
@ -144,6 +145,7 @@ void hide(snac *snac, const char *id);
int is_hidden(snac *snac, const char *id); int is_hidden(snac *snac, const char *id);
void tag_index(const char *id, const xs_dict *obj); void tag_index(const char *id, const xs_dict *obj);
xs_list *tag_search(char *tag, int skip, int show);
int actor_add(const char *actor, xs_dict *msg); int actor_add(const char *actor, xs_dict *msg);
int actor_get(const char *actor, xs_dict **data); int actor_get(const char *actor, xs_dict **data);