mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-18 05:33:32 +02:00
room_photo_selection
-> update to have the same room displayname as the webclient.
This commit is contained in:
@@ -27,10 +27,15 @@
|
||||
@property(nonatomic, readonly) BOOL areRoomNotificationsMuted;
|
||||
|
||||
/**
|
||||
Returns YES if the oneself user is a super user i.e. he is allowed to modify the
|
||||
Returns YES if the oneself user is a super user i.e. he is allowed to modify the room members and so on.
|
||||
*/
|
||||
@property(nonatomic, readonly) BOOL isSuperUser;
|
||||
|
||||
/**
|
||||
Returns the vector displayname.
|
||||
*/
|
||||
@property(nonatomic, readonly) NSString* vectorDisplayname;
|
||||
|
||||
/**
|
||||
Toggle a room rule notifications.
|
||||
|
||||
|
||||
@@ -240,4 +240,133 @@
|
||||
mxkImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
}
|
||||
|
||||
- (NSString *)vectorDisplayname
|
||||
{
|
||||
// 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];
|
||||
}
|
||||
}
|
||||
|
||||
if (alias)
|
||||
{
|
||||
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 = @"";
|
||||
|
||||
// TODO: Localisation
|
||||
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
|
||||
{
|
||||
displayName = myUserId;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright 2015 OpenMarket 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 <Foundation/Foundation.h>
|
||||
#import <MatrixSDK/MatrixSDK.h>
|
||||
|
||||
#import "MXKRecentCellData.h"
|
||||
/**
|
||||
`RecentCellData` is Vector cuustomized MXKRecentCellData` cell.
|
||||
*/
|
||||
@interface RecentCellData : MXKRecentCellData
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright 2015 OpenMarket 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 "RecentCellData.h"
|
||||
|
||||
#import "MXRoom+Vector.h"
|
||||
|
||||
@implementation RecentCellData
|
||||
// trick to hide the mother class property as it is readonly one.
|
||||
// self.roomDisplayname returns this value instead of the mother class.
|
||||
@synthesize roomDisplayname;
|
||||
|
||||
- (void)update
|
||||
{
|
||||
[super update];
|
||||
roomDisplayname = self.roomDataSource.room.vectorDisplayname;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
#import "MXRoom+Vector.h"
|
||||
|
||||
#import "RecentCellData.h"
|
||||
|
||||
@interface RecentsDataSource()
|
||||
{
|
||||
NSMutableArray* invitesCellDataArray;
|
||||
@@ -63,10 +65,15 @@
|
||||
sectionsCount = 0;
|
||||
|
||||
roomTagsListenerByUserId = [[NSMutableDictionary alloc] init];
|
||||
|
||||
// Set default data and view classes
|
||||
[self registerCellDataClass:RecentCellData.class forCellIdentifier:kMXKRecentCellIdentifier];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)removeMatrixSession:(MXSession*)matrixSession
|
||||
{
|
||||
[super removeMatrixSession:matrixSession];
|
||||
|
||||
Reference in New Issue
Block a user