Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix userInformationLoaded leaks

Chocobozzzf9e82ef37b36
diff --git a/client/src/app/+my-library/my-history/my-history.component.ts b/client/src/app/+my-library/my-history/my-history.component.ts
index 596ec63cec..60c35f1863 100644
--- a/client/src/app/+my-library/my-history/my-history.component.ts
+++ b/client/src/app/+my-library/my-history/my-history.component.ts
@@ -1,4 +1,5 @@
-import { Component, OnInit, inject, viewChild } from '@angular/core'
+import { Component, DestroyRef, inject, OnInit, viewChild } from '@angular/core'
+import { takeUntilDestroyed } from '@angular/core/rxjs-interop'
import { FormsModule } from '@angular/forms'
import {
AuthService,
@@ -41,6 +42,7 @@ export class MyHistoryComponent implements OnInit, DisableForReuseHook {
private notifier = inject(Notifier)
private confirmService = inject(ConfirmService)
private userHistoryService = inject(UserHistoryService)
+ private destroyRef = inject(DestroyRef)
readonly videosSelection = viewChild<VideosSelectionComponent>('videosSelection')
@@ -77,6 +79,7 @@ export class MyHistoryComponent implements OnInit, DisableForReuseHook {
this.user = this.authService.getUser()
this.authService.userInformationLoaded
+ .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => this.videosHistoryEnabled = this.user.videosHistoryEnabled)
}
diff --git a/client/src/app/+video-list/video-user-subscriptions.component.ts b/client/src/app/+video-list/video-user-subscriptions.component.ts
index 4c2946b0c5..6556c26e81 100644
--- a/client/src/app/+video-list/video-user-subscriptions.component.ts
+++ b/client/src/app/+video-list/video-user-subscriptions.component.ts
@@ -7,7 +7,7 @@ import { VideoFilters } from '@app/shared/shared-video-miniature/video-filters.m
import { VideosListComponent } from '@app/shared/shared-video-miniature/videos-list.component'
import { VideoSortField } from '@peertube/peertube-models'
import { firstValueFrom } from 'rxjs'
-import { switchMap, tap } from 'rxjs/operators'
+import { first, switchMap, tap } from 'rxjs/operators'
@Component({
selector: 'my-videos-user-subscriptions',
@@ -77,6 +77,7 @@ export class VideoUserSubscriptionsComponent implements DisableForReuseHook {
const obs = this.authService.userInformationLoaded
.pipe(
+ first(),
switchMap(() => this.scopedTokensService.getScopedTokens()),
tap(tokens => this.feedToken = tokens.feedToken)
)
diff --git a/client/src/app/shared/shared-user-settings/user-interface-settings.component.ts b/client/src/app/shared/shared-user-settings/user-interface-settings.component.ts
index 4bd6940427..4c8a771102 100644
--- a/client/src/app/shared/shared-user-settings/user-interface-settings.component.ts
+++ b/client/src/app/shared/shared-user-settings/user-interface-settings.component.ts
@@ -46,6 +46,7 @@ export class UserInterfaceSettingsComponent implements OnInit, OnDestroy {
availableLanguages: SelectOptionsItem[]
formValuesWatcher: Subscription
+ userInfoSub: Subscription
private serverConfig: HTMLServerConfig
private initialUserLanguage: string
@@ -71,7 +72,7 @@ export class UserInterfaceSettingsComponent implements OnInit, OnDestroy {
this.buildForm()
- this.userInformationLoaded()
+ this.userInfoSub = this.userInformationLoaded()
.subscribe(() => {
this.form.patchValue({
theme: this.user().theme,
@@ -83,6 +84,12 @@ export class UserInterfaceSettingsComponent implements OnInit, OnDestroy {
}
})
}
+
+ ngOnDestroy () {
+ this.formValuesWatcher?.unsubscribe()
+ this.userInfoSub?.unsubscribe()
+ }
+
private buildForm () {
const obj: BuildFormArgumentTyped<Form> = {
theme: null,
@@ -100,10 +107,6 @@ export class UserInterfaceSettingsComponent implements OnInit, OnDestroy {
this.validationMessages = validationMessages
}
- ngOnDestroy () {
- this.formValuesWatcher?.unsubscribe()
- }
-
// ---------------------------------------------------------------------------
updateInterfaceSettings () {
@@ -163,8 +166,6 @@ export class UserInterfaceSettingsComponent implements OnInit, OnDestroy {
getSubmitValue () {
return $localize`Save interface settings`
-
- // return $localize`Save and reload the interface`
}
private getDefaultInstanceThemeLabel () {
diff --git a/client/src/app/shared/shared-video-miniature/video-miniature.component.ts b/client/src/app/shared/shared-video-miniature/video-miniature.component.ts
index 9527c143bd..2894522d7c 100644
--- a/client/src/app/shared/shared-video-miniature/video-miniature.component.ts
+++ b/client/src/app/shared/shared-video-miniature/video-miniature.component.ts
@@ -13,7 +13,7 @@ import {
import { AuthService, ScreenService, ServerService, User } from '@app/core'
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap'
import { HTMLServerConfig, VideoPlaylistType, VideoPrivacy } from '@peertube/peertube-models'
-import { switchMap } from 'rxjs/operators'
+import { first, switchMap } from 'rxjs/operators'
import { LinkType } from '../../../types/link.type'
import { ActorAvatarComponent } from '../shared-actor-image/actor-avatar.component'
import { ActorHostComponent } from '../shared-actor/actor-host.component'
@@ -323,7 +323,7 @@ export class VideoMiniatureComponent implements OnInit {
if (this.screenService.isInTouchScreen() || !this.displayVideoActions() || !this.isUserLoggedIn()) return
this.authService.userInformationLoaded
- .pipe(switchMap(() => this.videoPlaylistService.listenToVideoPlaylistChange(this.video().id)))
+ .pipe(first(), switchMap(() => this.videoPlaylistService.listenToVideoPlaylistChange(this.video().id)))
.subscribe(existResult => {
const watchLaterPlaylist = this.authService.getUser().specialPlaylists.find(p => p.type === VideoPlaylistType.WATCH_LATER)
const existsInWatchLater = existResult.find(r => r.playlistId === watchLaterPlaylist.id)