handle inputs for non-delegated usernames as well

This commit is contained in:
hazycora 2023-08-31 12:07:23 -05:00
parent 5e1ef08548
commit d3299af352
No known key found for this signature in database
GPG key ID: 215AF1F81F86940E

View file

@ -556,15 +556,19 @@ function parseHandle(fediHandle, fallbackInstance = "") {
/** /**
* @typedef @param {Handle} handle * @typedef @param {Handle} handle
* @returns {Promise<string>} instance * @returns {Promise<Handle>}
*/ */
async function getDelegateInstance(handle) { async function getDelegatedHandle(handle) {
// We're checking webfinger to see which URL is for the user, // We're checking webfinger to see which URL is for the user,
// since that may be on a different domain than the webfinger request // since that may be on a different domain than the webfinger request
const response = await apiRequest(`https://${handle.instance}/.well-known/webfinger?resource=acct:${handle.handle}`) const response = await apiRequest(`https://${handle.instance}/.well-known/webfinger?resource=acct:${handle.handle}`)
const selfLink = response.links.find(link => link.rel == 'self') const selfLink = response.links.find(link => link.rel == 'self')
const url = new URL(selfLink.href) const url = new URL(selfLink.href)
return url.hostname; handle.instance = url.hostname;
// If a user inputs @h@social.besties.house but their handle is actually @h@besties.house,
// we want to use the latter
handle.handle = response.subject?.replace(/^acct:/, '') ?? handle.handle;
return handle
} }
/** /**
@ -579,9 +583,8 @@ async function circleMain() {
generateBtn.style.display = "none"; generateBtn.style.display = "none";
let fediHandle = document.getElementById("txt_mastodon_handle"); let fediHandle = document.getElementById("txt_mastodon_handle");
const selfUser = parseHandle(fediHandle.value);
selfUser.instance = await getDelegateInstance(selfUser) const selfUser = await getDelegatedHandle(parseHandle(fediHandle.value));
let form = document.getElementById("generateForm"); let form = document.getElementById("generateForm");
let backend = form.backend; let backend = form.backend;