fixes after review

This commit is contained in:
kontrollanten 2025-01-15 07:23:52 +01:00
parent cd417ddefa
commit efafef6da6
10 changed files with 49 additions and 36 deletions

View File

@ -40,6 +40,7 @@ import {
import { TableExpanderIconComponent } from '../../../../shared/shared-tables/table-expander-icon.component'
import { UserEmailInfoComponent } from '../../../shared/user-email-info.component'
import { shortCacheObservable } from '@root-helpers/utils'
import { lastValueFrom } from 'rxjs'
type UserForList = User & {
rawVideoQuota: number
@ -181,7 +182,7 @@ export class UserListComponent extends RestTable <User> implements OnInit, OnDes
]
]
this.bulkActions = await this.hooks.wrapObject(bulkActions, 'admin-users', 'filter:admin-user-list.bulk-actions.create.result')
this.bulkActions = await this.hooks.wrapObject(bulkActions, 'admin-users', 'filter:admin-users-list.bulk-actions.create.result')
this.columns = [
{ id: 'username', label: $localize`Username` },
@ -377,7 +378,7 @@ export class UserListComponent extends RestTable <User> implements OnInit, OnDes
error: err => this.notifier.error(err.message)
})
return obs
return lastValueFrom(obs)
}
private loadMutedStatus () {

View File

@ -10,7 +10,7 @@ import { VideoComment } from '@app/shared/shared-video-comment/video-comment.mod
import { VideoCommentService } from '@app/shared/shared-video-comment/video-comment.service'
import { NgbDropdown, NgbDropdownButtonItem, NgbDropdownItem, NgbDropdownMenu, NgbDropdownToggle } from '@ng-bootstrap/ng-bootstrap'
import { PeerTubeProblemDocument, ServerErrorCode, VideoCommentPolicy } from '@peertube/peertube-models'
import { Subject, Subscription } from 'rxjs'
import { lastValueFrom, Subject, Subscription } from 'rxjs'
import { InfiniteScrollerDirective } from '../../../../shared/shared-main/common/infinite-scroller.directive'
import { FeedComponent } from '../../../../shared/shared-main/feeds/feed.component'
import { LoaderComponent } from '../../../../shared/shared-main/common/loader.component'
@ -151,13 +151,14 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
}
loadMoreThreads (reset = false) {
if (reset === true) {
this.componentPagination.currentPage = 1
}
const params = {
videoId: this.video.uuid,
videoPassword: this.videoPassword,
componentPagination: {
...this.componentPagination,
currentPage: reset === true ? 1 : this.componentPagination.currentPage
},
componentPagination: this.componentPagination,
sort: this.sort
}
@ -185,7 +186,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
error: err => this.notifier.error(err.message)
})
return obs
return lastValueFrom(obs)
}
onCommentThreadCreated (comment: VideoComment) {

View File

@ -1,4 +1,4 @@
import { forkJoin, from } from 'rxjs'
import { forkJoin } from 'rxjs'
import { filter, first, map } from 'rxjs/operators'
import { DOCUMENT, getLocaleDirection, NgClass, NgIf, PlatformLocation } from '@angular/common'
import { AfterViewInit, Component, Inject, LOCALE_ID, OnDestroy, OnInit, ViewChild } from '@angular/core'
@ -150,12 +150,12 @@ export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
this.pluginService.addAction('application:increment-loader', () => {
this.loadingBar.useRef('plugins').start()
return from([])
return Promise.resolve()
})
this.pluginService.addAction('application:decrement-loader', () => {
this.loadingBar.useRef('plugins').complete()
return from([])
return Promise.resolve()
})
}

View File

@ -61,7 +61,7 @@ export class PluginService implements ClientHook {
private pluginsManager: PluginsManager
private actions: { [name in ClientDoActionName]?: ClientDoActionCallback } = {}
private actions = new Map<ClientDoActionName, ClientDoActionCallback>()
constructor (
private authService: AuthService,
@ -85,11 +85,11 @@ export class PluginService implements ClientHook {
}
addAction (actionName: ClientDoActionName, callback: ClientDoActionCallback) {
this.actions[actionName] = callback
this.actions.set(actionName, callback)
}
removeAction (actionName: ClientDoActionName) {
delete this.actions[actionName]
this.actions.delete(actionName)
}
initializePlugins () {
@ -199,11 +199,15 @@ export class PluginService implements ClientHook {
}
private doAction (actionName: ClientDoActionName) {
try {
return this.actions[actionName]()
} catch (err: any) {
if (!this.actions.has(actionName)) {
logger.warn(`Plugin tried to do unknown action: ${actionName}`)
}
try {
return this.actions.get(actionName)()
} catch (err: any) {
logger.warn(`Cannot run action ${actionName}`, err)
}
}
private onFormFields (

View File

@ -30,6 +30,7 @@ import { AbuseMessageModalComponent } from './abuse-message-modal.component'
import { ModerationCommentModalComponent } from './moderation-comment-modal.component'
import { ProcessedAbuse } from './processed-abuse.model'
import { shortCacheObservable } from '@root-helpers/utils'
import { lastValueFrom } from 'rxjs'
const debugLogger = debug('peertube:moderation:AbuseListTableComponent')
@ -293,7 +294,7 @@ export class AbuseListTableComponent extends RestTable implements OnInit, OnDest
error: err => this.notifier.error(err.message)
})
return observable
return lastValueFrom(observable)
}
private buildInternalActions (): DropdownAction<ProcessedAbuse>[] {

View File

@ -286,7 +286,7 @@ export class UserModerationDropdownComponent implements OnInit, OnChanges {
if (myAccountModerationActions.length !== 0) userActions.push(myAccountModerationActions)
if (instanceModerationActions.length !== 0) userActions.push(instanceModerationActions)
this.userActions = await this.hooks.wrapObject(userActions, 'admin-users', 'filter:admin-user-moderation.actions.create.result')
this.userActions = await this.hooks.wrapObject(userActions, 'moderation', 'filter:user-moderation.actions.create.result')
}
private buildMyAccountModerationActions () {

View File

@ -18,6 +18,7 @@ import { AutoColspanDirective } from '../shared-main/common/auto-colspan.directi
import { PTDatePipe } from '../shared-main/common/date.pipe'
import { TableExpanderIconComponent } from '../shared-tables/table-expander-icon.component'
import { shortCacheObservable } from '@root-helpers/utils'
import { lastValueFrom } from 'rxjs'
@Component({
selector: 'my-video-comment-list-admin-owner',
@ -102,7 +103,7 @@ export class VideoCommentListAdminOwnerComponent extends RestTable <VideoComment
this.videoCommentActions = await this.hooks.wrapObject(
videoCommentActions,
'admin-comments',
'filter:admin-video-comment-list.actions.create.result'
'filter:admin-video-comments-list.actions.create.result'
)
const bulkActions: DropdownAction<VideoCommentForAdminOrUser[]>[] = [
@ -119,11 +120,16 @@ export class VideoCommentListAdminOwnerComponent extends RestTable <VideoComment
iconName: 'tick'
}
]
this.bulkActions = await this.hooks.wrapObject(
bulkActions,
'admin-comments',
'filter:admin-video-comment-list.bulk-actions.create.result'
)
if (this.mode === 'admin') {
this.bulkActions = await this.hooks.wrapObject(
bulkActions,
'admin-comments',
'filter:admin-video-comments-list.bulk-actions.create.result'
)
} else {
this.bulkActions = bulkActions
}
if (this.mode === 'admin') {
this.inputFilters = [
@ -202,7 +208,7 @@ export class VideoCommentListAdminOwnerComponent extends RestTable <VideoComment
error: err => this.notifier.error(err.message)
})
return obs
return lastValueFrom(obs)
}
private approveComments (comments: VideoCommentForAdminOrUser[]) {

View File

@ -74,7 +74,8 @@ class PluginsManager {
'video-channel': new ReplaySubject<boolean>(1),
'my-account': new ReplaySubject<boolean>(1),
'admin-users': new ReplaySubject<boolean>(1),
'admin-comments': new ReplaySubject<boolean>(1)
'admin-comments': new ReplaySubject<boolean>(1),
'moderation': new ReplaySubject<boolean>(1)
}
private readonly doAction: ClientDoAction

View File

@ -1,5 +1,3 @@
import { Observable } from 'rxjs'
// Data from API hooks: {hookType}:api.{location}.{elementType}.{actionType}.{target}
// Data in internal functions: {hookType}:{location}.{elementType}.{actionType}.{target}
@ -106,16 +104,16 @@ export const clientFilterHookObject = {
'filter:internal.player.p2p-media-loader.options.result': true,
// Filter bulk actions in user list
'filter:admin-user-list.bulk-actions.create.result': true,
'filter:admin-users-list.bulk-actions.create.result': true,
// Filter actions in comment list
'filter:admin-video-comment-list.actions.create.result': true,
'filter:admin-video-comments-list.actions.create.result': true,
// Filter bulk actions in comment list
'filter:admin-video-comment-list.bulk-actions.create.result': true,
'filter:admin-video-comments-list.bulk-actions.create.result': true,
// Filter user moderation actions
'filter:admin-user-moderation.actions.create.result': true,
'filter:user-moderation.actions.create.result': true,
// Filter actions in abuse list
'filter:admin-abuse-list.actions.create.result': true
@ -226,5 +224,5 @@ export const clientDoActionObject = {
export type ClientDoActionName = keyof typeof clientDoActionObject
export type ClientDoActionCallback = () => Observable<any>
export type ClientDoAction = (actionName: ClientDoActionName) => Observable<any>
export type ClientDoActionCallback = () => Promise<any>
export type ClientDoAction = (actionName: ClientDoActionName) => Promise<any>

View File

@ -11,4 +11,5 @@ export type PluginClientScope =
'video-channel' |
'my-account' |
'admin-users' |
'admin-comments'
'admin-comments' |
'moderation'