Added support for caching pronouncs

This commit is contained in:
nuttylmao
2025-04-06 09:03:20 +10:00
parent a2e2e01541
commit 42117519c7
2 changed files with 36 additions and 16 deletions
+18 -8
View File
@@ -8,6 +8,7 @@ const urlParams = new URLSearchParams(queryString);
const sbServerAddress = urlParams.get("address") || "127.0.0.1";
const sbServerPort = urlParams.get("port") || "8080";
const avatarMap = new Map();
const pronounMap = new Map();
/////////////
// OPTIONS //
@@ -1772,14 +1773,23 @@ async function GetAvatar(username) {
}
async function GetPronouns(platform, username) {
const response = await client.getUserPronouns(platform, username);
const userFound = response.pronoun.userFound;
const pronouns = `${response.pronoun.pronounSubject}/${response.pronoun.pronounObject}`;
if (userFound)
return `${response.pronoun.pronounSubject}/${response.pronoun.pronounObject}`;
else
return '';
if (pronounMap.has(username)) {
console.debug(`Pronouns found for ${username}. Retrieving from hash map.`)
return pronounMap.get(username);
}
else {
console.debug(`No pronouns found for ${username}. Retrieving from alejo.io.`)
const response = await client.getUserPronouns(platform, username);
const userFound = response.pronoun.userFound;
const pronouns = `${response.pronoun.pronounSubject}/${response.pronoun.pronounObject}`;
pronounMap.set(username, pronouns);
if (userFound)
return pronouns;
else
return '';
}
}
// function IsImageUrl(url) {