Skip to content

Commit

Permalink
Merge pull request #4980 from vector-im/doug/4978_room_avatar_colours
Browse files Browse the repository at this point in the history
Fix generated avatar colours not matching Element Web.
  • Loading branch information
pixlwave authored Oct 11, 2021
2 parents f891cce + bd56dbe commit 93e7089
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Riot/Categories/MXKImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import Foundation

extension MXKImageView {
@objc func vc_setRoomAvatarImage(with url: String?, displayName: String, mediaManager: MXMediaManager) {
@objc func vc_setRoomAvatarImage(with url: String?, roomId: String, displayName: String, mediaManager: MXMediaManager) {
// Use the display name to prepare the default avatar image.
let avatarImage = AvatarGenerator.generateAvatar(forText: displayName)
let avatarImage = AvatarGenerator.generateAvatar(forMatrixItem: roomId, withDisplayName: displayName)

if let avatarUrl = url {
self.enableInMemoryCache = true
Expand Down
32 changes: 10 additions & 22 deletions Riot/Categories/MXRoomSummary+Riot.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,20 @@

#import "AvatarGenerator.h"

#ifdef IS_SHARE_EXTENSION
#import "RiotShareExtension-Swift.h"
#else
#import "Riot-Swift.h"
#endif

@implementation MXRoomSummary (Riot)

- (void)setRoomAvatarImageIn:(MXKImageView*)mxkImageView
{
// Use the room display name to prepare the default avatar image.
NSString *avatarDisplayName = self.displayname;
UIImage* avatarImage = [AvatarGenerator generateAvatarForMatrixItem:self.roomId withDisplayName:avatarDisplayName];

if (self.avatar)
{
mxkImageView.enableInMemoryCache = YES;

[mxkImageView setImageURI:self.avatar
withType:nil
andImageOrientation:UIImageOrientationUp
toFitViewSize:mxkImageView.frame.size
withMethod:MXThumbnailingMethodCrop
previewImage:avatarImage
mediaManager:self.mxSession.mediaManager];
}
else
{
mxkImageView.image = avatarImage;
}

mxkImageView.contentMode = UIViewContentModeScaleAspectFill;
[mxkImageView vc_setRoomAvatarImageWith:self.avatar
roomId:self.roomId
displayName:self.displayname
mediaManager:self.mxSession.mediaManager];
}

- (RoomEncryptionTrustLevel)roomEncryptionTrustLevel
Expand Down
10 changes: 8 additions & 2 deletions Riot/Modules/Common/Recents/Views/RecentTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,17 @@ - (void)render:(MXKCellData *)cellData

if (roomCellData.spaceChildInfo)
{
[self.roomAvatar vc_setRoomAvatarImageWith:roomCellData.spaceChildInfo.avatarUrl displayName:roomCellData.spaceChildInfo.displayName mediaManager:roomCellData.recentsDataSource.mxSession.mediaManager];
[self.roomAvatar vc_setRoomAvatarImageWith:roomCellData.spaceChildInfo.avatarUrl
roomId:roomCellData.spaceChildInfo.childRoomId
displayName:roomCellData.spaceChildInfo.displayName
mediaManager:roomCellData.recentsDataSource.mxSession.mediaManager];
}
else
{
[self.roomAvatar vc_setRoomAvatarImageWith:roomCellData.roomSummary.avatar displayName:roomCellData.roomSummary.displayname mediaManager:roomCellData.roomSummary.mxSession.mediaManager];
[self.roomAvatar vc_setRoomAvatarImageWith:roomCellData.roomSummary.avatar
roomId:roomCellData.roomSummary.roomId
displayName:roomCellData.roomSummary.displayname
mediaManager:roomCellData.roomSummary.mxSession.mediaManager];
}
}
else
Expand Down
10 changes: 8 additions & 2 deletions Riot/Modules/Home/Views/RoomCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,17 @@ - (void)render:(MXKCellData *)cellData

if (roomCellData.roomSummary)
{
[self.roomAvatar vc_setRoomAvatarImageWith:roomCellData.roomSummary.avatar displayName:roomCellData.roomSummary.displayname mediaManager:roomCellData.roomSummary.mxSession.mediaManager];
[self.roomAvatar vc_setRoomAvatarImageWith:roomCellData.roomSummary.avatar
roomId:roomCellData.roomSummary.roomId
displayName:roomCellData.roomSummary.displayname
mediaManager:roomCellData.roomSummary.mxSession.mediaManager];
}
else
{
[self.roomAvatar vc_setRoomAvatarImageWith:roomCellData.spaceChildInfo.avatarUrl displayName:roomCellData.spaceChildInfo.displayName mediaManager:roomCellData.recentsDataSource.mxSession.mediaManager];
[self.roomAvatar vc_setRoomAvatarImageWith:roomCellData.spaceChildInfo.avatarUrl
roomId:roomCellData.spaceChildInfo.childRoomId
displayName:roomCellData.spaceChildInfo.displayName
mediaManager:roomCellData.recentsDataSource.mxSession.mediaManager];
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
//

#import "ThemeService.h"
#import "AvatarGenerator.h"
1 change: 1 addition & 0 deletions RiotShareExtension/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ targets:
- path: ../Riot/Utils/AvatarGenerator.m
- path: ../Config/BuildSettings.swift
- path: ../Riot/Categories/Character.swift
- path: ../Riot/Categories/MXKImageView.swift
- path: ../Riot/Categories/MXRoom+Riot.m
- path: ../Config/Configurable.swift
- path: ../Config/CommonConfiguration.swift
Expand Down
1 change: 1 addition & 0 deletions changelog.d/4978.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Room Lists: Fix generated avatar colours not matching Element Web.

0 comments on commit 93e7089

Please sign in to comment.