Merge develop into element_3836

This commit is contained in:
SBiOSoftWhare
2020-11-30 17:54:16 +01:00
16 changed files with 379 additions and 105 deletions
@@ -153,7 +153,7 @@
}];
self.recentsSearchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.recentsSearchBar.placeholder = NSLocalizedStringFromTable(@"search_default_placeholder", @"Vector", nil);
self.recentsSearchBar.placeholder = NSLocalizedStringFromTable(@"search_default_placeholder", @"Vector", nil);
// Observe user interface theme change.
kThemeServiceDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kThemeServiceDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
@@ -454,6 +454,79 @@
}
}
- (void)joinRoom:(MXRoom*)room completion:(void(^)(BOOL succeed))completion
{
[room join:^{
// `recentsTableView` will be reloaded `roomChangeMembershipStateDataSourceDidChangeRoomMembershipState` function
if (completion)
{
completion(YES);
}
} failure:^(NSError * _Nonnull error) {
NSLog(@"[RecentsViewController] Failed to join an invited room (%@)", room.roomId);
[self presentRoomJoinFailedAlertForError:error completion:^{
if (completion)
{
completion(NO);
}
}];
}];
}
- (void)leaveRoom:(MXRoom*)room completion:(void(^)(BOOL succeed))completion
{
// Decline the invitation
[room leave:^{
// `recentsTableView` will be reloaded `roomChangeMembershipStateDataSourceDidChangeRoomMembershipState` function
if (completion)
{
completion(YES);
}
} failure:^(NSError * _Nonnull error) {
NSLog(@"[RecentsViewController] Failed to reject an invited room (%@)", room.roomId);
[[AppDelegate theDelegate] showErrorAsAlert:error];
if (completion)
{
completion(NO);
}
}];
}
- (void)presentRoomJoinFailedAlertForError:(NSError*)error completion:(void(^)(void))completion
{
MXWeakify(self);
NSString *msg = [error.userInfo valueForKey:NSLocalizedDescriptionKey];
if ([msg isEqualToString:@"No known servers"])
{
// minging kludge until https://matrix.org/jira/browse/SYN-678 is fixed
// 'Error when trying to join an empty room should be more explicit'
msg = [NSBundle mxk_localizedStringForKey:@"room_error_join_failed_empty_room"];
}
[self->currentAlert dismissViewControllerAnimated:NO completion:nil];
self->currentAlert = [UIAlertController alertControllerWithTitle:[NSBundle mxk_localizedStringForKey:@"room_error_join_failed_title"] message:msg preferredStyle:UIAlertControllerStyleAlert];
[self->currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
MXStrongifyAndReturnIfNil(self);
self->currentAlert = nil;
if (completion)
{
completion();
}
}]];
[self presentViewController:self->currentAlert animated:YES completion:nil];
}
#pragma mark - Sticky Headers
- (void)setEnableStickyHeaders:(BOOL)enableStickyHeaders
@@ -822,23 +895,23 @@
// Display the room preview
[self dispayRoomWithRoomId:invitedRoom.roomId inMatrixSession:invitedRoom.mxSession];
}
else if ([actionIdentifier isEqualToString:kInviteRecentTableViewCellDeclineButtonPressed])
else if ([actionIdentifier isEqualToString:kInviteRecentTableViewCellAcceptButtonPressed])
{
// Retrieve the invited room
MXRoom *invitedRoom = userInfo[kInviteRecentTableViewCellRoomKey];
// Accept invitation
[self joinRoom:invitedRoom completion:nil];
}
else if ([actionIdentifier isEqualToString:kInviteRecentTableViewCellDeclineButtonPressed])
{
// Retrieve the invited room
MXRoom *invitedRoom = userInfo[kInviteRecentTableViewCellRoomKey];
[self cancelEditionMode:isRefreshPending];
// Decline the invitation
[invitedRoom leave:^{
[self.recentsTableView reloadData];
} failure:^(NSError *error) {
NSLog(@"[RecentsViewController] Failed to reject an invited room (%@)", invitedRoom.roomId);
}];
[self leaveRoom:invitedRoom completion:nil];
}
else
{
@@ -1280,8 +1353,21 @@
if ([cell isKindOfClass:[InviteRecentTableViewCell class]])
{
// hide the selection
[tableView deselectRowAtIndexPath:indexPath animated:NO];
id<MXKRecentCellDataStoring> cellData = [self.dataSource cellDataAtIndexPath:indexPath];
// Retrieve the invited room
MXRoom* invitedRoom = cellData.roomSummary.room;
// Check if can show preview for the invited room
if ([self canShowRoomPreviewFor:invitedRoom])
{
// Display the room preview
[self dispayRoomWithRoomId:invitedRoom.roomId inMatrixSession:invitedRoom.mxSession];
}
else
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
}
else if ([cell isKindOfClass:[DirectoryRecentTableViewCell class]])
{