]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix avatars in notifications
authorChocobozzz <me@florianbigard.com>
Wed, 25 May 2022 07:10:20 +0000 (09:10 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 25 May 2022 07:37:30 +0000 (09:37 +0200)
client/src/app/shared/shared-main/account/actor.model.ts
server/models/actor/actor-image.ts
server/models/user/sql/user-notitication-list-query-builder.ts
server/tests/shared/notifications.ts

index 6be6b75d0e63c948f138674a4fec39676ba7f8de..6e45ba588355b539f3b36a7e4500fae97e965e9f 100644 (file)
@@ -21,11 +21,11 @@ export abstract class Actor implements ServerActor {
   isLocal: boolean
 
   static GET_ACTOR_AVATAR_URL (actor: { avatars: { width: number, url?: string, path: string }[] }, size?: number) {
-    const avatars = actor.avatars.sort((a, b) => b.width - a.width)
+    const avatarsAscWidth = actor.avatars.sort((a, b) => a.width - b.width)
 
     const avatar = size
-      ? avatars.find(a => a.width >= size)
-      : avatars[0]
+      ? avatarsAscWidth.find(a => a.width >= size)
+      : avatarsAscWidth[avatarsAscWidth.length - 1] // Bigger one
 
     if (!avatar) return ''
     if (avatar.url) return avatar.url
index f74ab735e31717d5e0a9f04069a487376fb4bf04..9d44ef4d1a2fdbad8f7a6b5f5634feb661e188f9 100644 (file)
@@ -138,6 +138,9 @@ export class ActorImageModel extends Model<Partial<AttributesOnly<ActorImageMode
 
       case ActorImageType.BANNER:
         return join(LAZY_STATIC_PATHS.BANNERS, this.filename)
+
+      default:
+        throw new Error('Unknown actor image type: ' + this.type)
     }
   }
 
index 6a6a71e3ade02d50a8f8bc61f911e1fd235cf808..31b4932bf47466c5d8159b8582d2defbe3978c90 100644 (file)
@@ -86,6 +86,7 @@ export class UserNotificationListQueryBuilder extends AbstractRunQuery {
       "Video->VideoChannel->Actor"."preferredUsername" AS "Video.VideoChannel.Actor.preferredUsername",
       "Video->VideoChannel->Actor->Avatars"."id" AS "Video.VideoChannel.Actor.Avatars.id",
       "Video->VideoChannel->Actor->Avatars"."width" AS "Video.VideoChannel.Actor.Avatars.width",
+      "Video->VideoChannel->Actor->Avatars"."type" AS "Video.VideoChannel.Actor.Avatars.type",
       "Video->VideoChannel->Actor->Avatars"."filename" AS "Video.VideoChannel.Actor.Avatars.filename",
       "Video->VideoChannel->Actor->Server"."id" AS "Video.VideoChannel.Actor.Server.id",
       "Video->VideoChannel->Actor->Server"."host" AS "Video.VideoChannel.Actor.Server.host",
@@ -97,6 +98,7 @@ export class UserNotificationListQueryBuilder extends AbstractRunQuery {
       "VideoComment->Account->Actor"."preferredUsername" AS "VideoComment.Account.Actor.preferredUsername",
       "VideoComment->Account->Actor->Avatars"."id" AS "VideoComment.Account.Actor.Avatars.id",
       "VideoComment->Account->Actor->Avatars"."width" AS "VideoComment.Account.Actor.Avatars.width",
+      "VideoComment->Account->Actor->Avatars"."type" AS "VideoComment.Account.Actor.Avatars.type",
       "VideoComment->Account->Actor->Avatars"."filename" AS "VideoComment.Account.Actor.Avatars.filename",
       "VideoComment->Account->Actor->Server"."id" AS "VideoComment.Account.Actor.Server.id",
       "VideoComment->Account->Actor->Server"."host" AS "VideoComment.Account.Actor.Server.host",
@@ -127,6 +129,7 @@ export class UserNotificationListQueryBuilder extends AbstractRunQuery {
       "Abuse->FlaggedAccount->Actor"."preferredUsername" AS "Abuse.FlaggedAccount.Actor.preferredUsername",
       "Abuse->FlaggedAccount->Actor->Avatars"."id" AS "Abuse.FlaggedAccount.Actor.Avatars.id",
       "Abuse->FlaggedAccount->Actor->Avatars"."width" AS "Abuse.FlaggedAccount.Actor.Avatars.width",
+      "Abuse->FlaggedAccount->Actor->Avatars"."type" AS "Abuse.FlaggedAccount.Actor.Avatars.type",
       "Abuse->FlaggedAccount->Actor->Avatars"."filename" AS "Abuse.FlaggedAccount.Actor.Avatars.filename",
       "Abuse->FlaggedAccount->Actor->Server"."id" AS "Abuse.FlaggedAccount.Actor.Server.id",
       "Abuse->FlaggedAccount->Actor->Server"."host" AS "Abuse.FlaggedAccount.Actor.Server.host",
@@ -155,6 +158,7 @@ export class UserNotificationListQueryBuilder extends AbstractRunQuery {
       "ActorFollow->ActorFollower->Account"."name" AS "ActorFollow.ActorFollower.Account.name",
       "ActorFollow->ActorFollower->Avatars"."id" AS "ActorFollow.ActorFollower.Avatars.id",
       "ActorFollow->ActorFollower->Avatars"."width" AS "ActorFollow.ActorFollower.Avatars.width",
+      "ActorFollow->ActorFollower->Avatars"."type" AS "ActorFollow.ActorFollower.Avatars.type",
       "ActorFollow->ActorFollower->Avatars"."filename" AS "ActorFollow.ActorFollower.Avatars.filename",
       "ActorFollow->ActorFollower->Server"."id" AS "ActorFollow.ActorFollower.Server.id",
       "ActorFollow->ActorFollower->Server"."host" AS "ActorFollow.ActorFollower.Server.host",
@@ -173,6 +177,7 @@ export class UserNotificationListQueryBuilder extends AbstractRunQuery {
       "Account->Actor"."preferredUsername" AS "Account.Actor.preferredUsername",
       "Account->Actor->Avatars"."id" AS "Account.Actor.Avatars.id",
       "Account->Actor->Avatars"."width" AS "Account.Actor.Avatars.width",
+      "Account->Actor->Avatars"."type" AS "Account.Actor.Avatars.type",
       "Account->Actor->Avatars"."filename" AS "Account.Actor.Avatars.filename",
       "Account->Actor->Server"."id" AS "Account.Actor.Server.id",
       "Account->Actor->Server"."host" AS "Account.Actor.Server.host"`
index a62410880fedb721f02dd408d58f173a387987c7..09bc8da03ac88ca6d25fe60b5a8c8301cdde2560 100644 (file)
@@ -185,7 +185,7 @@ async function checkUserRegistered (options: CheckerBaseParams & {
       expect(notification).to.not.be.undefined
       expect(notification.type).to.equal(notificationType)
 
-      checkActor(notification.account)
+      checkActor(notification.account, { withAvatar: false })
       expect(notification.account.name).to.equal(username)
     } else {
       expect(notification).to.satisfy(n => n.type !== notificationType || n.account.name !== username)
@@ -253,7 +253,7 @@ async function checkNewInstanceFollower (options: CheckerBaseParams & {
       expect(notification).to.not.be.undefined
       expect(notification.type).to.equal(notificationType)
 
-      checkActor(notification.actorFollow.follower)
+      checkActor(notification.actorFollow.follower, { withAvatar: false })
       expect(notification.actorFollow.follower.name).to.equal('peertube')
       expect(notification.actorFollow.follower.host).to.equal(followerHost)
 
@@ -288,7 +288,8 @@ async function checkAutoInstanceFollowing (options: CheckerBaseParams & {
       expect(notification.type).to.equal(notificationType)
 
       const following = notification.actorFollow.following
-      checkActor(following)
+
+      checkActor(following, { withAvatar: false })
       expect(following.name).to.equal('peertube')
       expect(following.host).to.equal(followingHost)
 
@@ -701,6 +702,9 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
   const userAccessToken = await servers[0].login.getAccessToken(user)
 
   await servers[0].notifications.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() })
+  await servers[0].users.updateMyAvatar({ token: userAccessToken, fixture: 'avatar.png' })
+  await servers[0].channels.updateImage({ channelName: 'user_1_channel', token: userAccessToken, fixture: 'avatar.png', type: 'avatar' })
+
   await servers[0].notifications.updateMySettings({ settings: getAllNotificationsSettings() })
 
   if (serversCount > 1) {
@@ -832,10 +836,18 @@ function checkVideo (video: any, videoName?: string, shortUUID?: string) {
   expect(video.id).to.be.a('number')
 }
 
-function checkActor (actor: any) {
+function checkActor (actor: any, options: { withAvatar?: boolean } = {}) {
+  const { withAvatar = true } = options
+
   expect(actor.displayName).to.be.a('string')
   expect(actor.displayName).to.not.be.empty
   expect(actor.host).to.not.be.undefined
+
+  if (withAvatar) {
+    expect(actor.avatars).to.be.an('array')
+    expect(actor.avatars).to.have.lengthOf(2)
+    expect(actor.avatars[0].path).to.exist.and.not.empty
+  }
 }
 
 function checkComment (comment: any, commentId: number, threadId: number) {