diff options
| author | 2023-01-12 13:49:37 +0100 | |
|---|---|---|
| committer | 2023-01-12 13:49:37 +0100 | |
| commit | 1d0ab9c1566041afd8519bf9640dc174ad311d7f (patch) | |
| tree | a6fd7f3cbe0fbe41b66394b4f456b91fda457f26 /activitypub.c | |
| parent | Backport from xs. (diff) | |
| download | snac2-1d0ab9c1566041afd8519bf9640dc174ad311d7f.tar.gz snac2-1d0ab9c1566041afd8519bf9640dc174ad311d7f.tar.xz snac2-1d0ab9c1566041afd8519bf9640dc174ad311d7f.zip | |
Added (partial) support for #HashTags in posts.
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/activitypub.c b/activitypub.c index 92f664c..3eb88c6 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -261,7 +261,7 @@ int is_msg_public(snac *snac, char *msg) | |||
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | 263 | ||
| 264 | void process_tags(const char *content, d_char **n_content, d_char **tag) | 264 | void process_tags(snac *snac, const char *content, d_char **n_content, d_char **tag) |
| 265 | /* parses mentions and tags from content */ | 265 | /* parses mentions and tags from content */ |
| 266 | { | 266 | { |
| 267 | d_char *nc = xs_str_new(NULL); | 267 | d_char *nc = xs_str_new(NULL); |
| @@ -270,7 +270,7 @@ void process_tags(const char *content, d_char **n_content, d_char **tag) | |||
| 270 | char *p, *v; | 270 | char *p, *v; |
| 271 | int n = 0; | 271 | int n = 0; |
| 272 | 272 | ||
| 273 | split = xs_regex_split(content, "(@[A-Za-z0-9_]+@[A-Za-z0-9\\.-]+|#[^ ,\\.:;]+)"); | 273 | split = xs_regex_split(content, "(@[A-Za-z0-9_]+@[A-Za-z0-9\\.-]+|#[^ ,\\.:;<]+)"); |
| 274 | 274 | ||
| 275 | p = split; | 275 | p = split; |
| 276 | while (xs_list_iter(&p, &v)) { | 276 | while (xs_list_iter(&p, &v)) { |
| @@ -304,8 +304,19 @@ void process_tags(const char *content, d_char **n_content, d_char **tag) | |||
| 304 | else | 304 | else |
| 305 | if (*v == '#') { | 305 | if (*v == '#') { |
| 306 | /* hashtag */ | 306 | /* hashtag */ |
| 307 | /* store as is by now */ | 307 | xs *d = xs_dict_new(); |
| 308 | nc = xs_str_cat(nc, v); | 308 | xs *n = xs_tolower_i(xs_dup(v)); |
| 309 | xs *h = xs_fmt("%s%s", snac->actor, n); | ||
| 310 | xs *l = xs_fmt("<a href=\"%s\" class=\"mention hashtag\" rel=\"tag\">%s</a>", h, v); | ||
| 311 | |||
| 312 | d = xs_dict_append(d, "type", "Hashtag"); | ||
| 313 | d = xs_dict_append(d, "href", h); | ||
| 314 | d = xs_dict_append(d, "name", n); | ||
| 315 | |||
| 316 | tl = xs_list_append(tl, d); | ||
| 317 | |||
| 318 | /* add the code */ | ||
| 319 | nc = xs_str_cat(nc, l); | ||
| 309 | } | 320 | } |
| 310 | } | 321 | } |
| 311 | else | 322 | else |
| @@ -601,7 +612,7 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char | |||
| 601 | fc2 = not_really_markdown(content); | 612 | fc2 = not_really_markdown(content); |
| 602 | 613 | ||
| 603 | /* extract the tags */ | 614 | /* extract the tags */ |
| 604 | process_tags(fc2, &fc1, &tag); | 615 | process_tags(snac, fc2, &fc1, &tag); |
| 605 | 616 | ||
| 606 | if (tag == NULL) | 617 | if (tag == NULL) |
| 607 | tag = xs_list_new(); | 618 | tag = xs_list_new(); |