Fixes vector-im/element-ios/issues/4830 - Automatically dismissing invites for empty rooms after failing to join.
MODIFY
MatrixKit/Assets/MatrixKitAssets.bundle/en.lproj/MatrixKit.strings
MatrixKit/Assets/MatrixKitAssets.bundle/en.lproj/MatrixKit.strings
// Room
"room_please_select" = "Please select a room";
"room_error_join_failed_title" = "Failed to join room";
-"room_error_join_failed_empty_room" = "It is not currently possible to re-join an empty room.";
+"room_error_join_failed_empty_room" = "It is not currently possible to join an empty room.";
"room_error_name_edition_not_authorized" = "You are not authorized to edit this room name";
"room_error_topic_edition_not_authorized" = "You are not authorized to edit this room topic";
"room_error_cannot_load_timeline" = "Failed to load timeline";

MODIFY
MatrixKit/Controllers/MXKRoomViewController.h
MatrixKit/Controllers/MXKRoomViewController.h
#import "MXKAttachmentsViewController.h"
#import "MXKAttachmentAnimator.h"
+typedef NS_ENUM(NSUInteger, MXKRoomViewControllerJoinRoomResult) {
+ MXKRoomViewControllerJoinRoomResultSuccess,
+ MXKRoomViewControllerJoinRoomResultFailureRoomEmpty,
+ MXKRoomViewControllerJoinRoomResultFailureJoinInProgress,
+ MXKRoomViewControllerJoinRoomResultFailureGeneric
+};
+
/**
This view controller displays messages of a room. Only one matrix session is handled by this view controller.
*/
@param completion the block to execute at the end of the operation.
You may specify nil for this parameter.
*/
-- (void)joinRoom:(void(^)(BOOL succeed))completion;
+- (void)joinRoom:(void(^)(MXKRoomViewControllerJoinRoomResult result))completion;
/**
Join a room with a room id or an alias.
@param completion the block to execute at the end of the operation.
You may specify nil for this parameter.
*/
-- (void)joinRoomWithRoomIdOrAlias:(NSString*)roomIdOrAlias viaServers:(NSArray<NSString*>*)viaServers andSignUrl:(NSString*)signUrl completion:(void(^)(BOOL succeed))completion;
+- (void)joinRoomWithRoomIdOrAlias:(NSString*)roomIdOrAlias
+ viaServers:(NSArray<NSString*>*)viaServers
+ andSignUrl:(NSString*)signUrl
+ completion:(void(^)(MXKRoomViewControllerJoinRoomResult result))completion;
/**
Update view controller appearance when the user is about to leave the displayed room.

MODIFY
MatrixKit/Controllers/MXKRoomViewController.m
MatrixKit/Controllers/MXKRoomViewController.m
}
}
-- (void)joinRoom:(void(^)(BOOL succeed))completion
+- (void)joinRoom:(void(^)(MXKRoomViewControllerJoinRoomResult result))completion
{
- // Check whether a join request is not already running
- if (!joinRoomRequest)
+ if (joinRoomRequest != nil)
{
+ if (completion)
+ {
+ completion(MXKRoomViewControllerJoinRoomResultFailureJoinInProgress);
+ }
+ return;
+ }
+
[self startActivityIndicator];
joinRoomRequest = [roomDataSource.room join:^{
if (completion)
{
- completion(YES);
+ completion(MXKRoomViewControllerJoinRoomResultSuccess);
}
} failure:^(NSError *error) {
-
MXLogDebug(@"[MXKRoomVC] Failed to join room (%@)", self->roomDataSource.room.summary.displayname);
-
- self->joinRoomRequest = nil;
- [self stopActivityIndicator];
-
- // Show the error to the end user
- 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 processRoomJoinFailureWithError:error completion:completion];
+ }];
}
- [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;
-
- }]];
-
- [self presentViewController:self->currentAlert animated:YES completion:nil];
-
+- (void)joinRoomWithRoomIdOrAlias:(NSString*)roomIdOrAlias
+ viaServers:(NSArray<NSString*>*)viaServers
+ andSignUrl:(NSString*)signUrl
+ completion:(void(^)(MXKRoomViewControllerJoinRoomResult result))completion
+{
+ if (joinRoomRequest != nil)
+ {
if (completion)
{
- completion(NO);
+ completion(MXKRoomViewControllerJoinRoomResultFailureJoinInProgress);
}
- }];
- }
- else if (completion)
- {
- completion (NO);
- }
+ return;
}
-- (void)joinRoomWithRoomIdOrAlias:(NSString*)roomIdOrAlias viaServers:(NSArray<NSString*>*)viaServers andSignUrl:(NSString*)signUrl completion:(void(^)(BOOL succeed))completion
-{
- // Check whether a join request is not already running
- if (!joinRoomRequest)
- {
[self startActivityIndicator];
void (^success)(MXRoom *room) = ^(MXRoom *room) {
if (completion)
{
- completion(YES);
+ completion(MXKRoomViewControllerJoinRoomResultSuccess);
}
}];
};
void (^failure)(NSError *error) = ^(NSError *error) {
-
MXLogDebug(@"[MXKRoomVC] Failed to join room (%@)", roomIdOrAlias);
+ [self processRoomJoinFailureWithError:error completion:completion];
+ };
+
+ // Does the join need to be validated before?
+ if (signUrl)
+ {
+ joinRoomRequest = [self.mainSession joinRoom:roomIdOrAlias viaServers:viaServers withSignUrl:signUrl success:success failure:failure];
+ }
+ else
+ {
+ joinRoomRequest = [self.mainSession joinRoom:roomIdOrAlias viaServers:viaServers success:success failure:failure];
+ }
+}
+- (void)processRoomJoinFailureWithError:(NSError *)error completion:(void(^)(MXKRoomViewControllerJoinRoomResult result))completion
+{
self->joinRoomRequest = nil;
[self stopActivityIndicator];
// Show the error to the end user
NSString *msg = [error.userInfo valueForKey:NSLocalizedDescriptionKey];
- if ([msg isEqualToString:@"No known servers"])
+
+ // FIXME: We should hide this inside the SDK and expose it as a domain specific error
+ BOOL isRoomEmpty = [msg isEqualToString:@"No known servers"];
+ if (isRoomEmpty)
{
// 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"];
}
+
MXWeakify(self);
[self->currentAlert dismissViewControllerAnimated:NO completion:nil];
MXStrongifyAndReturnIfNil(self);
self->currentAlert = nil;
- }]];
-
- [self presentViewController:self->currentAlert animated:YES completion:nil];
-
if (completion)
{
- completion(NO);
+ completion((isRoomEmpty ? MXKRoomViewControllerJoinRoomResultFailureRoomEmpty : MXKRoomViewControllerJoinRoomResultFailureGeneric));
}
- };
+ }]];
- // Does the join need to be validated before?
- if (signUrl)
- {
- joinRoomRequest = [self.mainSession joinRoom:roomIdOrAlias viaServers:viaServers withSignUrl:signUrl success:success failure:failure];
- }
- else
- {
- joinRoomRequest = [self.mainSession joinRoom:roomIdOrAlias viaServers:viaServers success:success failure:failure];
- }
- }
- else if (completion)
- {
- completion (NO);
- }
+ [self presentViewController:self->currentAlert animated:YES completion:nil];
}
- (void)leaveRoomOnEvent:(MXEvent*)event

ADD
changelog.d/4830.api
+Exposed more room joining result types in the completion handler.
\ No newline at end of file

Fixes vector-im/element-ios/issues/4830 - Automatically dismissing invites for empty rooms after failing to join.