From c5911fd347c76e8bdc05ea9f3ee9efed4a58c236 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 29 Dec 2017 19:10:13 +0100 Subject: Begin to add avatar to actors --- client/src/app/shared/account/account.model.ts | 10 +++++++--- client/src/app/shared/misc/utils.ts | 14 +++++++++++++- client/src/app/shared/users/user.model.ts | 4 ++-- client/src/app/shared/users/user.service.ts | 16 ++++++++++++++++ client/src/app/shared/video/abstract-video-list.ts | 2 +- client/src/app/shared/video/video.model.ts | 7 ++----- 6 files changed, 41 insertions(+), 12 deletions(-) (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/account/account.model.ts b/client/src/app/shared/account/account.model.ts index bacaa208a..cc46dad77 100644 --- a/client/src/app/shared/account/account.model.ts +++ b/client/src/app/shared/account/account.model.ts @@ -1,11 +1,13 @@ import { Account as ServerAccount } from '../../../../../shared/models/actors/account.model' import { Avatar } from '../../../../../shared/models/avatars/avatar.model' import { environment } from '../../../environments/environment' +import { getAbsoluteAPIUrl } from '../misc/utils' export class Account implements ServerAccount { id: number uuid: string name: string + displayName: string host: string followingCount: number followersCount: number @@ -13,9 +15,11 @@ export class Account implements ServerAccount { updatedAt: Date avatar: Avatar - static GET_ACCOUNT_AVATAR_PATH (account: Account) { - if (account && account.avatar) return account.avatar.path + static GET_ACCOUNT_AVATAR_URL (account: Account) { + const absoluteAPIUrl = getAbsoluteAPIUrl() - return '/client/assets/images/default-avatar.png' + if (account && account.avatar) return absoluteAPIUrl + account.avatar.path + + return window.location.origin + '/client/assets/images/default-avatar.png' } } diff --git a/client/src/app/shared/misc/utils.ts b/client/src/app/shared/misc/utils.ts index 5525e4efb..2739ff81a 100644 --- a/client/src/app/shared/misc/utils.ts +++ b/client/src/app/shared/misc/utils.ts @@ -1,5 +1,6 @@ // Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript +import { environment } from '../../../environments/environment' import { AuthService } from '../../core/auth' function getParameterByName (name: string, url: string) { @@ -38,8 +39,19 @@ function populateAsyncUserVideoChannels (authService: AuthService, channel: any[ }) } +function getAbsoluteAPIUrl () { + let absoluteAPIUrl = environment.apiUrl + if (!absoluteAPIUrl) { + // The API is on the same domain + absoluteAPIUrl = window.location.origin + } + + return absoluteAPIUrl +} + export { viewportHeight, getParameterByName, - populateAsyncUserVideoChannels + populateAsyncUserVideoChannels, + getAbsoluteAPIUrl } diff --git a/client/src/app/shared/users/user.model.ts b/client/src/app/shared/users/user.model.ts index 7a962ae3e..83aae4463 100644 --- a/client/src/app/shared/users/user.model.ts +++ b/client/src/app/shared/users/user.model.ts @@ -57,7 +57,7 @@ export class User implements UserServerModel { return hasUserRight(this.role, right) } - getAvatarPath () { - return Account.GET_ACCOUNT_AVATAR_PATH(this.account) + getAvatarUrl () { + return Account.GET_ACCOUNT_AVATAR_URL(this.account) } } diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts index d97edbcbe..58ddaa5ee 100644 --- a/client/src/app/shared/users/user.service.ts +++ b/client/src/app/shared/users/user.service.ts @@ -5,6 +5,7 @@ import 'rxjs/add/operator/map' import { UserCreate, UserUpdateMe } from '../../../../../shared' import { environment } from '../../../environments/environment' import { RestExtractor } from '../rest' +import { User } from './user.model' @Injectable() export class UserService { @@ -34,9 +35,24 @@ export class UserService { .catch(res => this.restExtractor.handleError(res)) } + changeAvatar (avatarForm: FormData) { + const url = UserService.BASE_USERS_URL + 'me/avatar/pick' + + return this.authHttp.post(url, avatarForm) + .catch(this.restExtractor.handleError) + } + signup (userCreate: UserCreate) { return this.authHttp.post(UserService.BASE_USERS_URL + 'register', userCreate) .map(this.restExtractor.extractDataBool) .catch(res => this.restExtractor.handleError(res)) } + + getMyInformation () { + const url = UserService.BASE_USERS_URL + 'me' + + return this.authHttp.get(url) + .map((userHash: any) => new User(userHash)) + .catch(res => this.restExtractor.handleError(res)) + } } diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts index bfe46bcdd..354373776 100644 --- a/client/src/app/shared/video/abstract-video-list.ts +++ b/client/src/app/shared/video/abstract-video-list.ts @@ -83,7 +83,7 @@ export abstract class AbstractVideoList implements OnInit { this.videos = this.videos.concat(videos) } }, - error => this.notificationsService.error('Error', error.text) + error => this.notificationsService.error('Error', error.message) ) } diff --git a/client/src/app/shared/video/video.model.ts b/client/src/app/shared/video/video.model.ts index f159464c5..060bf933f 100644 --- a/client/src/app/shared/video/video.model.ts +++ b/client/src/app/shared/video/video.model.ts @@ -2,6 +2,7 @@ import { User } from '../' import { Video as VideoServerModel } from '../../../../../shared' import { Account } from '../../../../../shared/models/actors' import { environment } from '../../../environments/environment' +import { getAbsoluteAPIUrl } from '../misc/utils' export class Video implements VideoServerModel { accountName: string @@ -48,11 +49,7 @@ export class Video implements VideoServerModel { } constructor (hash: VideoServerModel) { - let absoluteAPIUrl = environment.apiUrl - if (!absoluteAPIUrl) { - // The API is on the same domain - absoluteAPIUrl = window.location.origin - } + const absoluteAPIUrl = getAbsoluteAPIUrl() this.accountName = hash.accountName this.createdAt = new Date(hash.createdAt.toString()) -- cgit v1.2.3