Skip to content

Commit

Permalink
refactor(platform): use async avatar icon during user mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
fgravin committed Dec 4, 2023
1 parent f620fe5 commit 9ec32d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
import { UserModel } from '@geonetwork-ui/common/domain/model/user/user.model'
import { Injectable } from '@angular/core'
import { AvatarServiceInterface } from '../auth/avatar.service.interface'
import { map } from 'rxjs/operators'
import { Observable, of } from 'rxjs'

@Injectable()
export class Gn4PlatformMapper {
constructor(private avatarService: AvatarServiceInterface) {}
userFromMeApi(apiUser: MeResponseApiModel): UserModel {
if (!apiUser) return null
userFromMeApi(apiUser: MeResponseApiModel): Observable<UserModel | null> {
if (!apiUser) return of(null)
const {
hash,
groupsWithRegisteredUser,
Expand All @@ -20,8 +22,10 @@ export class Gn4PlatformMapper {
admin,
...user
} = apiUser
const icon = this.avatarService.getProfileIcon(hash)
return { ...user, profileIcon: icon } as UserModel

return this.avatarService
.getProfileIcon(hash)
.pipe(map((profileIcon) => ({ ...user, profileIcon } as UserModel)))
}
userFromApi(apiUser: UserApiModel): UserModel {
if (!apiUser) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Gn4PlatformService implements PlatformServiceInterface {
private mapper: Gn4PlatformMapper
) {
this.me$ = this.meApi.getMe().pipe(
map((apiUser) => this.mapper.userFromMeApi(apiUser)),
switchMap((apiUser) => this.mapper.userFromMeApi(apiUser)),
shareReplay({ bufferSize: 1, refCount: true })
)
this.isAnonymous$ = this.me$.pipe(map((user) => !user || !('id' in user)))
Expand Down

0 comments on commit 9ec32d1

Please sign in to comment.