]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-main/users/user-notification.service.ts
Add video filters to common video pages
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / users / user-notification.service.ts
index 8dd9472fe07a1567622f7f36a4d30ca800e24848..09fee87a30b7b9506478eb9066b103e19d287c83 100644 (file)
@@ -1,7 +1,8 @@
+import { SortMeta } from 'primeng/api'
 import { catchError, map, tap } from 'rxjs/operators'
 import { HttpClient, HttpParams } from '@angular/common/http'
 import { Injectable } from '@angular/core'
-import { ComponentPaginationLight, RestExtractor, RestService, User, UserNotificationSocket } from '@app/core'
+import { AuthService, ComponentPaginationLight, PeerTubeSocket, RestExtractor, RestService } from '@app/core'
 import { ResultList, UserNotification as UserNotificationServer, UserNotificationSetting } from '@shared/models'
 import { environment } from '../../../../environments/environment'
 import { UserNotification } from './user-notification.model'
@@ -13,14 +14,22 @@ export class UserNotificationService {
 
   constructor (
     private authHttp: HttpClient,
+    private auth: AuthService,
     private restExtractor: RestExtractor,
     private restService: RestService,
-    private userNotificationSocket: UserNotificationSocket
+    private peertubeSocket: PeerTubeSocket
   ) {}
 
-  listMyNotifications (pagination: ComponentPaginationLight, unread?: boolean, ignoreLoadingBar = false) {
+  listMyNotifications (parameters: {
+    pagination: ComponentPaginationLight
+    ignoreLoadingBar?: boolean
+    unread?: boolean
+    sort?: SortMeta
+  }) {
+    const { pagination, ignoreLoadingBar, unread, sort } = parameters
+
     let params = new HttpParams()
-    params = this.restService.addRestGetParams(params, this.restService.componentPaginationToRestPagination(pagination))
+    params = this.restService.addRestGetParams(params, this.restService.componentPaginationToRestPagination(pagination), sort)
 
     if (unread) params = params.append('unread', `${unread}`)
 
@@ -35,7 +44,7 @@ export class UserNotificationService {
   }
 
   countUnreadNotifications () {
-    return this.listMyNotifications({ currentPage: 1, itemsPerPage: 0 }, true)
+    return this.listMyNotifications({ pagination: { currentPage: 1, itemsPerPage: 0 }, ignoreLoadingBar: true, unread: true })
       .pipe(map(n => n.total))
   }
 
@@ -48,7 +57,7 @@ export class UserNotificationService {
     return this.authHttp.post(url, body, { headers })
                .pipe(
                  map(this.restExtractor.extractDataBool),
-                 tap(() => this.userNotificationSocket.dispatch('read')),
+                 tap(() => this.peertubeSocket.dispatchNotificationEvent('read')),
                  catchError(res => this.restExtractor.handleError(res))
                )
   }
@@ -60,12 +69,12 @@ export class UserNotificationService {
     return this.authHttp.post(url, {}, { headers })
                .pipe(
                  map(this.restExtractor.extractDataBool),
-                 tap(() => this.userNotificationSocket.dispatch('read-all')),
+                 tap(() => this.peertubeSocket.dispatchNotificationEvent('read-all')),
                  catchError(res => this.restExtractor.handleError(res))
                )
   }
 
-  updateNotificationSettings (user: User, settings: UserNotificationSetting) {
+  updateNotificationSettings (settings: UserNotificationSetting) {
     const url = UserNotificationService.BASE_NOTIFICATION_SETTINGS
 
     return this.authHttp.put(url, settings)
@@ -76,6 +85,6 @@ export class UserNotificationService {
   }
 
   private formatNotification (notification: UserNotificationServer) {
-    return new UserNotification(notification)
+    return new UserNotification(notification, this.auth.getUser())
   }
 }