]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-main/users/user-notification.service.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / users / user-notification.service.ts
index 9014b48a8d894ae43dbf5e829254956fa25da6fd..df886ed653dfdcf656449b21736f67c898ae63f7 100644 (file)
@@ -1,11 +1,12 @@
+import { SortMeta } from 'primeng/api'
 import { catchError, map, tap } from 'rxjs/operators'
-import { HttpClient, HttpParams } from '@angular/common/http'
+import { HttpClient, HttpContext, HttpParams } from '@angular/common/http'
 import { Injectable } from '@angular/core'
-import { ComponentPaginationLight, RestExtractor, RestService, User, PeerTubeSocket, AuthService } from '@app/core'
+import { AuthService, ComponentPaginationLight, PeerTubeSocket, RestExtractor, RestService } from '@app/core'
+import { NGX_LOADING_BAR_IGNORED } from '@ngx-loading-bar/http-client'
 import { ResultList, UserNotification as UserNotificationServer, UserNotificationSetting } from '@shared/models'
 import { environment } from '../../../../environments/environment'
 import { UserNotification } from './user-notification.model'
-import { SortMeta } from 'primeng/api'
 
 @Injectable()
 export class UserNotificationService {
@@ -23,19 +24,21 @@ export class UserNotificationService {
   listMyNotifications (parameters: {
     pagination: ComponentPaginationLight
     ignoreLoadingBar?: boolean
-    unread?: boolean,
+    unread?: boolean
     sort?: SortMeta
   }) {
     const { pagination, ignoreLoadingBar, unread, sort } = parameters
 
     let params = new HttpParams()
-    params = this.restService.addRestGetParams(params, this.restService.componentPaginationToRestPagination(pagination), sort)
+    params = this.restService.addRestGetParams(params, this.restService.componentToRestPagination(pagination), sort)
 
     if (unread) params = params.append('unread', `${unread}`)
 
-    const headers = ignoreLoadingBar ? { ignoreLoadingBar: '' } : undefined
+    const context = ignoreLoadingBar
+      ? new HttpContext().set(NGX_LOADING_BAR_IGNORED, true)
+      : undefined
 
-    return this.authHttp.get<ResultList<UserNotification>>(UserNotificationService.BASE_NOTIFICATIONS_URL, { params, headers })
+    return this.authHttp.get<ResultList<UserNotification>>(UserNotificationService.BASE_NOTIFICATIONS_URL, { params, context })
                .pipe(
                  map(res => this.restExtractor.convertResultListDateToHuman(res)),
                  map(res => this.restExtractor.applyToResultListData(res, this.formatNotification.bind(this))),
@@ -52,11 +55,10 @@ export class UserNotificationService {
     const url = UserNotificationService.BASE_NOTIFICATIONS_URL + '/read'
 
     const body = { ids: [ notification.id ] }
-    const headers = { ignoreLoadingBar: '' }
+    const context = new HttpContext().set(NGX_LOADING_BAR_IGNORED, true)
 
-    return this.authHttp.post(url, body, { headers })
+    return this.authHttp.post(url, body, { context })
                .pipe(
-                 map(this.restExtractor.extractDataBool),
                  tap(() => this.peertubeSocket.dispatchNotificationEvent('read')),
                  catchError(res => this.restExtractor.handleError(res))
                )
@@ -64,11 +66,10 @@ export class UserNotificationService {
 
   markAllAsRead () {
     const url = UserNotificationService.BASE_NOTIFICATIONS_URL + '/read-all'
-    const headers = { ignoreLoadingBar: '' }
+    const context = new HttpContext().set(NGX_LOADING_BAR_IGNORED, true)
 
-    return this.authHttp.post(url, {}, { headers })
+    return this.authHttp.post(url, {}, { context })
                .pipe(
-                 map(this.restExtractor.extractDataBool),
                  tap(() => this.peertubeSocket.dispatchNotificationEvent('read-all')),
                  catchError(res => this.restExtractor.handleError(res))
                )
@@ -78,10 +79,7 @@ export class UserNotificationService {
     const url = UserNotificationService.BASE_NOTIFICATION_SETTINGS
 
     return this.authHttp.put(url, settings)
-               .pipe(
-                 map(this.restExtractor.extractDataBool),
-                 catchError(res => this.restExtractor.handleError(res))
-               )
+               .pipe(catchError(res => this.restExtractor.handleError(res)))
   }
 
   private formatNotification (notification: UserNotificationServer) {