From b6c4906c6af96ca3847cc716f3c3174bbc0085b4 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 27 Sep 2022 18:20:25 +0200 Subject: [PATCH] New function process_tags() (untested). --- activitypub.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/activitypub.c b/activitypub.c index edb32c7..47e9efe 100644 --- a/activitypub.c +++ b/activitypub.c @@ -7,6 +7,7 @@ #include "xs_curl.h" #include "xs_mime.h" #include "xs_openssl.h" +#include "xs_regex.h" #include "snac.h" @@ -202,6 +203,57 @@ int is_msg_public(snac *snac, char *msg) } +void process_tags(const char *content, d_char **n_content, d_char **tag) +/* parses mentions and tags from content */ +{ + d_char *nc = xs_str_new(NULL); + d_char *tl = xs_list_new(); + xs *split; + char *p, *v; + int n = 0; + + p = split = xs_regex_split(content, "(@[A-Za-z0-9_]+@[A-Za-z0-9-\\.]+|#[^ ]+)"); + while (xs_list_iter(&p, &v)) { + if ((n & 0x1)) { + if (*v == '@') { + /* query the webfinger about this fellow */ + xs *actor = NULL; + xs *uid = NULL; + int status; + + status = webfinger_request(v, &actor, &uid); + + if (valid_status(status)) { + xs *d = xs_dict_new(); + + d = xs_dict_append(d, "type", "Mention"); + d = xs_dict_append(d, "href", actor); + d = xs_dict_append(d, "name", uid); + + tl = xs_list_append(tl, d); + } + else + /* store as is */ + nc = xs_str_cat(nc, v); + } + else + if (*v == '#') { + /* hashtag */ + /* store as is by now */ + nc = xs_str_cat(nc, v); + } + } + else + nc = xs_str_cat(nc, v); + + n++; + } + + *n_content = nc; + *tag = tl; +} + + /** messages **/ d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date, char *object)