mirror of
https://github.com/AMNatty/Mastodon-Circles.git
synced 2024-11-09 12:51:26 -07:00
handle inputs for non-delegated usernames as well
This commit is contained in:
parent
5e1ef08548
commit
d3299af352
1 changed files with 8 additions and 5 deletions
|
@ -556,15 +556,19 @@ function parseHandle(fediHandle, fallbackInstance = "") {
|
|||
|
||||
/**
|
||||
* @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,
|
||||
// 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 selfLink = response.links.find(link => link.rel == 'self')
|
||||
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";
|
||||
|
||||
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 backend = form.backend;
|
||||
|
|
Loading…
Reference in a new issue