From b1bac758e3a1609cbddb6df0e82eab42302e1fa8 Mon Sep 17 00:00:00 2001 From: Tom Date: Thu, 27 Mar 2025 11:31:36 +0000 Subject: [PATCH] Added a scuffed redirect to prior page for impersonation. Fixed some conditions for websocket message checks. --- .../impersonation/impersonation.component.ts | 30 ++++++++++--------- .../groups/group-page/group-page.component.ts | 2 +- .../services/connection-state.service.ts | 2 +- src/app/shared/services/connection.service.ts | 2 +- src/app/shared/services/group.service.ts | 2 +- src/app/shared/services/permission.service.ts | 2 +- src/app/shared/services/policy.service.ts | 2 +- src/app/shared/services/redemption.service.ts | 2 +- src/app/shared/services/tts-filter.service.ts | 6 ++-- .../twitch-user-item.component.ts | 2 +- 10 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/app/auth/impersonation/impersonation.component.ts b/src/app/auth/impersonation/impersonation.component.ts index 2ef05b8..9fd37b9 100644 --- a/src/app/auth/impersonation/impersonation.component.ts +++ b/src/app/auth/impersonation/impersonation.component.ts @@ -25,7 +25,7 @@ export class ImpersonationComponent implements OnInit { impersonated: string | undefined; users: { id: string, name: string }[]; - constructor(private hermes: HermesClientService, private auth: ApiAuthenticationService, private router: Router, private events: EventService, private http: HttpClient, @Inject(PLATFORM_ID) private platformId: Object) { + constructor(private client: HermesClientService, private auth: ApiAuthenticationService, private router: Router, private events: EventService, private http: HttpClient, @Inject(PLATFORM_ID) private platformId: Object) { this.users = [] } @@ -46,17 +46,19 @@ export class ImpersonationComponent implements OnInit { } }); - if (this.auth.isAdmin()) { - this.events.listen('impersonation', (userId) => { - this.keyService.fetch(true) - .pipe(timeout(3000), first()) - .subscribe(async (d: ApiKey[]) => { - if (d.length > 0) - this.hermes.login(d[0].id); - await this.router.navigate([this.router.url.substring(1)]); - }); - }); - } + this.events.listen('impersonation', (userId) => { + const url = this.router.url; + this.client.first(d => d.op == 2 && !d.d.another_client) + .subscribe(async _ => + await setTimeout(async () => + await this.router.navigate([url.substring(1)]), 500)); + this.keyService.fetch(true) + .pipe(timeout(3000), first()) + .subscribe(async (d: ApiKey[]) => { + if (d.length > 0) + this.client.login(d[0].id); + }); + }); } public isAdmin() { @@ -80,7 +82,7 @@ export class ImpersonationComponent implements OnInit { impersonation: e.value } }).subscribe(async (data: any) => { - this.hermes.disconnect(); + this.client.disconnect(); this.events.emit('impersonation', e.value); }); } else { @@ -91,7 +93,7 @@ export class ImpersonationComponent implements OnInit { 'Authorization': 'Bearer ' + localStorage.getItem('jwt') } }).subscribe(async (data: any) => { - this.hermes.disconnect(); + this.client.disconnect(); this.events.emit('impersonation', e.value); await this.router.navigate(['tts-login']); }); diff --git a/src/app/groups/group-page/group-page.component.ts b/src/app/groups/group-page/group-page.component.ts index 4141542..0a996e3 100644 --- a/src/app/groups/group-page/group-page.component.ts +++ b/src/app/groups/group-page/group-page.component.ts @@ -161,7 +161,7 @@ export class GroupPageComponent implements OnDestroy { if (!this.group) return; - this._client.first(d => d.d.request.type == 'delete_group' && d.d.request.data.id == this.group!.id) + this._client.first(d => d.op == 4 && d.d.request.type == 'delete_group' && d.d.request.data.id == this.group!.id) .subscribe(async () => await this._router.navigate(['groups'])); this._client.deleteGroup(this.group.id); } diff --git a/src/app/shared/services/connection-state.service.ts b/src/app/shared/services/connection-state.service.ts index 6830bda..3d0011a 100644 --- a/src/app/shared/services/connection-state.service.ts +++ b/src/app/shared/services/connection-state.service.ts @@ -63,7 +63,7 @@ export class ConnectionStateService { return of(this.data); } - const $ = this.client.first(d => d.d.request.type == 'get_connection_states')!.pipe(map(d => d.d.data)); + const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_connection_states')!.pipe(map(d => d.d.data)); $.subscribe(d => { this.data = d; this.loaded = true; diff --git a/src/app/shared/services/connection.service.ts b/src/app/shared/services/connection.service.ts index 7c863c6..b94d313 100644 --- a/src/app/shared/services/connection.service.ts +++ b/src/app/shared/services/connection.service.ts @@ -64,7 +64,7 @@ export class ConnectionService { return of(this.data); } - const $ = this.client.first(d => d.d.request.type == 'get_connections')!.pipe(map(d => d.d.data)); + const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_connections')!.pipe(map(d => d.d.data)); $.subscribe(d => { this.data = d; this.loaded = true; diff --git a/src/app/shared/services/group.service.ts b/src/app/shared/services/group.service.ts index 972f74b..bd8168f 100644 --- a/src/app/shared/services/group.service.ts +++ b/src/app/shared/services/group.service.ts @@ -69,7 +69,7 @@ export default class GroupService { }); } - const $ = this.client.first(d => d.d.request.type == 'get_groups')!.pipe(map(d => d.d.data)); + const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_groups')!.pipe(map(d => d.d.data)); $.subscribe(d => { this.groups = d.map((item: any) => item.group); this.chatters = d.map((item: any) => item.chatters).flat(); diff --git a/src/app/shared/services/permission.service.ts b/src/app/shared/services/permission.service.ts index 2cc8c5b..36fd72d 100644 --- a/src/app/shared/services/permission.service.ts +++ b/src/app/shared/services/permission.service.ts @@ -61,7 +61,7 @@ export class PermissionService { return of(this.data); } - const $ = this.client.first(d => d.d.request.type == 'get_group_permissions')!.pipe(map(d => d.d.data)); + const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_group_permissions')!.pipe(map(d => d.d.data)); $.subscribe(d => { this.data = d; this.loaded = true; diff --git a/src/app/shared/services/policy.service.ts b/src/app/shared/services/policy.service.ts index 79c55fd..d78af57 100644 --- a/src/app/shared/services/policy.service.ts +++ b/src/app/shared/services/policy.service.ts @@ -45,7 +45,7 @@ export default class PolicyService { return of(this.data); } - const $ = this.client.first(d => d.d.request.type == 'get_policies')!.pipe(map(d => d.d.data)); + const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_policies')!.pipe(map(d => d.d.data)); $.subscribe(d => { this.data = d; this.loaded = true; diff --git a/src/app/shared/services/redemption.service.ts b/src/app/shared/services/redemption.service.ts index d236453..e15f4e2 100644 --- a/src/app/shared/services/redemption.service.ts +++ b/src/app/shared/services/redemption.service.ts @@ -45,7 +45,7 @@ export default class RedemptionService { return of(this.data); } - const $ = this.client.first(d => d.d.request.type == 'get_redemptions')!.pipe(map(d => d.d.data)); + const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_redemptions')!.pipe(map(d => d.d.data)); $.subscribe(d => { this.data = d; this.loaded = true; diff --git a/src/app/shared/services/tts-filter.service.ts b/src/app/shared/services/tts-filter.service.ts index 9a4ef6a..6687b3e 100644 --- a/src/app/shared/services/tts-filter.service.ts +++ b/src/app/shared/services/tts-filter.service.ts @@ -1,6 +1,6 @@ import { inject, Injectable } from '@angular/core'; import { HermesClientService } from '../../hermes-client.service'; -import { map, Observable, of } from 'rxjs'; +import { first, map, Observable, of } from 'rxjs'; import EventService from './EventService'; import { Filter } from '../models/filter'; @@ -41,10 +41,10 @@ export default class TtsFilterService { fetch() { if (this.loaded) { - return of(this.data); + return of(this.data).pipe(first()); } - const $ = this.client.first(d => d.d.request.type == 'get_tts_word_filters')!.pipe(map(d => d.d.data)); + const $ = this.client.first(d => d.op == 4 && d.d.request.type == 'get_tts_word_filters')!.pipe(map(d => d.d.data)); $.subscribe(d => { this.data = d; this.loaded = true; diff --git a/src/app/twitch-users/twitch-user-item/twitch-user-item.component.ts b/src/app/twitch-users/twitch-user-item/twitch-user-item.component.ts index c6c827b..7a442fc 100644 --- a/src/app/twitch-users/twitch-user-item/twitch-user-item.component.ts +++ b/src/app/twitch-users/twitch-user-item/twitch-user-item.component.ts @@ -32,7 +32,7 @@ export class TwitchUserItemComponent { this.waitForResponse = true; this.responseError = undefined; - this._client.first(d => d.d.request.type == 'delete_group_chatter' && d.d.request.data.group == this.user.group_id && d.d.request.data.chatter == this.user.chatter_id) + this._client.first(d => d.op == 4 && d.d.request.type == 'delete_group_chatter' && d.d.request.data.group == this.user.group_id && d.d.request.data.chatter == this.user.chatter_id) .subscribe({ next: (d) => { if (d.d.error) {