aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-25 15:43:19 +0200
committerChocobozzz <me@florianbigard.com>2018-04-25 15:43:19 +0200
commitd3e91a5f72ac9c986cdb67d7d6c85bb4819e680c (patch)
tree3c2406346c7774587ba4e095ab595e5953e25c61 /client/src/app/shared
parent03e12d7c4954e1071fdeb7ef362ea5c3965d4075 (diff)
downloadPeerTube-d3e91a5f72ac9c986cdb67d7d6c85bb4819e680c.tar.gz
PeerTube-d3e91a5f72ac9c986cdb67d7d6c85bb4819e680c.tar.zst
PeerTube-d3e91a5f72ac9c986cdb67d7d6c85bb4819e680c.zip
Add video channel account list
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/account/account.model.ts44
-rw-r--r--client/src/app/shared/actor/actor.model.ts50
-rw-r--r--client/src/app/shared/shared.module.ts4
-rw-r--r--client/src/app/shared/users/user.model.ts17
-rw-r--r--client/src/app/shared/video-channel/video-channel.model.ts23
-rw-r--r--client/src/app/shared/video-channel/video-channel.service.ts36
-rw-r--r--client/src/app/shared/video/video.model.ts6
7 files changed, 131 insertions, 49 deletions
diff --git a/client/src/app/shared/account/account.model.ts b/client/src/app/shared/account/account.model.ts
index 10a70ac31..6a3c6451c 100644
--- a/client/src/app/shared/account/account.model.ts
+++ b/client/src/app/shared/account/account.model.ts
@@ -1,50 +1,14 @@
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 { Actor } from '../actor/actor.model'
3import { getAbsoluteAPIUrl } from '../misc/utils'
4 3
5export class Account implements ServerAccount { 4export class Account extends Actor implements ServerAccount {
6 id: number
7 uuid: string
8 url: string
9 name: string
10 displayName: string 5 displayName: string
11 description: string 6 description: string
12 host: string
13 followingCount: number
14 followersCount: number
15 createdAt: Date
16 updatedAt: Date
17 avatar: Avatar
18
19 static GET_ACCOUNT_AVATAR_URL (account: Account) {
20 const absoluteAPIUrl = getAbsoluteAPIUrl()
21
22 if (account && account.avatar) return absoluteAPIUrl + account.avatar.path
23
24 return window.location.origin + '/client/assets/images/default-avatar.png'
25 }
26
27 static CREATE_BY_STRING (accountName: string, host: string) {
28 const absoluteAPIUrl = getAbsoluteAPIUrl()
29 const thisHost = new URL(absoluteAPIUrl).host
30
31 if (host.trim() === thisHost) return accountName
32
33 return accountName + '@' + host
34 }
35 7
36 constructor (hash: ServerAccount) { 8 constructor (hash: ServerAccount) {
37 this.id = hash.id 9 super(hash)
38 this.uuid = hash.uuid 10
39 this.url = hash.url
40 this.name = hash.name
41 this.displayName = hash.displayName 11 this.displayName = hash.displayName
42 this.description = hash.description 12 this.description = hash.description
43 this.host = hash.host
44 this.followingCount = hash.followingCount
45 this.followersCount = hash.followersCount
46 this.createdAt = new Date(hash.createdAt.toString())
47 this.updatedAt = new Date(hash.updatedAt.toString())
48 this.avatar = hash.avatar
49 } 13 }
50} 14}
diff --git a/client/src/app/shared/actor/actor.model.ts b/client/src/app/shared/actor/actor.model.ts
new file mode 100644
index 000000000..56ff780b7
--- /dev/null
+++ b/client/src/app/shared/actor/actor.model.ts
@@ -0,0 +1,50 @@
1import { Actor as ActorServer } from '../../../../../shared/models/actors/actor.model'
2import { getAbsoluteAPIUrl } from '@app/shared/misc/utils'
3import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
4
5export abstract class Actor implements ActorServer {
6 id: number
7 uuid: string
8 url: string
9 name: string
10 host: string
11 followingCount: number
12 followersCount: number
13 createdAt: Date
14 updatedAt: Date
15 avatar: Avatar
16
17 avatarUrl: string
18
19 static GET_ACTOR_AVATAR_URL (actor: { avatar: Avatar }) {
20 const absoluteAPIUrl = getAbsoluteAPIUrl()
21
22 if (actor && actor.avatar) return absoluteAPIUrl + actor.avatar.path
23
24 return window.location.origin + '/client/assets/images/default-avatar.png'
25 }
26
27 static CREATE_BY_STRING (accountName: string, host: string) {
28 const absoluteAPIUrl = getAbsoluteAPIUrl()
29 const thisHost = new URL(absoluteAPIUrl).host
30
31 if (host.trim() === thisHost) return accountName
32
33 return accountName + '@' + host
34 }
35
36 protected constructor (hash: ActorServer) {
37 this.id = hash.id
38 this.uuid = hash.uuid
39 this.url = hash.url
40 this.name = hash.name
41 this.host = hash.host
42 this.followingCount = hash.followingCount
43 this.followersCount = hash.followersCount
44 this.createdAt = new Date(hash.createdAt.toString())
45 this.updatedAt = new Date(hash.updatedAt.toString())
46 this.avatar = hash.avatar
47
48 this.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(this)
49 }
50}
diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts
index 2178eebc8..20019e47a 100644
--- a/client/src/app/shared/shared.module.ts
+++ b/client/src/app/shared/shared.module.ts
@@ -32,6 +32,7 @@ import { VideoFeedComponent } from './video/video-feed.component'
32import { VideoThumbnailComponent } from './video/video-thumbnail.component' 32import { VideoThumbnailComponent } from './video/video-thumbnail.component'
33import { VideoService } from './video/video.service' 33import { VideoService } from './video/video.service'
34import { AccountService } from '@app/shared/account/account.service' 34import { AccountService } from '@app/shared/account/account.service'
35import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
35 36
36@NgModule({ 37@NgModule({
37 imports: [ 38 imports: [
@@ -106,7 +107,8 @@ import { AccountService } from '@app/shared/account/account.service'
106 UserService, 107 UserService,
107 VideoService, 108 VideoService,
108 AccountService, 109 AccountService,
109 MarkdownService 110 MarkdownService,
111 VideoChannelService
110 ] 112 ]
111}) 113})
112export class SharedModule { } 114export class SharedModule { }
diff --git a/client/src/app/shared/users/user.model.ts b/client/src/app/shared/users/user.model.ts
index 2bdc48a1d..d4551de89 100644
--- a/client/src/app/shared/users/user.model.ts
+++ b/client/src/app/shared/users/user.model.ts
@@ -1,6 +1,6 @@
1import { hasUserRight, User as UserServerModel, UserRight, UserRole, VideoChannel } from '../../../../../shared' 1import { Account, hasUserRight, User as UserServerModel, UserRight, UserRole, VideoChannel } from '../../../../../shared'
2import { Account } from '../account/account.model'
3import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type' 2import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
3import { Actor } from '@app/shared/actor/actor.model'
4 4
5export type UserConstructorHash = { 5export type UserConstructorHash = {
6 id: number, 6 id: number,
@@ -25,6 +25,7 @@ export class User implements UserServerModel {
25 account: Account 25 account: Account
26 videoChannels: VideoChannel[] 26 videoChannels: VideoChannel[]
27 createdAt: Date 27 createdAt: Date
28 accountAvatarUrl: string
28 29
29 constructor (hash: UserConstructorHash) { 30 constructor (hash: UserConstructorHash) {
30 this.id = hash.id 31 this.id = hash.id
@@ -52,19 +53,23 @@ export class User implements UserServerModel {
52 if (hash.createdAt !== undefined) { 53 if (hash.createdAt !== undefined) {
53 this.createdAt = hash.createdAt 54 this.createdAt = hash.createdAt
54 } 55 }
56
57 this.updateComputedAttributes()
55 } 58 }
56 59
57 hasRight (right: UserRight) { 60 hasRight (right: UserRight) {
58 return hasUserRight(this.role, right) 61 return hasUserRight(this.role, right)
59 } 62 }
60 63
61 getAvatarUrl () {
62 return Account.GET_ACCOUNT_AVATAR_URL(this.account)
63 }
64
65 patch (obj: UserServerModel) { 64 patch (obj: UserServerModel) {
66 for (const key of Object.keys(obj)) { 65 for (const key of Object.keys(obj)) {
67 this[key] = obj[key] 66 this[key] = obj[key]
68 } 67 }
68
69 this.updateComputedAttributes()
70 }
71
72 private updateComputedAttributes () {
73 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
69 } 74 }
70} 75}
diff --git a/client/src/app/shared/video-channel/video-channel.model.ts b/client/src/app/shared/video-channel/video-channel.model.ts
new file mode 100644
index 000000000..01381ac30
--- /dev/null
+++ b/client/src/app/shared/video-channel/video-channel.model.ts
@@ -0,0 +1,23 @@
1import { VideoChannel as ServerVideoChannel } from '../../../../../shared/models/videos/video-channel.model'
2import { Actor } from '../actor/actor.model'
3
4export class VideoChannel extends Actor implements ServerVideoChannel {
5 displayName: string
6 description: string
7 support: string
8 isLocal: boolean
9 ownerAccount?: {
10 id: number
11 uuid: string
12 }
13
14 constructor (hash: ServerVideoChannel) {
15 super(hash)
16
17 this.displayName = hash.displayName
18 this.description = hash.description
19 this.support = hash.support
20 this.isLocal = hash.isLocal
21 this.ownerAccount = hash.ownerAccount
22 }
23}
diff --git a/client/src/app/shared/video-channel/video-channel.service.ts b/client/src/app/shared/video-channel/video-channel.service.ts
new file mode 100644
index 000000000..1f9088c38
--- /dev/null
+++ b/client/src/app/shared/video-channel/video-channel.service.ts
@@ -0,0 +1,36 @@
1import { Injectable } from '@angular/core'
2import 'rxjs/add/operator/catch'
3import 'rxjs/add/operator/map'
4import { Observable } from 'rxjs/Observable'
5import { RestExtractor } from '../rest/rest-extractor.service'
6import { RestService } from '../rest/rest.service'
7import { HttpClient } from '@angular/common/http'
8import { VideoChannel as VideoChannelServer } from '../../../../../shared/models/videos'
9import { AccountService } from '../account/account.service'
10import { ResultList } from '../../../../../shared'
11import { VideoChannel } from './video-channel.model'
12
13@Injectable()
14export class VideoChannelService {
15 constructor (
16 private authHttp: HttpClient,
17 private restExtractor: RestExtractor,
18 private restService: RestService
19 ) {}
20
21 getVideoChannels (accountId: number): Observable<ResultList<VideoChannel>> {
22 return this.authHttp.get<ResultList<VideoChannelServer>>(AccountService.BASE_ACCOUNT_URL + accountId + '/video-channels')
23 .map(res => this.extractVideoChannels(res))
24 .catch((res) => this.restExtractor.handleError(res))
25 }
26
27 private extractVideoChannels (result: ResultList<VideoChannelServer>) {
28 const videoChannels: VideoChannel[] = []
29
30 for (const videoChannelJSON of result.data) {
31 videoChannels.push(new VideoChannel(videoChannelJSON))
32 }
33
34 return { data: videoChannels, total: result.total }
35 }
36}
diff --git a/client/src/app/shared/video/video.model.ts b/client/src/app/shared/video/video.model.ts
index 2e85f40ef..f56eecaeb 100644
--- a/client/src/app/shared/video/video.model.ts
+++ b/client/src/app/shared/video/video.model.ts
@@ -1,13 +1,14 @@
1import { Account } from '@app/shared/account/account.model'
2import { User } from '../' 1import { User } from '../'
3import { Video as VideoServerModel, VideoPrivacy } from '../../../../../shared' 2import { Video as VideoServerModel, VideoPrivacy } from '../../../../../shared'
4import { Avatar } from '../../../../../shared/models/avatars/avatar.model' 3import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
5import { VideoConstant } from '../../../../../shared/models/videos/video.model' 4import { VideoConstant } from '../../../../../shared/models/videos/video.model'
6import { getAbsoluteAPIUrl } from '../misc/utils' 5import { getAbsoluteAPIUrl } from '../misc/utils'
7import { ServerConfig } from '../../../../../shared/models' 6import { ServerConfig } from '../../../../../shared/models'
7import { Actor } from '@app/shared/actor/actor.model'
8 8
9export class Video implements VideoServerModel { 9export class Video implements VideoServerModel {
10 by: string 10 by: string
11 accountAvatarUrl: string
11 createdAt: Date 12 createdAt: Date
12 updatedAt: Date 13 updatedAt: Date
13 publishedAt: Date 14 publishedAt: Date
@@ -85,7 +86,8 @@ export class Video implements VideoServerModel {
85 this.nsfw = hash.nsfw 86 this.nsfw = hash.nsfw
86 this.account = hash.account 87 this.account = hash.account
87 88
88 this.by = Account.CREATE_BY_STRING(hash.account.name, hash.account.host) 89 this.by = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
90 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account)
89 } 91 }
90 92
91 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) { 93 isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {