aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-main
diff options
context:
space:
mode:
authorkimsible <kimsible@users.noreply.github.com>2020-11-18 19:20:05 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-25 11:12:06 +0100
commitc418d483004dfbae9ea38d54aa1577db46d34a8a (patch)
treec4fd4ec790c6e5d6bc44e887090a8286e10fffd2 /client/src/app/shared/shared-main
parent18490b07650d77d7fe376970b749af5a8c672fd6 (diff)
downloadPeerTube-c418d483004dfbae9ea38d54aa1577db46d34a8a.tar.gz
PeerTube-c418d483004dfbae9ea38d54aa1577db46d34a8a.tar.zst
PeerTube-c418d483004dfbae9ea38d54aa1577db46d34a8a.zip
Add new default different avatar for channel and account
Diffstat (limited to 'client/src/app/shared/shared-main')
-rw-r--r--client/src/app/shared/shared-main/account/account.model.ts22
-rw-r--r--client/src/app/shared/shared-main/account/actor.model.ts18
-rw-r--r--client/src/app/shared/shared-main/users/user-notification.model.ts18
-rw-r--r--client/src/app/shared/shared-main/video-channel/video-channel.model.ts22
-rw-r--r--client/src/app/shared/shared-main/video/video.model.ts6
5 files changed, 56 insertions, 30 deletions
diff --git a/client/src/app/shared/shared-main/account/account.model.ts b/client/src/app/shared/shared-main/account/account.model.ts
index 6df2e9d10..b3dc6cfe5 100644
--- a/client/src/app/shared/shared-main/account/account.model.ts
+++ b/client/src/app/shared/shared-main/account/account.model.ts
@@ -1,4 +1,4 @@
1import { Account as ServerAccount } from '@shared/models/actors/account.model' 1import { Account as ServerAccount, Avatar } from '@shared/models'
2import { Actor } from './actor.model' 2import { Actor } from './actor.model'
3 3
4export class Account extends Actor implements ServerAccount { 4export class Account extends Actor implements ServerAccount {
@@ -13,9 +13,19 @@ export class Account extends Actor implements ServerAccount {
13 13
14 userId?: number 14 userId?: number
15 15
16 static GET_ACTOR_AVATAR_URL (actor: object) {
17 return Actor.GET_ACTOR_AVATAR_URL(actor) || this.GET_DEFAULT_AVATAR_URL()
18 }
19
20 static GET_DEFAULT_AVATAR_URL () {
21 return `${window.location.origin}/client/assets/images/default-avatar-account.png`
22 }
23
16 constructor (hash: ServerAccount) { 24 constructor (hash: ServerAccount) {
17 super(hash) 25 super(hash)
18 26
27 this.updateComputedAttributes()
28
19 this.displayName = hash.displayName 29 this.displayName = hash.displayName
20 this.description = hash.description 30 this.description = hash.description
21 this.userId = hash.userId 31 this.userId = hash.userId
@@ -27,4 +37,14 @@ export class Account extends Actor implements ServerAccount {
27 this.mutedServerByUser = false 37 this.mutedServerByUser = false
28 this.mutedServerByInstance = false 38 this.mutedServerByInstance = false
29 } 39 }
40
41 updateAvatar (newAvatar: Avatar) {
42 this.avatar = newAvatar
43
44 this.updateComputedAttributes()
45 }
46
47 private updateComputedAttributes () {
48 this.avatarUrl = Account.GET_ACTOR_AVATAR_URL(this)
49 }
30} 50}
diff --git a/client/src/app/shared/shared-main/account/actor.model.ts b/client/src/app/shared/shared-main/account/actor.model.ts
index 950e256ff..8222c9769 100644
--- a/client/src/app/shared/shared-main/account/actor.model.ts
+++ b/client/src/app/shared/shared-main/account/actor.model.ts
@@ -24,12 +24,6 @@ export abstract class Actor implements ActorServer {
24 24
25 return absoluteAPIUrl + actor.avatar.path 25 return absoluteAPIUrl + actor.avatar.path
26 } 26 }
27
28 return this.GET_DEFAULT_AVATAR_URL()
29 }
30
31 static GET_DEFAULT_AVATAR_URL () {
32 return window.location.origin + '/client/assets/images/default-avatar.png'
33 } 27 }
34 28
35 static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) { 29 static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) {
@@ -61,17 +55,5 @@ export abstract class Actor implements ActorServer {
61 55
62 this.avatar = hash.avatar 56 this.avatar = hash.avatar
63 this.isLocal = Actor.IS_LOCAL(this.host) 57 this.isLocal = Actor.IS_LOCAL(this.host)
64
65 this.updateComputedAttributes()
66 }
67
68 updateAvatar (newAvatar: Avatar) {
69 this.avatar = newAvatar
70
71 this.updateComputedAttributes()
72 }
73
74 private updateComputedAttributes () {
75 this.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(this)
76 } 58 }
77} 59}
diff --git a/client/src/app/shared/shared-main/users/user-notification.model.ts b/client/src/app/shared/shared-main/users/user-notification.model.ts
index 648bb7fe0..b1df4a584 100644
--- a/client/src/app/shared/shared-main/users/user-notification.model.ts
+++ b/client/src/app/shared/shared-main/users/user-notification.model.ts
@@ -7,7 +7,7 @@ import {
7 VideoInfo, 7 VideoInfo,
8 UserRight 8 UserRight
9} from '@shared/models' 9} from '@shared/models'
10import { Actor } from '../account/actor.model' 10import { Account, Actor, VideoChannel } from '@app/shared/shared-main'
11import { AuthUser } from '@app/core' 11import { AuthUser } from '@app/core'
12 12
13export class UserNotification implements UserNotificationServer { 13export class UserNotification implements UserNotificationServer {
@@ -95,22 +95,22 @@ export class UserNotification implements UserNotificationServer {
95 // To prevent a notification popup crash in case of bug, wrap it inside a try/catch 95 // To prevent a notification popup crash in case of bug, wrap it inside a try/catch
96 try { 96 try {
97 this.video = hash.video 97 this.video = hash.video
98 if (this.video) this.setAvatarUrl(this.video.channel) 98 if (this.video) this.setVideoChannelAvatarUrl(this.video.channel)
99 99
100 this.videoImport = hash.videoImport 100 this.videoImport = hash.videoImport
101 101
102 this.comment = hash.comment 102 this.comment = hash.comment
103 if (this.comment) this.setAvatarUrl(this.comment.account) 103 if (this.comment) this.setAccountAvatarUrl(this.comment.account)
104 104
105 this.abuse = hash.abuse 105 this.abuse = hash.abuse
106 106
107 this.videoBlacklist = hash.videoBlacklist 107 this.videoBlacklist = hash.videoBlacklist
108 108
109 this.account = hash.account 109 this.account = hash.account
110 if (this.account) this.setAvatarUrl(this.account) 110 if (this.account) this.setAccountAvatarUrl(this.account)
111 111
112 this.actorFollow = hash.actorFollow 112 this.actorFollow = hash.actorFollow
113 if (this.actorFollow) this.setAvatarUrl(this.actorFollow.follower) 113 if (this.actorFollow) this.setAccountAvatarUrl(this.actorFollow.follower)
114 114
115 this.createdAt = hash.createdAt 115 this.createdAt = hash.createdAt
116 this.updatedAt = hash.updatedAt 116 this.updatedAt = hash.updatedAt
@@ -222,7 +222,11 @@ export class UserNotification implements UserNotificationServer {
222 return [ this.buildVideoUrl(comment.video), { threadId: comment.threadId } ] 222 return [ this.buildVideoUrl(comment.video), { threadId: comment.threadId } ]
223 } 223 }
224 224
225 private setAvatarUrl (actor: { avatarUrl?: string, avatar?: { url?: string, path: string } }) { 225 private setAccountAvatarUrl (actor: { avatarUrl?: string, avatar?: { url?: string, path: string } }) {
226 actor.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(actor) 226 actor.avatarUrl = Account.GET_ACTOR_AVATAR_URL(actor)
227 }
228
229 private setVideoChannelAvatarUrl (actor: { avatarUrl?: string, avatar?: { url?: string, path: string } }) {
230 actor.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(actor)
227 } 231 }
228} 232}
diff --git a/client/src/app/shared/shared-main/video-channel/video-channel.model.ts b/client/src/app/shared/shared-main/video-channel/video-channel.model.ts
index 123389afb..4f1f5b65d 100644
--- a/client/src/app/shared/shared-main/video-channel/video-channel.model.ts
+++ b/client/src/app/shared/shared-main/video-channel/video-channel.model.ts
@@ -1,4 +1,4 @@
1import { VideoChannel as ServerVideoChannel, ViewsPerDate, Account } from '@shared/models' 1import { VideoChannel as ServerVideoChannel, ViewsPerDate, Account, Avatar } from '@shared/models'
2import { Actor } from '../account/actor.model' 2import { Actor } from '../account/actor.model'
3 3
4export class VideoChannel extends Actor implements ServerVideoChannel { 4export class VideoChannel extends Actor implements ServerVideoChannel {
@@ -17,9 +17,19 @@ export class VideoChannel extends Actor implements ServerVideoChannel {
17 17
18 viewsPerDay?: ViewsPerDate[] 18 viewsPerDay?: ViewsPerDate[]
19 19
20 static GET_ACTOR_AVATAR_URL (actor: object) {
21 return Actor.GET_ACTOR_AVATAR_URL(actor) || this.GET_DEFAULT_AVATAR_URL()
22 }
23
24 static GET_DEFAULT_AVATAR_URL () {
25 return `${window.location.origin}/client/assets/images/default-avatar-videochannel.png`
26 }
27
20 constructor (hash: ServerVideoChannel) { 28 constructor (hash: ServerVideoChannel) {
21 super(hash) 29 super(hash)
22 30
31 this.updateComputedAttributes()
32
23 this.displayName = hash.displayName 33 this.displayName = hash.displayName
24 this.description = hash.description 34 this.description = hash.description
25 this.support = hash.support 35 this.support = hash.support
@@ -39,4 +49,14 @@ export class VideoChannel extends Actor implements ServerVideoChannel {
39 this.ownerAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.ownerAccount) 49 this.ownerAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.ownerAccount)
40 } 50 }
41 } 51 }
52
53 updateAvatar (newAvatar: Avatar) {
54 this.avatar = newAvatar
55
56 this.updateComputedAttributes()
57 }
58
59 private updateComputedAttributes () {
60 this.avatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this)
61 }
42} 62}
diff --git a/client/src/app/shared/shared-main/video/video.model.ts b/client/src/app/shared/shared-main/video/video.model.ts
index 92f5bc0c0..8e0e68020 100644
--- a/client/src/app/shared/shared-main/video/video.model.ts
+++ b/client/src/app/shared/shared-main/video/video.model.ts
@@ -12,7 +12,7 @@ import {
12 VideoScheduleUpdate, 12 VideoScheduleUpdate,
13 VideoState 13 VideoState
14} from '@shared/models' 14} from '@shared/models'
15import { Actor } from '../account/actor.model' 15import { Account, Actor, VideoChannel } from '@app/shared/shared-main'
16 16
17export class Video implements VideoServerModel { 17export class Video implements VideoServerModel {
18 byVideoChannel: string 18 byVideoChannel: string
@@ -142,8 +142,8 @@ export class Video implements VideoServerModel {
142 142
143 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host) 143 this.byAccount = Actor.CREATE_BY_STRING(hash.account.name, hash.account.host)
144 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host) 144 this.byVideoChannel = Actor.CREATE_BY_STRING(hash.channel.name, hash.channel.host)
145 this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) 145 this.accountAvatarUrl = Account.GET_ACTOR_AVATAR_URL(this.account)
146 this.videoChannelAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.channel) 146 this.videoChannelAvatarUrl = VideoChannel.GET_ACTOR_AVATAR_URL(this.channel)
147 147
148 this.category.label = peertubeTranslate(this.category.label, translations) 148 this.category.label = peertubeTranslate(this.category.label, translations)
149 this.licence.label = peertubeTranslate(this.licence.label, translations) 149 this.licence.label = peertubeTranslate(this.licence.label, translations)