]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Refractor account by
authorChocobozzz <me@florianbigard.com>
Mon, 8 Jan 2018 09:35:54 +0000 (10:35 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 8 Jan 2018 09:35:54 +0000 (10:35 +0100)
client/src/app/shared/account/account.model.ts
client/src/app/shared/video/video.model.ts
client/src/app/videos/+video-watch/comment/video-comment.model.ts

index 1dce0003ca0dd9dd02d57a4024242bc800ac13f9..dffca783b159f94500e5055aee1ad948904087ee 100644 (file)
@@ -22,4 +22,13 @@ export class Account implements ServerAccount {
 
     return window.location.origin + '/client/assets/images/default-avatar.png'
   }
+
+  static CREATE_BY_STRING (accountName: string, host: string) {
+    const absoluteAPIUrl = getAbsoluteAPIUrl()
+    const thisHost = new URL(absoluteAPIUrl).host
+
+    if (host.trim() === thisHost) return accountName
+
+    return accountName + '@' + host
+  }
 }
index a4b90ad94f0ae924c4db3e596f2aaf95c40fe5a1..79351ba2a70458b8a84aee5a6cc9fe86ad76069d 100644 (file)
@@ -1,7 +1,6 @@
+import { Account } from '@app/shared/account/account.model'
 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 {
@@ -35,13 +34,6 @@ export class Video implements VideoServerModel {
   nsfw: boolean
   account: Account
 
-  private static createByString (account: string, serverHost: string, apiURL: string) {
-    const thisHost = new URL(apiURL).host
-    if (serverHost.trim() === thisHost)
-      return account
-    return account + '@' + serverHost
-  }
-
   private static createDurationString (duration: number) {
     const minutes = Math.floor(duration / 60)
     const seconds = duration % 60
@@ -81,7 +73,7 @@ export class Video implements VideoServerModel {
     this.dislikes = hash.dislikes
     this.nsfw = hash.nsfw
 
-    this.by = Video.createByString(hash.accountName, hash.serverHost, absoluteAPIUrl)
+    this.by = Account.CREATE_BY_STRING(hash.accountName, hash.serverHost)
   }
 
   isVideoNSFWForUser (user: User) {
index abecae3032b1b16573437f1a544e4b6ca00e9f8d..4c5971f54b2d5056034495fbaaebadbc7d62cb0d 100644 (file)
@@ -1,4 +1,5 @@
-import { Account } from '../../../../../../shared/models/actors'
+import { Account } from '@app/shared/account/account.model'
+import { Account as AccountInterface } from '../../../../../../shared/models/actors'
 import { VideoComment as VideoCommentServerModel } from '../../../../../../shared/models/videos/video-comment.model'
 
 export class VideoComment implements VideoCommentServerModel {
@@ -10,15 +11,11 @@ export class VideoComment implements VideoCommentServerModel {
   videoId: number
   createdAt: Date | string
   updatedAt: Date | string
-  account: Account
+  account: AccountInterface
   totalReplies: number
 
   by: string
 
-  private static createByString (account: string, serverHost: string) {
-    return account + '@' + serverHost
-  }
-
   constructor (hash: VideoCommentServerModel) {
     this.id = hash.id
     this.url = hash.url
@@ -31,6 +28,6 @@ export class VideoComment implements VideoCommentServerModel {
     this.account = hash.account
     this.totalReplies = hash.totalReplies
 
-    this.by = VideoComment.createByString(this.account.name, this.account.host)
+    this.by = Account.CREATE_BY_STRING(this.account.name, this.account.host)
   }
 }