diff options
| -rw-r--r-- | activitypub.c | 88 | ||||
| -rw-r--r-- | webfinger.c | 5 |
2 files changed, 47 insertions, 46 deletions
diff --git a/activitypub.c b/activitypub.c index 51a2cfa..13415df 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -368,6 +368,31 @@ void process_tags(snac *snac, const char *content, xs_str **n_content, xs_list * | |||
| 368 | xs_val *v; | 368 | xs_val *v; |
| 369 | int n = 0; | 369 | int n = 0; |
| 370 | 370 | ||
| 371 | /* create a default server for incomplete mentions */ | ||
| 372 | xs *def_srv = NULL; | ||
| 373 | |||
| 374 | if (xs_list_len(tl)) { | ||
| 375 | /* if there are any mentions, get the server from | ||
| 376 | the first one, which is the inReplyTo author */ | ||
| 377 | p = tl; | ||
| 378 | while (xs_list_iter(&p, &v)) { | ||
| 379 | const char *type = xs_dict_get(v, "type"); | ||
| 380 | const char *name = xs_dict_get(v, "name"); | ||
| 381 | |||
| 382 | if (type && name && strcmp(type, "Mention") == 0) { | ||
| 383 | xs *l = xs_split(name, "@"); | ||
| 384 | |||
| 385 | def_srv = xs_dup(xs_list_get(l, -1)); | ||
| 386 | |||
| 387 | break; | ||
| 388 | } | ||
| 389 | } | ||
| 390 | } | ||
| 391 | |||
| 392 | if (xs_is_null(def_srv)) | ||
| 393 | /* use this same server */ | ||
| 394 | def_srv = xs_dup(xs_dict_get(srv_config, "host")); | ||
| 395 | |||
| 371 | split = xs_regex_split(content, "(@[A-Za-z0-9_]+(@[A-Za-z0-9\\.-]+)?|&#[0-9]+;|#[^ ,\\.:;<]+)"); | 396 | split = xs_regex_split(content, "(@[A-Za-z0-9_]+(@[A-Za-z0-9\\.-]+)?|&#[0-9]+;|#[^ ,\\.:;<]+)"); |
| 372 | 397 | ||
| 373 | p = split; | 398 | p = split; |
| @@ -375,57 +400,36 @@ void process_tags(snac *snac, const char *content, xs_str **n_content, xs_list * | |||
| 375 | if ((n & 0x1)) { | 400 | if ((n & 0x1)) { |
| 376 | if (*v == '@') { | 401 | if (*v == '@') { |
| 377 | xs *link = NULL; | 402 | xs *link = NULL; |
| 403 | xs *wuid = NULL; | ||
| 378 | 404 | ||
| 379 | if (strchr(v + 1, '@') == NULL) { | 405 | if (strchr(v + 1, '@') == NULL) { |
| 380 | /* only one @? it's a dumb Mastodon-like mention | 406 | /* only one @? it's a dumb Mastodon-like mention |
| 381 | without server; check if there is anybody | 407 | without server; add the default one */ |
| 382 | whose name starts with this in the tag list */ | 408 | wuid = xs_fmt("%s@%s", v, def_srv); |
| 383 | xs_list *p2 = tl; | 409 | |
| 384 | xs_dict *v2; | 410 | snac_debug(snac, 2, xs_fmt("mention without server '%s' '%s'", v, wuid)); |
| 385 | xs *pname = xs_fmt("%s@", v); | ||
| 386 | |||
| 387 | while (xs_list_iter(&p2, &v2)) { | ||
| 388 | const char *type = xs_dict_get(v2, "type"); | ||
| 389 | |||
| 390 | if (type && strcmp(type, "Mention") == 0) { | ||
| 391 | const char *name = xs_dict_get(v2, "name"); | ||
| 392 | const char *href = xs_dict_get(v2, "href"); | ||
| 393 | |||
| 394 | if (name && href && (xs_startswith(name, pname) || | ||
| 395 | xs_startswith(name, pname + 1))) { | ||
| 396 | /* good enough :shrug2: */ | ||
| 397 | link = xs_fmt( | ||
| 398 | "<a href=\"%s\" class=\"u-url mention\">%s</a>", href, name); | ||
| 399 | |||
| 400 | break; | ||
| 401 | } | ||
| 402 | } | ||
| 403 | } | ||
| 404 | |||
| 405 | snac_debug(snac, 2, xs_fmt( | ||
| 406 | "mention without server '%s' (%s)", v, link ? link : "none")); | ||
| 407 | } | 411 | } |
| 408 | else { | 412 | else |
| 409 | /* query the webfinger about this fellow */ | 413 | wuid = xs_dup(v); |
| 410 | xs *v2 = xs_strip_chars_i(xs_dup(v), "@."); | 414 | |
| 411 | xs *actor = NULL; | 415 | /* query the webfinger about this fellow */ |
| 412 | xs *uid = NULL; | 416 | xs *actor = NULL; |
| 413 | int status; | 417 | xs *uid = NULL; |
| 418 | int status; | ||
| 414 | 419 | ||
| 415 | status = webfinger_request(v2, &actor, &uid); | 420 | status = webfinger_request(wuid, &actor, &uid); |
| 416 | 421 | ||
| 417 | if (valid_status(status)) { | 422 | if (valid_status(status)) { |
| 418 | xs *d = xs_dict_new(); | 423 | xs *d = xs_dict_new(); |
| 419 | xs *n = xs_fmt("@%s", uid); | 424 | xs *n = xs_fmt("@%s", uid); |
| 420 | 425 | ||
| 421 | d = xs_dict_append(d, "type", "Mention"); | 426 | d = xs_dict_append(d, "type", "Mention"); |
| 422 | d = xs_dict_append(d, "href", actor); | 427 | d = xs_dict_append(d, "href", actor); |
| 423 | d = xs_dict_append(d, "name", n); | 428 | d = xs_dict_append(d, "name", n); |
| 424 | 429 | ||
| 425 | tl = xs_list_append(tl, d); | 430 | tl = xs_list_append(tl, d); |
| 426 | 431 | ||
| 427 | link = xs_fmt("<a href=\"%s\" class=\"u-url mention\">%s</a>", actor, n); | 432 | link = xs_fmt("<a href=\"%s\" class=\"u-url mention\">%s</a>", actor, n); |
| 428 | } | ||
| 429 | } | 433 | } |
| 430 | 434 | ||
| 431 | if (!xs_is_null(link)) | 435 | if (!xs_is_null(link)) |
diff --git a/webfinger.c b/webfinger.c index c7b73f7..c743455 100644 --- a/webfinger.c +++ b/webfinger.c | |||
| @@ -30,10 +30,7 @@ int webfinger_request(const char *qs, char **actor, char **user) | |||
| 30 | } | 30 | } |
| 31 | else { | 31 | else { |
| 32 | /* it's a user */ | 32 | /* it's a user */ |
| 33 | xs *s = xs_dup(qs); | 33 | xs *s = xs_strip_chars_i(xs_dup(qs), "@."); |
| 34 | |||
| 35 | if (xs_startswith(s, "@")) | ||
| 36 | s = xs_crop_i(s, 1, 0); | ||
| 37 | 34 | ||
| 38 | l = xs_split_n(s, "@", 1); | 35 | l = xs_split_n(s, "@", 1); |
| 39 | 36 | ||