Merged profile-page into the Handle logic

This commit is contained in:
Natty 2023-09-01 17:48:52 +02:00
parent 1823230b64
commit c444f4be3d
No known key found for this signature in database
GPG key ID: BF6CB659ADEE60EC

View file

@ -32,6 +32,7 @@ function Handle(name, instance) {
handleObj.instance = instance; handleObj.instance = instance;
handleObj._baseInstance = null; handleObj._baseInstance = null;
handleObj._apiInstance = null; handleObj._apiInstance = null;
handleObj.profileUrl = null;
return handleObj; return handleObj;
} }
@ -106,6 +107,15 @@ Handle.prototype.webFinger = async function () {
console.error(`Error parsing WebFinger self link ${selfLink["href"]}: ${e}`); console.error(`Error parsing WebFinger self link ${selfLink["href"]}: ${e}`);
} }
const profileLink = links.find(link => link["rel"] === "http://webfinger.net/rel/profile-page");
if (profileLink?.["href"]) {
try {
baseHandle.profileUrl = new URL(profileLink["href"]);
} catch (e) {
console.error(`Error parsing WebFinger profile page link ${profileLink["href"]}: ${e}`);
}
}
return baseHandle; return baseHandle;
}; };
@ -791,30 +801,6 @@ function incConnectionValue(connectionList, user, plus) {
connectionList.get(user.id).conStrength += plus; connectionList.get(user.id).conStrength += plus;
} }
// TODO: Store the profile URL in the handle
async function webfingerVisit(name, instance) {
const webfingerUrl = `https://${instance}/.well-known/webfinger?resource=acct:${name}@${instance}`;
const response = await apiRequest(webfingerUrl);
if (!response) {
return;
}
const links = response.links;
if (!Array.isArray(links)) {
return;
}
const profileLink = links.find(link => link.rel === "http://webfinger.net/rel/profile-page");
if (!profileLink) {
return;
}
window.open(profileLink.href, "_blank");
}
/** /**
* @param {FediUser} localUser * @param {FediUser} localUser
* @param {Map<string, RatedUser>} connectionList * @param {Map<string, RatedUser>} connectionList
@ -845,8 +831,16 @@ function showConnections(localUser, connectionList) {
newUser.className = "userItem"; newUser.className = "userItem";
newUser.innerText = items[i].handle.name; newUser.innerText = items[i].handle.name;
newUser.title = items[i].name; newUser.title = items[i].name;
// I'm so sorry
newUser.href = "javascript:void(0)";
const handle = items[i].handle; const handle = items[i].handle;
newUser.href = `javascript: webfingerVisit(${JSON.stringify(handle.name)}, ${JSON.stringify(handle.instance)})`; newUser.onclick = async () => {
const fingeredHandle = await handle.webFinger();
if (fingeredHandle.profileUrl)
window.open(fingeredHandle.profileUrl, "_blank");
else
alert("Could not the profile URL for " + fingeredHandle.baseHandle);
};
const newUserHost = document.createElement("span"); const newUserHost = document.createElement("span");
newUserHost.className = "userHost"; newUserHost.className = "userHost";
@ -857,6 +851,9 @@ function showConnections(localUser, connectionList) {
newUserImg.src = items[i].avatar; newUserImg.src = items[i].avatar;
newUserImg.title = newUserImg.alt = stripName(items[i].name || items[i].handle.name) + "'s avatar"; newUserImg.title = newUserImg.alt = stripName(items[i].name || items[i].handle.name) + "'s avatar";
newUserImg.className = "userImg"; newUserImg.className = "userImg";
newUserImg.onerror = () => {
newUserImg.alt = "";
};
newUser.prepend(newUserImg); newUser.prepend(newUserImg);
let udNum = 0; let udNum = 0;