mirror of https://github.com/Chocobozzz/PeerTube
Fix avatars in notifications
parent
424aeb12bd
commit
a220b84b0e
|
@ -21,11 +21,11 @@ export abstract class Actor implements ServerActor {
|
||||||
isLocal: boolean
|
isLocal: boolean
|
||||||
|
|
||||||
static GET_ACTOR_AVATAR_URL (actor: { avatars: { width: number, url?: string, path: string }[] }, size?: number) {
|
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
|
const avatar = size
|
||||||
? avatars.find(a => a.width >= size)
|
? avatarsAscWidth.find(a => a.width >= size)
|
||||||
: avatars[0]
|
: avatarsAscWidth[avatarsAscWidth.length - 1] // Bigger one
|
||||||
|
|
||||||
if (!avatar) return ''
|
if (!avatar) return ''
|
||||||
if (avatar.url) return avatar.url
|
if (avatar.url) return avatar.url
|
||||||
|
|
|
@ -138,6 +138,9 @@ export class ActorImageModel extends Model<Partial<AttributesOnly<ActorImageMode
|
||||||
|
|
||||||
case ActorImageType.BANNER:
|
case ActorImageType.BANNER:
|
||||||
return join(LAZY_STATIC_PATHS.BANNERS, this.filename)
|
return join(LAZY_STATIC_PATHS.BANNERS, this.filename)
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Error('Unknown actor image type: ' + this.type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,7 @@ export class UserNotificationListQueryBuilder extends AbstractRunQuery {
|
||||||
"Video->VideoChannel->Actor"."preferredUsername" AS "Video.VideoChannel.Actor.preferredUsername",
|
"Video->VideoChannel->Actor"."preferredUsername" AS "Video.VideoChannel.Actor.preferredUsername",
|
||||||
"Video->VideoChannel->Actor->Avatars"."id" AS "Video.VideoChannel.Actor.Avatars.id",
|
"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"."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->Avatars"."filename" AS "Video.VideoChannel.Actor.Avatars.filename",
|
||||||
"Video->VideoChannel->Actor->Server"."id" AS "Video.VideoChannel.Actor.Server.id",
|
"Video->VideoChannel->Actor->Server"."id" AS "Video.VideoChannel.Actor.Server.id",
|
||||||
"Video->VideoChannel->Actor->Server"."host" AS "Video.VideoChannel.Actor.Server.host",
|
"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"."preferredUsername" AS "VideoComment.Account.Actor.preferredUsername",
|
||||||
"VideoComment->Account->Actor->Avatars"."id" AS "VideoComment.Account.Actor.Avatars.id",
|
"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"."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->Avatars"."filename" AS "VideoComment.Account.Actor.Avatars.filename",
|
||||||
"VideoComment->Account->Actor->Server"."id" AS "VideoComment.Account.Actor.Server.id",
|
"VideoComment->Account->Actor->Server"."id" AS "VideoComment.Account.Actor.Server.id",
|
||||||
"VideoComment->Account->Actor->Server"."host" AS "VideoComment.Account.Actor.Server.host",
|
"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"."preferredUsername" AS "Abuse.FlaggedAccount.Actor.preferredUsername",
|
||||||
"Abuse->FlaggedAccount->Actor->Avatars"."id" AS "Abuse.FlaggedAccount.Actor.Avatars.id",
|
"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"."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->Avatars"."filename" AS "Abuse.FlaggedAccount.Actor.Avatars.filename",
|
||||||
"Abuse->FlaggedAccount->Actor->Server"."id" AS "Abuse.FlaggedAccount.Actor.Server.id",
|
"Abuse->FlaggedAccount->Actor->Server"."id" AS "Abuse.FlaggedAccount.Actor.Server.id",
|
||||||
"Abuse->FlaggedAccount->Actor->Server"."host" AS "Abuse.FlaggedAccount.Actor.Server.host",
|
"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->Account"."name" AS "ActorFollow.ActorFollower.Account.name",
|
||||||
"ActorFollow->ActorFollower->Avatars"."id" AS "ActorFollow.ActorFollower.Avatars.id",
|
"ActorFollow->ActorFollower->Avatars"."id" AS "ActorFollow.ActorFollower.Avatars.id",
|
||||||
"ActorFollow->ActorFollower->Avatars"."width" AS "ActorFollow.ActorFollower.Avatars.width",
|
"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->Avatars"."filename" AS "ActorFollow.ActorFollower.Avatars.filename",
|
||||||
"ActorFollow->ActorFollower->Server"."id" AS "ActorFollow.ActorFollower.Server.id",
|
"ActorFollow->ActorFollower->Server"."id" AS "ActorFollow.ActorFollower.Server.id",
|
||||||
"ActorFollow->ActorFollower->Server"."host" AS "ActorFollow.ActorFollower.Server.host",
|
"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"."preferredUsername" AS "Account.Actor.preferredUsername",
|
||||||
"Account->Actor->Avatars"."id" AS "Account.Actor.Avatars.id",
|
"Account->Actor->Avatars"."id" AS "Account.Actor.Avatars.id",
|
||||||
"Account->Actor->Avatars"."width" AS "Account.Actor.Avatars.width",
|
"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->Avatars"."filename" AS "Account.Actor.Avatars.filename",
|
||||||
"Account->Actor->Server"."id" AS "Account.Actor.Server.id",
|
"Account->Actor->Server"."id" AS "Account.Actor.Server.id",
|
||||||
"Account->Actor->Server"."host" AS "Account.Actor.Server.host"`
|
"Account->Actor->Server"."host" AS "Account.Actor.Server.host"`
|
||||||
|
|
|
@ -185,7 +185,7 @@ async function checkUserRegistered (options: CheckerBaseParams & {
|
||||||
expect(notification).to.not.be.undefined
|
expect(notification).to.not.be.undefined
|
||||||
expect(notification.type).to.equal(notificationType)
|
expect(notification.type).to.equal(notificationType)
|
||||||
|
|
||||||
checkActor(notification.account)
|
checkActor(notification.account, { withAvatar: false })
|
||||||
expect(notification.account.name).to.equal(username)
|
expect(notification.account.name).to.equal(username)
|
||||||
} else {
|
} else {
|
||||||
expect(notification).to.satisfy(n => n.type !== notificationType || n.account.name !== username)
|
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).to.not.be.undefined
|
||||||
expect(notification.type).to.equal(notificationType)
|
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.name).to.equal('peertube')
|
||||||
expect(notification.actorFollow.follower.host).to.equal(followerHost)
|
expect(notification.actorFollow.follower.host).to.equal(followerHost)
|
||||||
|
|
||||||
|
@ -288,7 +288,8 @@ async function checkAutoInstanceFollowing (options: CheckerBaseParams & {
|
||||||
expect(notification.type).to.equal(notificationType)
|
expect(notification.type).to.equal(notificationType)
|
||||||
|
|
||||||
const following = notification.actorFollow.following
|
const following = notification.actorFollow.following
|
||||||
checkActor(following)
|
|
||||||
|
checkActor(following, { withAvatar: false })
|
||||||
expect(following.name).to.equal('peertube')
|
expect(following.name).to.equal('peertube')
|
||||||
expect(following.host).to.equal(followingHost)
|
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)
|
const userAccessToken = await servers[0].login.getAccessToken(user)
|
||||||
|
|
||||||
await servers[0].notifications.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() })
|
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() })
|
await servers[0].notifications.updateMySettings({ settings: getAllNotificationsSettings() })
|
||||||
|
|
||||||
if (serversCount > 1) {
|
if (serversCount > 1) {
|
||||||
|
@ -832,10 +836,18 @@ function checkVideo (video: any, videoName?: string, shortUUID?: string) {
|
||||||
expect(video.id).to.be.a('number')
|
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.be.a('string')
|
||||||
expect(actor.displayName).to.not.be.empty
|
expect(actor.displayName).to.not.be.empty
|
||||||
expect(actor.host).to.not.be.undefined
|
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) {
|
function checkComment (comment: any, commentId: number, threadId: number) {
|
||||||
|
|
Loading…
Reference in New Issue