aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-29 19:10:13 +0100
committerChocobozzz <me@florianbigard.com>2017-12-29 19:10:13 +0100
commitc5911fd347c76e8bdc05ea9f3ee9efed4a58c236 (patch)
treeb8d287daca6c45305090cbec9da97d1155f275bd /client/src/app/shared
parent8b0d42ee372de6589796be26b83e5bffb1b69cdf (diff)
downloadPeerTube-c5911fd347c76e8bdc05ea9f3ee9efed4a58c236.tar.gz
PeerTube-c5911fd347c76e8bdc05ea9f3ee9efed4a58c236.tar.zst
PeerTube-c5911fd347c76e8bdc05ea9f3ee9efed4a58c236.zip
Begin to add avatar to actors
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/account/account.model.ts10
-rw-r--r--client/src/app/shared/misc/utils.ts14
-rw-r--r--client/src/app/shared/users/user.model.ts4
-rw-r--r--client/src/app/shared/users/user.service.ts16
-rw-r--r--client/src/app/shared/video/abstract-video-list.ts2
-rw-r--r--client/src/app/shared/video/video.model.ts7
6 files changed, 41 insertions, 12 deletions
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 @@
1import { Account as ServerAccount } from '../../../../../shared/models/actors/account.model' 1import { Account as ServerAccount } from '../../../../../shared/models/actors/account.model'
2import { Avatar } from '../../../../../shared/models/avatars/avatar.model' 2import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
3import { environment } from '../../../environments/environment' 3import { environment } from '../../../environments/environment'
4import { getAbsoluteAPIUrl } from '../misc/utils'
4 5
5export class Account implements ServerAccount { 6export class Account implements ServerAccount {
6 id: number 7 id: number
7 uuid: string 8 uuid: string
8 name: string 9 name: string
10 displayName: string
9 host: string 11 host: string
10 followingCount: number 12 followingCount: number
11 followersCount: number 13 followersCount: number
@@ -13,9 +15,11 @@ export class Account implements ServerAccount {
13 updatedAt: Date 15 updatedAt: Date
14 avatar: Avatar 16 avatar: Avatar
15 17
16 static GET_ACCOUNT_AVATAR_PATH (account: Account) { 18 static GET_ACCOUNT_AVATAR_URL (account: Account) {
17 if (account && account.avatar) return account.avatar.path 19 const absoluteAPIUrl = getAbsoluteAPIUrl()
18 20
19 return '/client/assets/images/default-avatar.png' 21 if (account && account.avatar) return absoluteAPIUrl + account.avatar.path
22
23 return window.location.origin + '/client/assets/images/default-avatar.png'
20 } 24 }
21} 25}
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 @@
1// Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript 1// Thanks: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
2 2
3import { environment } from '../../../environments/environment'
3import { AuthService } from '../../core/auth' 4import { AuthService } from '../../core/auth'
4 5
5function getParameterByName (name: string, url: string) { 6function getParameterByName (name: string, url: string) {
@@ -38,8 +39,19 @@ function populateAsyncUserVideoChannels (authService: AuthService, channel: any[
38 }) 39 })
39} 40}
40 41
42function getAbsoluteAPIUrl () {
43 let absoluteAPIUrl = environment.apiUrl
44 if (!absoluteAPIUrl) {
45 // The API is on the same domain
46 absoluteAPIUrl = window.location.origin
47 }
48
49 return absoluteAPIUrl
50}
51
41export { 52export {
42 viewportHeight, 53 viewportHeight,
43 getParameterByName, 54 getParameterByName,
44 populateAsyncUserVideoChannels 55 populateAsyncUserVideoChannels,
56 getAbsoluteAPIUrl
45} 57}
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 {
57 return hasUserRight(this.role, right) 57 return hasUserRight(this.role, right)
58 } 58 }
59 59
60 getAvatarPath () { 60 getAvatarUrl () {
61 return Account.GET_ACCOUNT_AVATAR_PATH(this.account) 61 return Account.GET_ACCOUNT_AVATAR_URL(this.account)
62 } 62 }
63} 63}
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'
5import { UserCreate, UserUpdateMe } from '../../../../../shared' 5import { UserCreate, UserUpdateMe } from '../../../../../shared'
6import { environment } from '../../../environments/environment' 6import { environment } from '../../../environments/environment'
7import { RestExtractor } from '../rest' 7import { RestExtractor } from '../rest'
8import { User } from './user.model'
8 9
9@Injectable() 10@Injectable()
10export class UserService { 11export class UserService {
@@ -34,9 +35,24 @@ export class UserService {
34 .catch(res => this.restExtractor.handleError(res)) 35 .catch(res => this.restExtractor.handleError(res))
35 } 36 }
36 37
38 changeAvatar (avatarForm: FormData) {
39 const url = UserService.BASE_USERS_URL + 'me/avatar/pick'
40
41 return this.authHttp.post(url, avatarForm)
42 .catch(this.restExtractor.handleError)
43 }
44
37 signup (userCreate: UserCreate) { 45 signup (userCreate: UserCreate) {
38 return this.authHttp.post(UserService.BASE_USERS_URL + 'register', userCreate) 46 return this.authHttp.post(UserService.BASE_USERS_URL + 'register', userCreate)
39 .map(this.restExtractor.extractDataBool) 47 .map(this.restExtractor.extractDataBool)
40 .catch(res => this.restExtractor.handleError(res)) 48 .catch(res => this.restExtractor.handleError(res))
41 } 49 }
50
51 getMyInformation () {
52 const url = UserService.BASE_USERS_URL + 'me'
53
54 return this.authHttp.get(url)
55 .map((userHash: any) => new User(userHash))
56 .catch(res => this.restExtractor.handleError(res))
57 }
42} 58}
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 {
83 this.videos = this.videos.concat(videos) 83 this.videos = this.videos.concat(videos)
84 } 84 }
85 }, 85 },
86 error => this.notificationsService.error('Error', error.text) 86 error => this.notificationsService.error('Error', error.message)
87 ) 87 )
88 } 88 }
89 89
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 '../'
2import { Video as VideoServerModel } from '../../../../../shared' 2import { Video as VideoServerModel } from '../../../../../shared'
3import { Account } from '../../../../../shared/models/actors' 3import { Account } from '../../../../../shared/models/actors'
4import { environment } from '../../../environments/environment' 4import { environment } from '../../../environments/environment'
5import { getAbsoluteAPIUrl } from '../misc/utils'
5 6
6export class Video implements VideoServerModel { 7export class Video implements VideoServerModel {
7 accountName: string 8 accountName: string
@@ -48,11 +49,7 @@ export class Video implements VideoServerModel {
48 } 49 }
49 50
50 constructor (hash: VideoServerModel) { 51 constructor (hash: VideoServerModel) {
51 let absoluteAPIUrl = environment.apiUrl 52 const absoluteAPIUrl = getAbsoluteAPIUrl()
52 if (!absoluteAPIUrl) {
53 // The API is on the same domain
54 absoluteAPIUrl = window.location.origin
55 }
56 53
57 this.accountName = hash.accountName 54 this.accountName = hash.accountName
58 this.createdAt = new Date(hash.createdAt.toString()) 55 this.createdAt = new Date(hash.createdAt.toString())