From 09bf0f1730dddd945a84264a0bfeeca1111949b6 Mon Sep 17 00:00:00 2001 From: FlaminSarge Date: Thu, 4 Jan 2024 12:52:18 -0800 Subject: [PATCH 1/4] Add handling to check for emotes if collectibleHash is missing --- src/app/app.component.ts | 62 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index ada1e95..f65f6a5 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -115,7 +115,9 @@ export class AppComponent implements OnInit { }) } + this.resetCodeStates(); this.filterCollectibles(membershipType, membershipId); + this.filterProfilePlugSets(membershipType, membershipId); } else { this.users = [] if (this.router.url != "/") @@ -193,7 +195,6 @@ export class AppComponent implements OnInit { async filterCollectibles(membershipType: number, membershipId: number) { this.loading = true; this.errorMessage = ""; - this.resetCodeStates(); this.currentUserMembershipId = membershipId; const url = `https://www.bungie.net/Platform/Destiny2/${membershipType}/Profile/${membershipId}/?components=800`; @@ -219,7 +220,7 @@ export class AppComponent implements OnInit { this.Codes.forEach(code => { - if (!code.collectibleHash || k.indexOf(code.collectibleHash.toString()) == -1) + if (!code.collectibleHash || k.indexOf(code.collectibleHash.toString()) == -1) code.state = State.Unknown; else { let existing = (c[code.collectibleHash.toString()].state & 1) == 0; @@ -229,7 +230,62 @@ export class AppComponent implements OnInit { else code.state = State.NotRewarded; } - }) + }); + /* + this.Codes.sort((a,b) => { + if (a.state > b.state) + return -1; + if (a.state < b.state) + return 1; + if (a.name < b.name) + return -1; + else return 1; + })*/ + this.updateUnclaimedCodesCount(); + this.loading = false; + } + + async filterProfilePlugSets(membershipType: number, membershipId: number) { + if (this.Codes.every(code => code.collectibleHash)) { + // skip the plugSet check if all codes have collectibleHash + return; + } + this.loading = true; + this.errorMessage = ""; + + this.currentUserMembershipId = membershipId; + const url = `https://www.bungie.net/Platform/Destiny2/${membershipType}/Profile/${membershipId}/?components=305`; + const result = await this.http.get(url, { + headers: {"X-API-Key": "d740f7aa26874fd59aa0a09ce0c47fd6"} + }).pipe( + tap(_ => console.log('fetched plugSets')), + catchError(e => this.handleError(e)) + ).toPromise(); + if (!result) { + this.loading = false; + return; + } + + if (!result.Response.profilePlugSets.data) { + this.errorMessage = "The API did not return any profilePlugSets for this account. Privacy setting?"; + this.loading = false; + return; + } + + var c = result.Response.profilePlugSets.data.plugs[2860926541]; // emote plugSet + var kv = new Map(c.map(plug => [plug.plugItemHash, plug])); + + this.Codes.forEach(code => { + if (!code.collectibleHash) { // skip any with collectibleHash as those would not be in plugSets + let plug = kv.get(code.itemHash); + let existing = plug && plug.canInsert && plug.enable; + console.log(code.name, plug?.canInsert, plug?.enable); + if (existing) + code.state = State.Rewarded; + else + code.state = State.NotRewarded; + } + }); /* this.Codes.sort((a,b) => { if (a.state > b.state) From cb41f3ee0538ce83cb0e4bb24f6b2b0e5fea2822 Mon Sep 17 00:00:00 2001 From: FlaminSarge Date: Thu, 4 Jan 2024 17:59:50 -0800 Subject: [PATCH 2/4] Fixed typing for plug --- src/app/app.component.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index f65f6a5..cad758b 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -22,6 +22,12 @@ interface GuardianInfo { } +interface DestinyItemPlugBase { + plugItemHash: number; + canInsert: boolean; + enabled: boolean; +} + enum State { Unknown, NotRewarded, @@ -273,13 +279,13 @@ export class AppComponent implements OnInit { } var c = result.Response.profilePlugSets.data.plugs[2860926541]; // emote plugSet - var kv = new Map(c.map(plug => [plug.plugItemHash, plug])); + var kv = new Map(c.map((plug: DestinyItemPlugBase) => [plug.plugItemHash, plug])); this.Codes.forEach(code => { if (!code.collectibleHash) { // skip any with collectibleHash as those would not be in plugSets - let plug = kv.get(code.itemHash); - let existing = plug && plug.canInsert && plug.enable; - console.log(code.name, plug?.canInsert, plug?.enable); + let plug = kv.get(code.itemHash) as DestinyItemPlugBase; + let existing = plug && plug.canInsert && plug.enabled; + console.log(code.name, plug?.canInsert, plug?.enabled); if (existing) code.state = State.Rewarded; else From 58452e9fe5caf76b4f9d27118eb55a80681b72f9 Mon Sep 17 00:00:00 2001 From: FlaminSarge Date: Thu, 4 Jan 2024 18:14:31 -0800 Subject: [PATCH 3/4] Prevent each filter* method from stepping on each others' toes by avoiding setting state if no new info found --- src/app/app.component.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index cad758b..4216eb3 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -226,9 +226,7 @@ export class AppComponent implements OnInit { this.Codes.forEach(code => { - if (!code.collectibleHash || k.indexOf(code.collectibleHash.toString()) == -1) - code.state = State.Unknown; - else { + if (code.collectibleHash && k.indexOf(code.collectibleHash.toString()) != -1) { let existing = (c[code.collectibleHash.toString()].state & 1) == 0; console.log(code.name, c[code.collectibleHash.toString()].state, existing) if (existing) From f9c23e505dd802eabdc200ca76829742628c6620 Mon Sep 17 00:00:00 2001 From: FlaminSarge Date: Thu, 4 Jan 2024 18:16:24 -0800 Subject: [PATCH 4/4] Add the inverse of the collectibleHash presence check to skip filterCollectibles, for good measure --- src/app/app.component.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 4216eb3..071d1de 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -199,6 +199,10 @@ export class AppComponent implements OnInit { } async filterCollectibles(membershipType: number, membershipId: number) { + if (this.Codes.every(code => !code.collectibleHash)) { + // skip the collectibles check if no codes have collectibleHash + return; + } this.loading = true; this.errorMessage = "";