diff options
| author | 2024-12-19 05:00:23 +0100 | |
|---|---|---|
| committer | 2024-12-19 05:00:23 +0100 | |
| commit | 7b8f766feb35629c7db6e9392dbe9de2dd6f7239 (patch) | |
| tree | 3b868c179624509db9419dfce3a59a2ba15b3885 /html.c | |
| parent | content_search() also checks for the post id. (diff) | |
| download | snac2-7b8f766feb35629c7db6e9392dbe9de2dd6f7239.tar.gz snac2-7b8f766feb35629c7db6e9392dbe9de2dd6f7239.tar.xz snac2-7b8f766feb35629c7db6e9392dbe9de2dd6f7239.zip | |
Searching for URLs brings a post to the user timeline.
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 45 |
1 files changed, 45 insertions, 0 deletions
| @@ -2996,6 +2996,51 @@ int html_get_handler(const xs_dict *req, const char *q_path, | |||
| 2996 | } | 2996 | } |
| 2997 | else { | 2997 | else { |
| 2998 | const char *q = xs_dict_get(q_vars, "q"); | 2998 | const char *q = xs_dict_get(q_vars, "q"); |
| 2999 | xs *url_acct = NULL; | ||
| 3000 | |||
| 3001 | /* searching for an URL? */ | ||
| 3002 | if (q && xs_match(q, "https://*|http://*")) { | ||
| 3003 | /* may by an actor; try a webfinger */ | ||
| 3004 | xs *actor_obj = NULL; | ||
| 3005 | |||
| 3006 | if (valid_status(webfinger_request(q, &actor_obj, &url_acct))) { | ||
| 3007 | /* it's an actor; do the dirty trick of changing q to the account name */ | ||
| 3008 | q = url_acct; | ||
| 3009 | } | ||
| 3010 | else { | ||
| 3011 | /* if it's not already here, try to bring it to the user's timeline */ | ||
| 3012 | xs *md5 = xs_md5_hex(q, strlen(q)); | ||
| 3013 | |||
| 3014 | if (!timeline_here(&snac, md5)) { | ||
| 3015 | xs *object = NULL; | ||
| 3016 | int status; | ||
| 3017 | |||
| 3018 | status = activitypub_request(&snac, q, &object); | ||
| 3019 | snac_debug(&snac, 1, xs_fmt("Request searched URL %s %d", q, status)); | ||
| 3020 | |||
| 3021 | if (valid_status(status)) { | ||
| 3022 | /* got it; also request the actor */ | ||
| 3023 | const char *attr_to = get_atto(object); | ||
| 3024 | |||
| 3025 | if (!xs_is_null(attr_to)) { | ||
| 3026 | status = actor_request(&snac, attr_to, &actor_obj); | ||
| 3027 | |||
| 3028 | snac_debug(&snac, 1, xs_fmt("Request author %s of %s %d", attr_to, q, status)); | ||
| 3029 | |||
| 3030 | if (valid_status(status)) { | ||
| 3031 | /* add the actor */ | ||
| 3032 | actor_add(attr_to, actor_obj); | ||
| 3033 | |||
| 3034 | /* add the post to the timeline */ | ||
| 3035 | timeline_add(&snac, q, object); | ||
| 3036 | } | ||
| 3037 | } | ||
| 3038 | } | ||
| 3039 | } | ||
| 3040 | } | ||
| 3041 | |||
| 3042 | /* fall through */ | ||
| 3043 | } | ||
| 2999 | 3044 | ||
| 3000 | if (q && *q) { | 3045 | if (q && *q) { |
| 3001 | if (xs_regex_match(q, "^@?[a-zA-Z0-9_]+@[a-zA-Z0-9-]+\\.")) { | 3046 | if (xs_regex_match(q, "^@?[a-zA-Z0-9_]+@[a-zA-Z0-9-]+\\.")) { |