mirror of https://github.com/Chocobozzz/PeerTube
Add get user cache for comments
parent
bc6f886347
commit
218b0874ed
|
@ -1,5 +1,5 @@
|
||||||
import { from, Observable } from 'rxjs'
|
import { from, Observable, of } from 'rxjs'
|
||||||
import { catchError, concatMap, map, toArray } from 'rxjs/operators'
|
import { catchError, concatMap, map, share, shareReplay, tap, toArray } from 'rxjs/operators'
|
||||||
import { HttpClient, HttpParams } from '@angular/common/http'
|
import { HttpClient, HttpParams } from '@angular/common/http'
|
||||||
import { Injectable } from '@angular/core'
|
import { Injectable } from '@angular/core'
|
||||||
import { ResultList, User, UserCreate, UserRole, UserUpdate, UserUpdateMe, UserVideoQuota } from '../../../../../shared'
|
import { ResultList, User, UserCreate, UserRole, UserUpdate, UserUpdateMe, UserVideoQuota } from '../../../../../shared'
|
||||||
|
@ -17,6 +17,8 @@ export class UserService {
|
||||||
|
|
||||||
private bytesPipe = new BytesPipe()
|
private bytesPipe = new BytesPipe()
|
||||||
|
|
||||||
|
private userCache: { [ id: number ]: Observable<User> } = {}
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private authHttp: HttpClient,
|
private authHttp: HttpClient,
|
||||||
private restExtractor: RestExtractor,
|
private restExtractor: RestExtractor,
|
||||||
|
@ -194,6 +196,14 @@ export class UserService {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getUserWithCache (userId: number) {
|
||||||
|
if (!this.userCache[userId]) {
|
||||||
|
this.userCache[ userId ] = this.getUser(userId).pipe(shareReplay())
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.userCache[userId]
|
||||||
|
}
|
||||||
|
|
||||||
getUser (userId: number) {
|
getUser (userId: number) {
|
||||||
return this.authHttp.get<User>(UserService.BASE_USERS_URL + userId)
|
return this.authHttp.get<User>(UserService.BASE_USERS_URL + userId)
|
||||||
.pipe(catchError(err => this.restExtractor.handleError(err)))
|
.pipe(catchError(err => this.restExtractor.handleError(err)))
|
||||||
|
|
|
@ -36,8 +36,9 @@
|
||||||
<div class="comment-actions">
|
<div class="comment-actions">
|
||||||
<div *ngIf="isUserLoggedIn()" (click)="onWantToReply()" class="comment-action-reply" i18n>Reply</div>
|
<div *ngIf="isUserLoggedIn()" (click)="onWantToReply()" class="comment-action-reply" i18n>Reply</div>
|
||||||
<div *ngIf="isRemovableByUser()" (click)="onWantToDelete()" class="comment-action-delete" i18n>Delete</div>
|
<div *ngIf="isRemovableByUser()" (click)="onWantToDelete()" class="comment-action-delete" i18n>Delete</div>
|
||||||
|
|
||||||
<my-user-moderation-dropdown
|
<my-user-moderation-dropdown
|
||||||
buttonSize="small" [account]="commentAccount" [user]="commentUser" label="Options" placement="bottom-left auto"
|
buttonSize="small" [account]="commentAccount" [user]="commentUser" i18n-label label="Options" placement="bottom-left auto"
|
||||||
></my-user-moderation-dropdown>
|
></my-user-moderation-dropdown>
|
||||||
</div>
|
</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
@ -80,8 +81,8 @@
|
||||||
></my-video-comment>
|
></my-video-comment>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<ng-content></ng-content>
|
<ng-content></ng-content>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -107,7 +107,7 @@ export class VideoCommentComponent implements OnInit, OnChanges {
|
||||||
|
|
||||||
const user = this.authService.getUser()
|
const user = this.authService.getUser()
|
||||||
if (user.hasRight(UserRight.MANAGE_USERS)) {
|
if (user.hasRight(UserRight.MANAGE_USERS)) {
|
||||||
this.userService.getUser(account.userId)
|
this.userService.getUserWithCache(account.userId)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
user => this.commentUser = user,
|
user => this.commentUser = user,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue