merged element-ios 1.10.5 into 4409_basis_update_1_10_5

This commit is contained in:
Arnfried Griesert
2023-03-16 12:19:26 +01:00
168 changed files with 2451 additions and 850 deletions
@@ -36,6 +36,9 @@
UIBarButtonItem *cancelBarButtonItem;
UIBarButtonItem *createBarButtonItem;
// SearchBar text
NSString *currentSearch;
// HTTP Request
MXHTTPOperation *roomCreationRequest;
@@ -46,10 +49,13 @@
@property (weak, nonatomic) IBOutlet UIView *searchBarHeader;
@property (weak, nonatomic) IBOutlet UISearchBar *searchBarView;
@property (weak, nonatomic) IBOutlet UIView *searchBarHeaderBorder;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *searchBarHeaderHeightConstraint;
@property (nonatomic, strong) InviteFriendsPresenter *inviteFriendsPresenter;
@property (nonatomic, weak) InviteFriendsHeaderView *inviteFriendsHeaderView;
@property (nonatomic, weak) UIView *onlyOneEmailInvitationView;
@end
@implementation StartChatViewController
@@ -131,6 +137,11 @@
- (void)setupInviteFriendsHeaderView
{
if (self.inviteFriendsHeaderView)
{
return;
}
if (!RiotSettings.shared.allowInviteExernalUsers)
{
self.contactsTableView.tableHeaderView = nil;
@@ -157,7 +168,7 @@
[self setupInviteFriendsHeaderView];
}
}
else
else if (self.inviteFriendsHeaderView != nil)
{
self.contactsTableView.tableHeaderView = nil;
}
@@ -309,6 +320,104 @@
contactsDataSource.ignoredContactsByMatrixId[self.mainSession.myUser.userId] = userContact;
}
}
// hide the search bar if a participant is already invited by email
BOOL hideSearchBar = [self participantsAlreadyContainAnEmail];
self.searchBarHeader.alpha = hideSearchBar ? 0.0f : 1.0f;
self.searchBarHeaderHeightConstraint.constant = hideSearchBar ? 0.0f : 50.0f;
[UIView animateWithDuration:0.2f animations:^{
[self.view layoutIfNeeded];
}];
}
- (BOOL)participantsAlreadyContainAnEmail
{
for (MXKContact* participant in participants)
{
// if it is not a matrix contact or a local contact with a MatrixID
if (participant.matrixIdentifiers.count == 0 && ![MXTools isMatrixUserIdentifier:participant.displayName])
{
return YES;
}
}
return NO;
}
- (BOOL)canAddParticipant: (MXKContact*) contact
{
if (!contact)
{
return YES;
}
// The following rules will be applied only if the resulting room is going to be encrypted
if (![self.mainSession vc_homeserverConfiguration].encryption.isE2EEByDefaultEnabled)
{
return YES;
}
// If we have already invited an email, we cannot add another participant
if ([self participantsAlreadyContainAnEmail])
{
return NO;
}
// if it is not a matrix contact, nor a local contact with a MatrixID, and if there is already at least one participant, another participant cannot be added.
if ((contact.matrixIdentifiers.count == 0 && ![MXTools isMatrixUserIdentifier:contact.displayName]) && participants.count > 0)
{
return NO;
}
// Otherwise, we should be able to add this participant
return YES;
}
- (void)showAllowOnlyOneInvitByEmailAllowedHeaderView:(BOOL)visible
{
if (visible)
{
if (!self.onlyOneEmailInvitationView)
{
UIView *headerView = [[UIView alloc] initWithFrame: CGRectZero];
headerView.translatesAutoresizingMaskIntoConstraints = NO;
UILabel *label = [[UILabel alloc] initWithFrame: CGRectZero];
label.numberOfLines = 0;
label.textColor = ThemeService.shared.theme.textSecondaryColor;
label.font = [UIFont systemFontOfSize:14 weight:UIFontWeightLight];
label.adjustsFontSizeToFitWidth = YES;
label.text = VectorL10n.roomCreationOnlyOneEmailInvite;
label.translatesAutoresizingMaskIntoConstraints = NO;
[headerView addSubview:label];
[NSLayoutConstraint activateConstraints:@[
[label.leadingAnchor constraintEqualToAnchor:headerView.leadingAnchor constant:16],
[label.trailingAnchor constraintEqualToAnchor:headerView.trailingAnchor constant:-16],
[label.topAnchor constraintEqualToAnchor:headerView.topAnchor constant:8],
[label.bottomAnchor constraintEqualToAnchor:headerView.bottomAnchor constant:-8],
]];
[label setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
[headerView setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
self.onlyOneEmailInvitationView = headerView;
self.contactsTableView.tableHeaderView = self.onlyOneEmailInvitationView;
[NSLayoutConstraint activateConstraints:@[
[headerView.leadingAnchor constraintEqualToAnchor:self.contactsTableView.safeAreaLayoutGuide.leadingAnchor],
[headerView.trailingAnchor constraintEqualToAnchor:self.contactsTableView.safeAreaLayoutGuide.trailingAnchor]
]];
[self.contactsTableView.tableHeaderView layoutIfNeeded];
}
}
else if (self.onlyOneEmailInvitationView != nil)
{
if (self.contactsTableView.tableHeaderView == self.onlyOneEmailInvitationView)
{
self.contactsTableView.tableHeaderView = nil;
}
self.onlyOneEmailInvitationView = nil;
}
}
- (void)showInviteFriendsFromSourceView:(UIView*)sourceView
@@ -372,6 +481,14 @@
if (_isAddParticipantSearchBarEditing)
{
cell = [contactsDataSource tableView:tableView cellForRowAtIndexPath:indexPath];
MXKContact* contact = [contactsDataSource contactAtIndexPath:indexPath];
if (![self canAddParticipant:contact])
{
// Prevent to add it
cell.contentView.alpha = 0.5;
cell.userInteractionEnabled = NO;
cell.accessoryView = nil;
}
}
else if (indexPath.section == participantsSection)
{
@@ -538,7 +655,7 @@
// Prepare the invited participant data
NSMutableArray *inviteArray = [NSMutableArray array];
NSMutableArray *invite3PIDArray = [NSMutableArray array];
NSMutableArray<MXInvite3PID *> *invite3PIDArray = [NSMutableArray array];
// Check whether some users must be invited
for (MXKContact *contact in participants)
@@ -599,7 +716,7 @@
// Is it a direct chat?
BOOL isDirect = ((inviteArray.count + invite3PIDArray.count == 1) ? YES : NO);
// In case of a direct chat with only one user id, we open the first available direct chat
// or creates a new one (if it doesn't exist).
if (isDirect && inviteArray.count)
@@ -611,6 +728,19 @@
}
else
{
// We don't want to create a new direct room for a 3rd party invite if we already have one
NSString *first3rdPartyInvitee = invite3PIDArray.firstObject.address;
if (isDirect && first3rdPartyInvitee)
{
MXRoom *existingRoom = [self.mainSession directJoinedRoomWithUserId:first3rdPartyInvitee];
if (existingRoom)
{
[self stopActivityIndicator];
[[AppDelegate theDelegate] showRoom:existingRoom.roomId andEventId:nil withMatrixSession:self.mainSession];
return;
}
}
// Ensure direct chat are created with equal ops on both sides (the trusted_private_chat preset)
MXRoomPreset preset = (isDirect ? kMXRoomPresetTrustedPrivateChat : nil);
@@ -640,7 +770,7 @@
roomCreationParameters.isDirect = isDirect;
roomCreationParameters.preset = preset;
if (canEnableE2E && roomCreationParameters.invite3PIDArray == nil)
if (canEnableE2E)
{
roomCreationParameters.initialStateEvents = @[
[MXRoomCreationParameters initialStateEventForEncryptionWithAlgorithm:kMXCryptoMegolmAlgorithm
@@ -649,6 +779,9 @@
self->roomCreationRequest = [self.mainSession createRoomWithParameters:roomCreationParameters success:^(MXRoom *room) {
// Update the room summary
[room.summary resetRoomStateData];
self->roomCreationRequest = nil;
[self stopActivityIndicator];
@@ -713,7 +846,29 @@
[contactsDataSource searchWithPattern:searchText forceReset:NO];
}
// $$$ 1.10.5 has the floowing lines
// self->currentSearch = searchText;
// if (searchText != nil && searchText.length > 0)
// {
// MXKContact *contact = nil;
// if ([MXTools isMatrixUserIdentifier:searchText])
// {
// contact = [[MXKContact alloc] initMatrixContactWithDisplayName:searchText andMatrixID:searchText];
//
// }
// else if ([MXTools isEmailAddress:searchText])
// {
// contact = [[MXKContact alloc] initContactWithDisplayName:searchText emails:nil phoneNumbers:nil andThumbnail:nil];
// }
//
// [self showAllowOnlyOneInvitByEmailAllowedHeaderView: ![self canAddParticipant:contact]];
// }
// else
// {
// [self showAllowOnlyOneInvitByEmailAllowedHeaderView:NO];
// }
[contactsDataSource searchWithPattern:searchText forceReset:NO];
self.contactsAreFilteredWithSearch = searchText.length ? YES : NO;
}
@@ -728,6 +883,7 @@
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
searchBar.text = nil;
self->currentSearch = nil;
self.isAddParticipantSearchBarEditing = NO;
// Reset filtering
@@ -735,6 +891,8 @@
// Leave search
[searchBar resignFirstResponder];
[self showAllowOnlyOneInvitByEmailAllowedHeaderView:NO];
}
#pragma mark - ContactsTableViewControllerDelegate
@@ -773,14 +931,14 @@
}
}
if (contact)
if ([self canAddParticipant:contact])
{
// Update here the mutable list of participants
[participants addObject:contact];
// Refresh display by leaving search session
[self searchBarCancelButtonClicked:_searchBarView];
}
// Refresh display by leaving search session
[self searchBarCancelButtonClicked:_searchBarView];
}
#pragma mark - InviteFriendsHeaderViewDelegate