mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-24 00:16:39 +02:00
Merge pull request #1510 from vector-im/room_summary_displayname_avatar
Handle the room display name and its avatar at the room summary level.
This commit is contained in:
@@ -491,6 +491,7 @@
|
||||
F0B4CBB11F4215E3008E99C5 /* EventDetailsView.m in Sources */ = {isa = PBXBuildFile; fileRef = F0B4CBAF1F4215E3008E99C5 /* EventDetailsView.m */; };
|
||||
F0B4CBB21F4215E3008E99C5 /* EventDetailsView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F0B4CBB01F4215E3008E99C5 /* EventDetailsView.xib */; };
|
||||
F0B7A8B11F475783006E27D2 /* RoomsListViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F0B7A8AF1F4756A5006E27D2 /* RoomsListViewController.xib */; };
|
||||
F0D2ADA11F6AA5FD00A7097D /* MXRoomSummary+Riot.m in Sources */ = {isa = PBXBuildFile; fileRef = F0D2ADA01F6AA5FD00A7097D /* MXRoomSummary+Riot.m */; };
|
||||
F0D869EB1EC455A100BB0A2B /* create_direct_chat.png in Resources */ = {isa = PBXBuildFile; fileRef = F0D869E81EC455A100BB0A2B /* create_direct_chat.png */; };
|
||||
F0D869EC1EC455A100BB0A2B /* create_direct_chat@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0D869E91EC455A100BB0A2B /* create_direct_chat@2x.png */; };
|
||||
F0D869ED1EC455A100BB0A2B /* create_direct_chat@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0D869EA1EC455A100BB0A2B /* create_direct_chat@3x.png */; };
|
||||
@@ -1188,6 +1189,8 @@
|
||||
F0B4CBAF1F4215E3008E99C5 /* EventDetailsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EventDetailsView.m; sourceTree = "<group>"; };
|
||||
F0B4CBB01F4215E3008E99C5 /* EventDetailsView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EventDetailsView.xib; sourceTree = "<group>"; };
|
||||
F0B7A8AF1F4756A5006E27D2 /* RoomsListViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RoomsListViewController.xib; sourceTree = "<group>"; };
|
||||
F0D2AD9F1F6AA5FD00A7097D /* MXRoomSummary+Riot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MXRoomSummary+Riot.h"; sourceTree = "<group>"; };
|
||||
F0D2ADA01F6AA5FD00A7097D /* MXRoomSummary+Riot.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MXRoomSummary+Riot.m"; sourceTree = "<group>"; };
|
||||
F0D869E81EC455A100BB0A2B /* create_direct_chat.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = create_direct_chat.png; sourceTree = "<group>"; };
|
||||
F0D869E91EC455A100BB0A2B /* create_direct_chat@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "create_direct_chat@2x.png"; sourceTree = "<group>"; };
|
||||
F0D869EA1EC455A100BB0A2B /* create_direct_chat@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "create_direct_chat@3x.png"; sourceTree = "<group>"; };
|
||||
@@ -1749,6 +1752,8 @@
|
||||
F083BBE61E7009EC00A9B29C /* MXKRoomBubbleTableViewCell+Riot.m */,
|
||||
F083BBE71E7009EC00A9B29C /* MXRoom+Riot.h */,
|
||||
F083BBE81E7009EC00A9B29C /* MXRoom+Riot.m */,
|
||||
F0D2AD9F1F6AA5FD00A7097D /* MXRoomSummary+Riot.h */,
|
||||
F0D2ADA01F6AA5FD00A7097D /* MXRoomSummary+Riot.m */,
|
||||
F083BBE91E7009EC00A9B29C /* UINavigationController+Riot.h */,
|
||||
F083BBEA1E7009EC00A9B29C /* UINavigationController+Riot.m */,
|
||||
F083BBEB1E7009EC00A9B29C /* UIViewController+RiotSearch.h */,
|
||||
@@ -3068,6 +3073,7 @@
|
||||
F083BE6E1E7009ED00A9B29C /* RoomOutgoingAttachmentWithPaginationTitleBubbleCell.m in Sources */,
|
||||
3233F7311F31F4BF006ACA81 /* JitsiViewController.m in Sources */,
|
||||
F083BE2A1E7009ED00A9B29C /* UsersDevicesViewController.m in Sources */,
|
||||
F0D2ADA11F6AA5FD00A7097D /* MXRoomSummary+Riot.m in Sources */,
|
||||
F083BE2D1E7009ED00A9B29C /* ForgotPasswordInputsView.m in Sources */,
|
||||
F083BE7E1E7009ED00A9B29C /* InviteRecentTableViewCell.m in Sources */,
|
||||
F083BE3C1E7009ED00A9B29C /* RoomIncomingEncryptedAttachmentWithoutSenderInfoBubbleCell.m in Sources */,
|
||||
|
||||
+1
-2
@@ -34,7 +34,6 @@
|
||||
#import "MatrixSDK/MatrixSDK.h"
|
||||
|
||||
#import "Tools.h"
|
||||
#import "MXRoom+Riot.h"
|
||||
#import "WidgetManager.h"
|
||||
|
||||
#import "AFNetworkReachabilityManager.h"
|
||||
@@ -2459,7 +2458,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
|
||||
[_jitsiViewController dismissViewControllerAnimated:YES completion:^{
|
||||
|
||||
MXRoom *room = [_jitsiViewController.widget.mxSession roomWithRoomId:_jitsiViewController.widget.roomId];
|
||||
NSString *btnTitle = [NSString stringWithFormat:NSLocalizedStringFromTable(@"active_call_details", @"Vector", nil), room.riotDisplayname];
|
||||
NSString *btnTitle = [NSString stringWithFormat:NSLocalizedStringFromTable(@"active_call_details", @"Vector", nil), room.summary.displayname];
|
||||
[self addCallStatusBar:btnTitle];
|
||||
|
||||
if (completion)
|
||||
|
||||
@@ -22,11 +22,6 @@
|
||||
*/
|
||||
@interface MXRoom (Riot)
|
||||
|
||||
/**
|
||||
The Riot displayname of the room
|
||||
*/
|
||||
@property(nonatomic, readonly) NSString* riotDisplayname;
|
||||
|
||||
/**
|
||||
Tell whether all the notifications are disabled for the room.
|
||||
*/
|
||||
@@ -47,17 +42,6 @@
|
||||
*/
|
||||
@property (nonatomic) id notificationCenterDidUpdateObserver;
|
||||
|
||||
/**
|
||||
Set the room avatar in the dedicated MXKImageView.
|
||||
The vector style implies to use in order :
|
||||
1 - the default avatar if there is one
|
||||
2 - the member avatar for < 3 members rooms
|
||||
3 - the first later of the room name.
|
||||
|
||||
@param mxkImageView the destinated MXKImageView.
|
||||
*/
|
||||
- (void)setRoomAvatarImageIn:(MXKImageView*)mxkImageView;
|
||||
|
||||
/**
|
||||
Update the room tag.
|
||||
|
||||
|
||||
@@ -23,182 +23,6 @@
|
||||
|
||||
@implementation MXRoom (Riot)
|
||||
|
||||
#pragma mark - Room avatar
|
||||
|
||||
- (void)setRoomAvatarImageIn:(MXKImageView*)mxkImageView
|
||||
{
|
||||
NSString* roomAvatarUrl = self.state.avatar;
|
||||
|
||||
if (!roomAvatarUrl)
|
||||
{
|
||||
// If the room has only two members, use the avatar of the second member.
|
||||
NSArray* members = self.state.members;
|
||||
|
||||
if (members.count == 2)
|
||||
{
|
||||
NSString* myUserId = self.mxSession.myUser.userId;
|
||||
|
||||
for (MXRoomMember *roomMember in members)
|
||||
{
|
||||
if (![roomMember.userId isEqualToString:myUserId])
|
||||
{
|
||||
// Use the avatar of this member only if he joined or he is invited.
|
||||
if (MXMembershipJoin == roomMember.membership || MXMembershipInvite == roomMember.membership)
|
||||
{
|
||||
roomAvatarUrl = roomMember.avatarUrl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve the Riot room display name to prepare the default avatar image.
|
||||
// Note: this display name is nil for an "empty room" without display name (We name "empty room" a room in which the current user is the only active member).
|
||||
NSString *avatarDisplayName = self.riotDisplayname;
|
||||
UIImage* avatarImage = [AvatarGenerator generateAvatarForMatrixItem:self.state.roomId withDisplayName:avatarDisplayName];
|
||||
|
||||
if (roomAvatarUrl)
|
||||
{
|
||||
mxkImageView.enableInMemoryCache = YES;
|
||||
|
||||
[mxkImageView setImageURL:[self.mxSession.matrixRestClient urlOfContentThumbnail:roomAvatarUrl toFitViewSize:mxkImageView.frame.size withMethod:MXThumbnailingMethodCrop] withType:nil andImageOrientation:UIImageOrientationUp previewImage:avatarImage];
|
||||
}
|
||||
else
|
||||
{
|
||||
mxkImageView.image = avatarImage;
|
||||
}
|
||||
|
||||
mxkImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
}
|
||||
|
||||
#pragma mark - Room display name
|
||||
// @TODO: May worth to refactor to use MXRoomSummary
|
||||
- (NSString *)riotDisplayname
|
||||
{
|
||||
// this algo is the one defined in
|
||||
// https://github.com/matrix-org/matrix-js-sdk/blob/develop/lib/models/room.js#L617
|
||||
// calculateRoomName(room, userId)
|
||||
|
||||
MXRoomState* roomState = self.state;
|
||||
|
||||
if (roomState.name.length > 0)
|
||||
{
|
||||
return roomState.name;
|
||||
}
|
||||
|
||||
NSString *alias = roomState.canonicalAlias;
|
||||
|
||||
if (!alias)
|
||||
{
|
||||
// For rooms where canonical alias is not defined, we use the 1st alias as a workaround
|
||||
NSArray *aliases = roomState.aliases;
|
||||
|
||||
if (aliases.count)
|
||||
{
|
||||
alias = [aliases[0] copy];
|
||||
}
|
||||
}
|
||||
|
||||
// check if there is non empty alias.
|
||||
if ([alias length] > 0)
|
||||
{
|
||||
return alias;
|
||||
}
|
||||
|
||||
NSString* myUserId = self.mxSession.myUser.userId;
|
||||
|
||||
NSArray* members = roomState.members;
|
||||
NSMutableArray* othersActiveMembers = [[NSMutableArray alloc] init];
|
||||
NSMutableArray* activeMembers = [[NSMutableArray alloc] init];
|
||||
|
||||
for(MXRoomMember* member in members)
|
||||
{
|
||||
if (member.membership != MXMembershipLeave)
|
||||
{
|
||||
if (![member.userId isEqualToString:myUserId])
|
||||
{
|
||||
[othersActiveMembers addObject:member];
|
||||
}
|
||||
|
||||
[activeMembers addObject:member];
|
||||
}
|
||||
}
|
||||
|
||||
// sort the members by their creation (oldest first)
|
||||
othersActiveMembers = [[othersActiveMembers sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
|
||||
|
||||
uint64_t originServerTs1 = 0;
|
||||
uint64_t originServerTs2 = 0;
|
||||
|
||||
MXRoomMember* member1 = (MXRoomMember*)obj1;
|
||||
MXRoomMember* member2 = (MXRoomMember*)obj2;
|
||||
|
||||
if (member1.originalEvent)
|
||||
{
|
||||
originServerTs1 = member1.originalEvent.originServerTs;
|
||||
}
|
||||
|
||||
if (member2.originalEvent)
|
||||
{
|
||||
originServerTs2 = member2.originalEvent.originServerTs;
|
||||
}
|
||||
|
||||
if (originServerTs1 == originServerTs2)
|
||||
{
|
||||
return NSOrderedSame;
|
||||
}
|
||||
else
|
||||
{
|
||||
return originServerTs1 > originServerTs2 ? NSOrderedDescending : NSOrderedAscending;
|
||||
}
|
||||
}] mutableCopy];
|
||||
|
||||
|
||||
NSString* displayName = @"";
|
||||
|
||||
if (othersActiveMembers.count == 0)
|
||||
{
|
||||
if (activeMembers.count == 1)
|
||||
{
|
||||
MXRoomMember* member = [activeMembers objectAtIndex:0];
|
||||
|
||||
if (member.membership == MXMembershipInvite)
|
||||
{
|
||||
if (member.originalEvent.sender)
|
||||
{
|
||||
// extract who invited us to the room
|
||||
displayName = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_displayname_invite_from", @"Vector", nil), [roomState memberName:member.originalEvent.sender]];
|
||||
}
|
||||
else
|
||||
{
|
||||
displayName = NSLocalizedStringFromTable(@"room_displayname_room_invite", @"Vector", nil);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (othersActiveMembers.count == 1)
|
||||
{
|
||||
MXRoomMember* member = [othersActiveMembers objectAtIndex:0];
|
||||
|
||||
displayName = [roomState memberName:member.userId];
|
||||
}
|
||||
else if (othersActiveMembers.count == 2)
|
||||
{
|
||||
MXRoomMember* member1 = [othersActiveMembers objectAtIndex:0];
|
||||
MXRoomMember* member2 = [othersActiveMembers objectAtIndex:1];
|
||||
|
||||
displayName = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_displayname_two_members", @"Vector", nil), [roomState memberName:member1.userId], [roomState memberName:member2.userId]];
|
||||
}
|
||||
else
|
||||
{
|
||||
MXRoomMember* member = [othersActiveMembers objectAtIndex:0];
|
||||
displayName = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_displayname_more_than_two_members", @"Vector", nil), [roomState memberName:member.userId], othersActiveMembers.count - 1];
|
||||
}
|
||||
|
||||
return displayName;
|
||||
}
|
||||
|
||||
#pragma mark - Room tags
|
||||
|
||||
- (void)setRoomTag:(NSString*)tag completion:(void (^)())completion
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright 2017 Vector Creations Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import <MatrixKit/MatrixKit.h>
|
||||
|
||||
/**
|
||||
Define a `MXRoomSummary` category at Riot level.
|
||||
*/
|
||||
@interface MXRoomSummary (Riot)
|
||||
|
||||
/**
|
||||
Set the room avatar in the dedicated MXKImageView.
|
||||
The riot style implies to use in order :
|
||||
1 - the default avatar if there is one
|
||||
2 - the member avatar for < 3 members rooms
|
||||
3 - the first letter of the room name.
|
||||
|
||||
@param mxkImageView the destinated MXKImageView.
|
||||
*/
|
||||
- (void)setRoomAvatarImageIn:(MXKImageView*)mxkImageView;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright 2017 Vector Creations Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import "MXRoomSummary+Riot.h"
|
||||
|
||||
#import "AvatarGenerator.h"
|
||||
|
||||
@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 setImageURL:[self.mxSession.matrixRestClient urlOfContentThumbnail:self.avatar toFitViewSize:mxkImageView.frame.size withMethod:MXThumbnailingMethodCrop] withType:nil andImageOrientation:UIImageOrientationUp previewImage:avatarImage];
|
||||
}
|
||||
else
|
||||
{
|
||||
mxkImageView.image = avatarImage;
|
||||
}
|
||||
|
||||
mxkImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -17,8 +17,6 @@
|
||||
|
||||
#import "RoomPreviewData.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
|
||||
@implementation RoomPreviewData
|
||||
|
||||
- (instancetype)initWithRoomId:(NSString *)roomId andSession:(MXSession *)mxSession
|
||||
@@ -88,8 +86,8 @@
|
||||
[_roomDataSource finalizeInitialization];
|
||||
_roomDataSource.markTimelineInitialEvent = YES;
|
||||
|
||||
_roomName = peekingRoom.riotDisplayname;
|
||||
_roomAvatarUrl = peekingRoom.state.avatar;
|
||||
_roomName = peekingRoom.summary.displayname;
|
||||
_roomAvatarUrl = peekingRoom.summary.avatar;
|
||||
|
||||
_roomTopic = [MXTools stripNewlineCharacters:peekingRoom.state.topic];;
|
||||
_roomAliases = peekingRoom.state.aliases;
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
- (void)update
|
||||
{
|
||||
[super update];
|
||||
roomDisplayname = self.roomSummary.room.riotDisplayname;
|
||||
roomDisplayname = self.roomSummary.displayname;
|
||||
if (!roomDisplayname.length)
|
||||
{
|
||||
roomDisplayname = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
|
||||
|
||||
@@ -1487,7 +1487,7 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
|
||||
|
||||
NSString* tagOrder = [room.mxSession tagOrderToBeAtIndex:newPath.row from:oldPos withTag:dstRoomTag];
|
||||
|
||||
NSLog(@"[RecentsDataSource] Update the room %@ [%@] tag from %@ to %@ with tag order %@", room.state.roomId, room.riotDisplayname, oldRoomTag, dstRoomTag, tagOrder);
|
||||
NSLog(@"[RecentsDataSource] Update the room %@ [%@] tag from %@ to %@ with tag order %@", room.state.roomId, room.summary.displayname, oldRoomTag, dstRoomTag, tagOrder);
|
||||
|
||||
[room replaceTag:oldRoomTag
|
||||
byTag:dstRoomTag
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
|
||||
#import "FilesSearchCellData.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
|
||||
@implementation FilesSearchCellData
|
||||
@synthesize roomId, senderDisplayName;
|
||||
@synthesize searchResult, title, message, date, shouldShowRoomDisplayName, roomDisplayName, attachment, isAttachmentWithThumbnail, attachmentIcon;
|
||||
@@ -82,7 +80,7 @@
|
||||
MXRoom *room = [searchDataSource.mxSession roomWithRoomId:roomId];
|
||||
if (room)
|
||||
{
|
||||
roomDisplayName = room.riotDisplayname;
|
||||
roomDisplayName = room.summary.displayname;
|
||||
if (!roomDisplayName.length)
|
||||
{
|
||||
roomDisplayName = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
|
||||
|
||||
@@ -190,6 +190,225 @@
|
||||
return senderAvatarUrl;
|
||||
}
|
||||
|
||||
#pragma mark - MXRoomSummaryUpdating
|
||||
|
||||
- (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary withStateEvents:(NSArray<MXEvent *> *)stateEvents
|
||||
{
|
||||
BOOL ret = [super session:session updateRoomSummary:summary withStateEvents:stateEvents];
|
||||
|
||||
// Check whether the room display name and/or the room avatar url should be updated at Riot level.
|
||||
NSString *riotRoomDisplayName;
|
||||
NSString *riotRoomAvatarURL;
|
||||
|
||||
for (MXEvent *event in stateEvents)
|
||||
{
|
||||
switch (event.eventType)
|
||||
{
|
||||
case MXEventTypeRoomName:
|
||||
case MXEventTypeRoomAliases:
|
||||
case MXEventTypeRoomCanonicalAlias:
|
||||
{
|
||||
if (!riotRoomDisplayName.length)
|
||||
{
|
||||
riotRoomDisplayName = [self riotRoomDisplayNameFromRoomState:summary.room.state];
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MXEventTypeRoomMember:
|
||||
{
|
||||
if (!riotRoomDisplayName.length)
|
||||
{
|
||||
riotRoomDisplayName = [self riotRoomDisplayNameFromRoomState:summary.room.state];
|
||||
}
|
||||
// Do not break here to check avatar url too.
|
||||
}
|
||||
case MXEventTypeRoomAvatar:
|
||||
{
|
||||
if (!riotRoomAvatarURL.length)
|
||||
{
|
||||
riotRoomAvatarURL = [self riotRoomAvatarURLFromRoomState:summary.room.state];
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (riotRoomDisplayName.length && ![summary.displayname isEqualToString:riotRoomDisplayName])
|
||||
{
|
||||
summary.displayname = riotRoomDisplayName;
|
||||
ret = YES;
|
||||
}
|
||||
|
||||
if (riotRoomAvatarURL.length && ![summary.avatar isEqualToString:riotRoomAvatarURL])
|
||||
{
|
||||
summary.avatar = riotRoomAvatarURL;
|
||||
ret = YES;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#pragma mark - Riot room display name
|
||||
|
||||
- (NSString *)riotRoomDisplayNameFromRoomState:(MXRoomState *)roomState
|
||||
{
|
||||
// this algo is the one defined in
|
||||
// https://github.com/matrix-org/matrix-js-sdk/blob/develop/lib/models/room.js#L617
|
||||
// calculateRoomName(room, userId)
|
||||
|
||||
// This display name is @"" for an "empty room" without display name (We name "empty room" a room in which the current user is the only active member).
|
||||
|
||||
if (roomState.name.length > 0)
|
||||
{
|
||||
return roomState.name;
|
||||
}
|
||||
|
||||
NSString *alias = roomState.canonicalAlias;
|
||||
|
||||
if (!alias)
|
||||
{
|
||||
// For rooms where canonical alias is not defined, we use the 1st alias as a workaround
|
||||
NSArray *aliases = roomState.aliases;
|
||||
|
||||
if (aliases.count)
|
||||
{
|
||||
alias = [aliases[0] copy];
|
||||
}
|
||||
}
|
||||
|
||||
// check if there is non empty alias.
|
||||
if ([alias length] > 0)
|
||||
{
|
||||
return alias;
|
||||
}
|
||||
|
||||
NSString* myUserId = mxSession.myUser.userId;
|
||||
|
||||
NSArray* members = roomState.members;
|
||||
NSMutableArray* othersActiveMembers = [[NSMutableArray alloc] init];
|
||||
NSMutableArray* activeMembers = [[NSMutableArray alloc] init];
|
||||
|
||||
for(MXRoomMember* member in members)
|
||||
{
|
||||
if (member.membership != MXMembershipLeave)
|
||||
{
|
||||
if (![member.userId isEqualToString:myUserId])
|
||||
{
|
||||
[othersActiveMembers addObject:member];
|
||||
}
|
||||
|
||||
[activeMembers addObject:member];
|
||||
}
|
||||
}
|
||||
|
||||
// sort the members by their creation (oldest first)
|
||||
othersActiveMembers = [[othersActiveMembers sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
|
||||
|
||||
uint64_t originServerTs1 = 0;
|
||||
uint64_t originServerTs2 = 0;
|
||||
|
||||
MXRoomMember* member1 = (MXRoomMember*)obj1;
|
||||
MXRoomMember* member2 = (MXRoomMember*)obj2;
|
||||
|
||||
if (member1.originalEvent)
|
||||
{
|
||||
originServerTs1 = member1.originalEvent.originServerTs;
|
||||
}
|
||||
|
||||
if (member2.originalEvent)
|
||||
{
|
||||
originServerTs2 = member2.originalEvent.originServerTs;
|
||||
}
|
||||
|
||||
if (originServerTs1 == originServerTs2)
|
||||
{
|
||||
return NSOrderedSame;
|
||||
}
|
||||
else
|
||||
{
|
||||
return originServerTs1 > originServerTs2 ? NSOrderedDescending : NSOrderedAscending;
|
||||
}
|
||||
}] mutableCopy];
|
||||
|
||||
|
||||
NSString* displayName = @"";
|
||||
|
||||
if (othersActiveMembers.count == 0)
|
||||
{
|
||||
if (activeMembers.count == 1)
|
||||
{
|
||||
MXRoomMember* member = [activeMembers objectAtIndex:0];
|
||||
|
||||
if (member.membership == MXMembershipInvite)
|
||||
{
|
||||
if (member.originalEvent.sender)
|
||||
{
|
||||
// extract who invited us to the room
|
||||
displayName = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_displayname_invite_from", @"Vector", nil), [roomState memberName:member.originalEvent.sender]];
|
||||
}
|
||||
else
|
||||
{
|
||||
displayName = NSLocalizedStringFromTable(@"room_displayname_room_invite", @"Vector", nil);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (othersActiveMembers.count == 1)
|
||||
{
|
||||
MXRoomMember* member = [othersActiveMembers objectAtIndex:0];
|
||||
|
||||
displayName = [roomState memberName:member.userId];
|
||||
}
|
||||
else if (othersActiveMembers.count == 2)
|
||||
{
|
||||
MXRoomMember* member1 = [othersActiveMembers objectAtIndex:0];
|
||||
MXRoomMember* member2 = [othersActiveMembers objectAtIndex:1];
|
||||
|
||||
displayName = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_displayname_two_members", @"Vector", nil), [roomState memberName:member1.userId], [roomState memberName:member2.userId]];
|
||||
}
|
||||
else
|
||||
{
|
||||
MXRoomMember* member = [othersActiveMembers objectAtIndex:0];
|
||||
displayName = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_displayname_more_than_two_members", @"Vector", nil), [roomState memberName:member.userId], othersActiveMembers.count - 1];
|
||||
}
|
||||
|
||||
return displayName;
|
||||
}
|
||||
|
||||
#pragma mark - Riot room avatar url
|
||||
|
||||
- (NSString *)riotRoomAvatarURLFromRoomState:(MXRoomState *)roomState
|
||||
{
|
||||
NSString* roomAvatarUrl = roomState.avatar;
|
||||
|
||||
if (!roomAvatarUrl)
|
||||
{
|
||||
// If the room has only two members, use the avatar of the second member.
|
||||
NSArray* members = roomState.members;
|
||||
|
||||
if (members.count == 2)
|
||||
{
|
||||
NSString* myUserId = mxSession.myUser.userId;
|
||||
|
||||
for (MXRoomMember *roomMember in members)
|
||||
{
|
||||
if (![roomMember.userId isEqualToString:myUserId])
|
||||
{
|
||||
// Use the avatar of this member only if he joined or he is invited.
|
||||
if (MXMembershipJoin == roomMember.membership || MXMembershipInvite == roomMember.membership)
|
||||
{
|
||||
roomAvatarUrl = roomMember.avatarUrl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return roomAvatarUrl;
|
||||
}
|
||||
|
||||
#pragma mark - Timestamp formatting
|
||||
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
|
||||
#import "AvatarGenerator.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
|
||||
#import "UsersDevicesViewController.h"
|
||||
|
||||
#import "RiotNavigationController.h"
|
||||
@@ -359,7 +357,7 @@
|
||||
}
|
||||
else if (self.mxCall.room)
|
||||
{
|
||||
return [AvatarGenerator generateAvatarForMatrixItem:self.mxCall.room.roomId withDisplayName:self.mxCall.room.riotDisplayname size:self.callerImageViewWidthConstraint.constant andFontSize:fontSize];
|
||||
return [AvatarGenerator generateAvatarForMatrixItem:self.mxCall.room.roomId withDisplayName:self.mxCall.room.summary.displayname size:self.callerImageViewWidthConstraint.constant andFontSize:fontSize];
|
||||
}
|
||||
|
||||
return [UIImage imageNamed:@"placeholder"];
|
||||
@@ -388,7 +386,7 @@
|
||||
}
|
||||
else if (self.mxCall.isConferenceCall)
|
||||
{
|
||||
peerDisplayName = self.mxCall.room.riotDisplayname;
|
||||
peerDisplayName = self.mxCall.room.summary.displayname;
|
||||
peerAvatarURL = self.mxCall.room.state.avatar;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#import "Tools.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
#import "MXRoomSummary+Riot.h"
|
||||
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@@ -1998,7 +1999,7 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
|
||||
}
|
||||
else
|
||||
{
|
||||
[mxRoom setRoomAvatarImageIn:roomPhotoCell.mxkImageView];
|
||||
[mxRoom.summary setRoomAvatarImageIn:roomPhotoCell.mxkImageView];
|
||||
|
||||
roomPhotoCell.userInteractionEnabled = (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomAvatar]);
|
||||
roomPhotoCell.mxkImageView.alpha = roomPhotoCell.userInteractionEnabled ? 1.0f : 0.5f;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#import "RiotDesignValues.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
#import "MXRoomSummary+Riot.h"
|
||||
|
||||
@implementation RecentTableViewCell
|
||||
|
||||
@@ -143,7 +143,7 @@
|
||||
|
||||
self.encryptedRoomIcon.hidden = !roomCellData.roomSummary.isEncrypted;
|
||||
|
||||
[roomCellData.roomSummary.room setRoomAvatarImageIn:self.roomAvatar];
|
||||
[roomCellData.roomSummary setRoomAvatarImageIn:self.roomAvatar];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#import "RiotDesignValues.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
#import "MXRoomSummary+Riot.h"
|
||||
|
||||
#import "MXTools.h"
|
||||
|
||||
@@ -171,7 +171,7 @@
|
||||
|
||||
self.encryptedRoomIcon.hidden = !roomCellData.roomSummary.isEncrypted;
|
||||
|
||||
[roomCellData.roomSummary.room setRoomAvatarImageIn:self.roomAvatar];
|
||||
[roomCellData.roomSummary setRoomAvatarImageIn:self.roomAvatar];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#import "RoomTableViewCell.h"
|
||||
|
||||
#import "RiotDesignValues.h"
|
||||
#import "MXRoom+Riot.h"
|
||||
#import "MXRoomSummary+Riot.h"
|
||||
|
||||
@implementation RoomTableViewCell
|
||||
|
||||
@@ -50,9 +50,9 @@
|
||||
|
||||
- (void)render:(MXRoom *)room
|
||||
{
|
||||
[room setRoomAvatarImageIn:self.avatarImageView];
|
||||
[room.summary setRoomAvatarImageIn:self.avatarImageView];
|
||||
|
||||
self.titleLabel.text = room.riotDisplayname;
|
||||
self.titleLabel.text = room.summary.displayname;
|
||||
|
||||
self.directRoomBorderView.hidden = !room.isDirect;
|
||||
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
#import "RiotDesignValues.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
|
||||
@implementation ExpandedRoomTitleView
|
||||
|
||||
+ (UINib *)nib
|
||||
@@ -38,7 +36,7 @@
|
||||
{
|
||||
[super customizeViewRendering];
|
||||
|
||||
self.displayNameTextField.textColor = (self.mxRoom.riotDisplayname.length ? kRiotPrimaryTextColor : kRiotSecondaryTextColor);
|
||||
self.displayNameTextField.textColor = (self.mxRoom.summary.displayname.length ? kRiotPrimaryTextColor : kRiotSecondaryTextColor);
|
||||
self.roomTopic.textColor = kRiotTopicTextColor;
|
||||
self.roomMembers.textColor = kRiotColorGreen;
|
||||
}
|
||||
@@ -49,7 +47,7 @@
|
||||
|
||||
if (self.mxRoom)
|
||||
{
|
||||
self.displayNameTextField.text = self.mxRoom.riotDisplayname;
|
||||
self.displayNameTextField.text = self.mxRoom.summary.displayname;
|
||||
if (!self.displayNameTextField.text.length)
|
||||
{
|
||||
self.displayNameTextField.text = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
#import "RiotDesignValues.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
|
||||
@implementation PreviewRoomTitleView
|
||||
|
||||
+ (UINib *)nib
|
||||
@@ -64,7 +62,7 @@
|
||||
self.backgroundColor = kRiotPrimaryBgColor;
|
||||
self.mainHeaderBackground.backgroundColor = kRiotSecondaryBgColor;
|
||||
|
||||
self.displayNameTextField.textColor = (self.mxRoom.riotDisplayname.length ? kRiotPrimaryTextColor : kRiotSecondaryTextColor);
|
||||
self.displayNameTextField.textColor = (self.mxRoom.summary.displayname.length ? kRiotPrimaryTextColor : kRiotSecondaryTextColor);
|
||||
|
||||
self.roomTopic.textColor = kRiotTopicTextColor;
|
||||
self.roomTopic.numberOfLines = 0;
|
||||
@@ -145,7 +143,7 @@
|
||||
else if (self.mxRoom)
|
||||
{
|
||||
// The user is here invited to join a room (This invitation has been received from server sync)
|
||||
self.displayNameTextField.text = self.mxRoom.riotDisplayname;
|
||||
self.displayNameTextField.text = self.mxRoom.summary.displayname;
|
||||
if (!self.displayNameTextField.text.length)
|
||||
{
|
||||
self.displayNameTextField.text = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#import "RiotDesignValues.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
#import "MXRoomSummary+Riot.h"
|
||||
|
||||
@implementation RoomAvatarTitleView
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
|
||||
if (self.mxRoom)
|
||||
{
|
||||
[self.mxRoom setRoomAvatarImageIn:self.roomAvatar];
|
||||
[self.mxRoom.summary setRoomAvatarImageIn:self.roomAvatar];
|
||||
}
|
||||
else if (self.roomAvatarURL)
|
||||
{
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
#import "RiotDesignValues.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
|
||||
@implementation RoomTitleView
|
||||
|
||||
+ (UINib *)nib
|
||||
@@ -111,7 +109,7 @@
|
||||
{
|
||||
[super customizeViewRendering];
|
||||
|
||||
self.displayNameTextField.textColor = (self.mxRoom.riotDisplayname.length ? kRiotPrimaryTextColor : kRiotSecondaryTextColor);
|
||||
self.displayNameTextField.textColor = (self.mxRoom.summary.displayname.length ? kRiotPrimaryTextColor : kRiotSecondaryTextColor);
|
||||
}
|
||||
|
||||
- (void)setRoomPreviewData:(RoomPreviewData *)roomPreviewData
|
||||
@@ -132,7 +130,7 @@
|
||||
}
|
||||
else if (self.mxRoom)
|
||||
{
|
||||
self.displayNameTextField.text = self.mxRoom.riotDisplayname;
|
||||
self.displayNameTextField.text = self.mxRoom.summary.displayname;
|
||||
if (!self.displayNameTextField.text.length)
|
||||
{
|
||||
self.displayNameTextField.text = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
#import "RiotDesignValues.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
|
||||
@implementation SimpleRoomTitleView
|
||||
|
||||
+ (UINib *)nib
|
||||
@@ -70,7 +68,7 @@
|
||||
{
|
||||
[super customizeViewRendering];
|
||||
|
||||
self.displayNameTextField.textColor = (self.mxRoom.riotDisplayname.length ? kRiotPrimaryTextColor : kRiotSecondaryTextColor);
|
||||
self.displayNameTextField.textColor = (self.mxRoom.summary.displayname.length ? kRiotPrimaryTextColor : kRiotSecondaryTextColor);
|
||||
}
|
||||
|
||||
- (void)refreshDisplay
|
||||
@@ -79,7 +77,7 @@
|
||||
|
||||
if (self.mxRoom)
|
||||
{
|
||||
self.displayNameTextField.text = self.mxRoom.riotDisplayname;
|
||||
self.displayNameTextField.text = self.mxRoom.summary.displayname;
|
||||
if (!self.displayNameTextField.text.length)
|
||||
{
|
||||
self.displayNameTextField.text = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
#import "RiotDesignValues.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
|
||||
@implementation MessagesSearchResultAttachmentBubbleCell
|
||||
|
||||
- (void)customizeTableViewCellRendering
|
||||
@@ -43,7 +41,7 @@
|
||||
MXRoom* room = [bubbleData.mxSession roomWithRoomId:bubbleData.roomId];
|
||||
if (room)
|
||||
{
|
||||
self.roomNameLabel.text = room.riotDisplayname;
|
||||
self.roomNameLabel.text = room.summary.displayname;
|
||||
if (!self.roomNameLabel.text.length)
|
||||
{
|
||||
self.roomNameLabel.text = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
#import "RiotDesignValues.h"
|
||||
|
||||
#import "MXRoom+Riot.h"
|
||||
|
||||
@implementation MessagesSearchResultTextMsgBubbleCell
|
||||
|
||||
- (void)customizeTableViewCellRendering
|
||||
@@ -43,7 +41,7 @@
|
||||
MXRoom* room = [bubbleData.mxSession roomWithRoomId:bubbleData.roomId];
|
||||
if (room)
|
||||
{
|
||||
self.roomNameLabel.text = room.riotDisplayname;
|
||||
self.roomNameLabel.text = room.summary.displayname;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -130,7 +130,8 @@
|
||||
|
||||
- (void)showShareAlertForRoomPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NSString *receipantName = [self.dataSource getRoomAtIndexPath:indexPath].riotDisplayname;
|
||||
// @TODO: the room should be instanciated here (only the room summary should be available from dataSource).
|
||||
NSString *receipantName = [self.dataSource getRoomAtIndexPath:indexPath].summary.displayname;
|
||||
if (!receipantName.length)
|
||||
{
|
||||
receipantName = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil);
|
||||
|
||||
Reference in New Issue
Block a user