Skip to content

Commit

Permalink
Migrate faction last action over to API V2.
Browse files Browse the repository at this point in the history
  • Loading branch information
DeKleineKobini committed Feb 21, 2025
1 parent 091cd0b commit d558fb6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions extension/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{ "message": "Prevent error on the faction page when member list is modified", "contributor": "MOBermejo" },
{ "message": "Migrate attacks over to API V2.", "contributor": "DeKleineKobini" },
{ "message": "Migrate faction stakeouts over to API V2.", "contributor": "DeKleineKobini" }
{ "message": "Migrate faction last action over to API V2.", "contributor": "DeKleineKobini" }
],
"removed": []
}
Expand Down
7 changes: 4 additions & 3 deletions extension/scripts/features/last-action/ttFactionLastAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@
if (row.find(".icons li[id*='icon77___']")) return;

const userID = getUsername(row).id;
const hours = ((nowDate - members[userID].last_action.timestamp * 1000) / TO_MILLIS.HOURS).dropDecimals();
const member = members.find((m) => m.id === userID);
const hours = ((nowDate - member.last_action.timestamp * 1000) / TO_MILLIS.HOURS).dropDecimals();

const element = document.newElement({
type: "div",
class: "tt-last-action",
text: `Last action: ${members[userID].last_action.relative}`,
text: `Last action: ${member.last_action.relative}`,
attributes: {
hours: hours,
},
Expand All @@ -91,7 +92,7 @@
members = ttCache.get("faction-members", id);
} else {
members = (
await fetchData("torn", {
await fetchData("tornv2", {
section: "faction",
...(isNaN(id) ? {} : { id }),
selections: ["basic"],
Expand Down
7 changes: 7 additions & 0 deletions extension/scripts/global/functions/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ async function migrateDatabase(force = false) {
if (storage?.settings?.apiUsage?.user?.attacks === false) {
newStorage.settings.apiUsage.userV2.attacks = false;
}
if (storage?.cache && "faction-members" in storage.cache) {
newStorage.cache = {
...(storage?.cache ?? {}),
"faction-members": {},
};
}

updated = true;
}

Expand Down

0 comments on commit d558fb6

Please sign in to comment.