Skip to content

Commit d558fb6

Browse files
Migrate faction last action over to API V2.
1 parent 091cd0b commit d558fb6

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

extension/changelog.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
{ "message": "Prevent error on the faction page when member list is modified", "contributor": "MOBermejo" },
1515
{ "message": "Migrate attacks over to API V2.", "contributor": "DeKleineKobini" },
1616
{ "message": "Migrate faction stakeouts over to API V2.", "contributor": "DeKleineKobini" }
17+
{ "message": "Migrate faction last action over to API V2.", "contributor": "DeKleineKobini" }
1718
],
1819
"removed": []
1920
}

extension/scripts/features/last-action/ttFactionLastAction.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@
6767
if (row.find(".icons li[id*='icon77___']")) return;
6868

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

7273
const element = document.newElement({
7374
type: "div",
7475
class: "tt-last-action",
75-
text: `Last action: ${members[userID].last_action.relative}`,
76+
text: `Last action: ${member.last_action.relative}`,
7677
attributes: {
7778
hours: hours,
7879
},
@@ -91,7 +92,7 @@
9192
members = ttCache.get("faction-members", id);
9293
} else {
9394
members = (
94-
await fetchData("torn", {
95+
await fetchData("tornv2", {
9596
section: "faction",
9697
...(isNaN(id) ? {} : { id }),
9798
selections: ["basic"],

extension/scripts/global/functions/database.js

+7
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ async function migrateDatabase(force = false) {
220220
if (storage?.settings?.apiUsage?.user?.attacks === false) {
221221
newStorage.settings.apiUsage.userV2.attacks = false;
222222
}
223+
if (storage?.cache && "faction-members" in storage.cache) {
224+
newStorage.cache = {
225+
...(storage?.cache ?? {}),
226+
"faction-members": {},
227+
};
228+
}
229+
223230
updated = true;
224231
}
225232

0 commit comments

Comments
 (0)