reuse userinfo for isVip and remove lastIsVipUpdate

This commit is contained in:
Michael C
2022-04-19 18:41:06 -04:00
parent 8aa10605c5
commit ac533c612c
3 changed files with 10 additions and 35 deletions

View File

@@ -487,6 +487,10 @@ function migrateOldSyncFormats(config: SBConfig) {
if (!config["supportInvidious"] && config["invidiousInstances"].length !== invidiousList.length) { if (!config["supportInvidious"] && config["invidiousInstances"].length !== invidiousList.length) {
config["invidiousInstances"] = invidiousList; config["invidiousInstances"] = invidiousList;
} }
if (config["lastIsVipUpdate"]) {
chrome.storage.sync.remove("lastIsVipUpdate");
}
} }
async function setupConfig() { async function setupConfig() {

View File

@@ -844,7 +844,9 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) {
retryFetch(); retryFetch();
} }
lookupVipInformation(id); if (Config.config.isVip) {
lockedCategoriesLookup(id);
}
} }
function getEnabledActionTypes(): ActionType[] { function getEnabledActionTypes(): ActionType[] {
@@ -859,39 +861,6 @@ function getEnabledActionTypes(): ActionType[] {
return actionTypes; return actionTypes;
} }
function lookupVipInformation(id: string): void {
updateVipInfo().then((isVip) => {
if (isVip) {
lockedCategoriesLookup(id);
}
});
}
async function updateVipInfo(): Promise<boolean> {
const currentTime = Date.now();
const lastUpdate = Config.config.lastIsVipUpdate;
if (currentTime - lastUpdate > 1000 * 60 * 60 * 72) { // 72 hours
Config.config.lastIsVipUpdate = currentTime;
const response = await utils.asyncRequestToServer("GET", "/api/isUserVIP", { userID: Config.config.userID});
if (response.ok) {
let isVip = false;
try {
const vipResponse = JSON.parse(response.responseText)?.vip;
if (typeof(vipResponse) === "boolean") {
isVip = vipResponse;
}
} catch (e) { } //eslint-disable-line no-empty
Config.config.isVip = isVip;
return isVip;
}
}
return Config.config.isVip;
}
async function lockedCategoriesLookup(id: string): Promise<void> { async function lockedCategoriesLookup(id: string): Promise<void> {
const hashPrefix = (await utils.getHash(id, 1)).slice(0, 4); const hashPrefix = (await utils.getHash(id, 1)).slice(0, 4);
const response = await utils.asyncRequestToServer("GET", "/api/lockCategories/" + hashPrefix); const response = await utils.asyncRequestToServer("GET", "/api/lockCategories/" + hashPrefix);

View File

@@ -175,7 +175,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
PageElements.showNoticeAgain.style.display = "unset"; PageElements.showNoticeAgain.style.display = "unset";
} }
utils.sendRequestToServer("GET", "/api/userInfo?value=userName&value=viewCount&value=minutesSaved&userID=" + Config.config.userID, (res) => { utils.sendRequestToServer("GET", "/api/userInfo?value=userName&value=viewCount&value=minutesSaved&value=vip&userID=" + Config.config.userID, (res) => {
if (res.status === 200) { if (res.status === 200) {
const userInfo = JSON.parse(res.responseText); const userInfo = JSON.parse(res.responseText);
PageElements.usernameValue.innerText = userInfo.userName; PageElements.usernameValue.innerText = userInfo.userName;
@@ -202,6 +202,8 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
} }
PageElements.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved); PageElements.sponsorTimesOthersTimeSavedDisplay.innerText = getFormattedHours(minutesSaved);
} }
Config.config.isVip = userInfo.vip;
} }
}); });