generalise fallback for glitch-soc notifications

This commit is contained in:
Vipra 2023-07-13 18:33:37 +02:00
parent 87906f2772
commit 3b779be8c8
2 changed files with 11 additions and 12 deletions

View file

@ -318,11 +318,7 @@ async function addProplate(element) {
// This allows us to pass incomplete nodes into this method, because // This allows us to pass incomplete nodes into this method, because
// we only process them after we have all required information. // we only process them after we have all required information.
let tempType = "status"; generateProPlate(statusId, accountName, nametagEl, "status");
if (location.href.endsWith("notifications")) tempType = "notification";
generateProPlate(statusId, accountName, nametagEl, tempType);
} }
async function addToNotification(element) { async function addToNotification(element) {
@ -337,7 +333,7 @@ async function addProplate(element) {
let nametagEl = accountNameEl; let nametagEl = accountNameEl;
element.setAttribute("protoots-checked", "true"); element.setAttribute("protoots-checked", "true");
generateProPlate(statusId, accountName, nametagEl, "notification"); //FIXME: change back to notification when done testing generateProPlate(statusId, accountName, nametagEl, "notification");
} }
async function addToAccount(element) { async function addToAccount(element) {
@ -350,11 +346,7 @@ async function addProplate(element) {
element.setAttribute("protoots-checked", "true"); element.setAttribute("protoots-checked", "true");
let tempType = "account"; generateProPlate(statusId, accountName, nametagEl, "account");
if (location.href.endsWith("notifications")) tempType = "notification";
generateProPlate(statusId, accountName, nametagEl, tempType);
} }
async function addToConversation(element) { async function addToConversation(element) {

View file

@ -1,4 +1,4 @@
import { debug, error, info, warn } from "./logging"; import { debug, error, info, log, warn } from "./logging";
import { cachePronouns, getPronouns } from "./caching"; import { cachePronouns, getPronouns } from "./caching";
import { normaliseAccountName } from "./protootshelpers"; import { normaliseAccountName } from "./protootshelpers";
@ -60,6 +60,9 @@ export async function fetchPronouns(dataID, accountName, type) {
status = await fetchStatus(dataID); status = await fetchStatus(dataID);
} }
log(`Fetching ${type} failed, trying notification instead.`);
if (!status) status = await fetchNotification(dataID); //fallback for glitch-soc notifications
const PronounField = getPronounField(status, accountName); const PronounField = getPronounField(status, accountName);
if (PronounField == "null") { if (PronounField == "null") {
//TODO: if no field check bio //TODO: if no field check bio
@ -86,6 +89,8 @@ async function fetchStatus(statusID) {
let status = await response.json(); let status = await response.json();
if (!response.ok) return null;
//if status contains a reblog get that for further processing - we want the embedded post's author //if status contains a reblog get that for further processing - we want the embedded post's author
if (status.reblog) status = status.reblog; if (status.reblog) status = status.reblog;
return status; return status;
@ -128,6 +133,8 @@ async function fetchAccount(accountID) {
}, },
); );
if (!response.ok) return null;
const account = await response.json(); const account = await response.json();
return { account: account }; return { account: account };