Leave chat correctly when leaving or deleting room from room info view.

Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Ivan Sein 2019-07-26 17:05:53 +02:00
Родитель d7e1e7738b
Коммит d7d2107306
4 изменённых файлов: 24 добавлений и 3 удалений

Просмотреть файл

@ -13,5 +13,6 @@
@interface NCChatViewController : SLKTextViewController
- (instancetype)initForRoom:(NCRoom *)room;
- (void)leaveChat;
@end

Просмотреть файл

@ -204,11 +204,16 @@
// Leave chat when the view controller has been removed from its parent view.
if (self.isMovingFromParentViewController) {
[_lobbyCheckTimer invalidate];
[[NCRoomsManager sharedInstance] leaveChatInRoom:_room.token];
[self leaveChat];
}
}
- (void)leaveChat
{
[_lobbyCheckTimer invalidate];
[[NCRoomsManager sharedInstance] leaveChatInRoom:_room.token];
}
#pragma mark - Configuration
- (void)setTitleView
@ -369,7 +374,7 @@
- (void)titleButtonPressed:(id)sender
{
RoomInfoTableViewController *roomInfoVC = [[RoomInfoTableViewController alloc] initForRoom:_room];
RoomInfoTableViewController *roomInfoVC = [[RoomInfoTableViewController alloc] initForRoom:_room fromChatViewController:self];
[self.navigationController pushViewController:roomInfoVC animated:YES];
}

Просмотреть файл

@ -8,9 +8,11 @@
#import <UIKit/UIKit.h>
#import "NCRoom.h"
#import "NCChatViewController.h"
@interface RoomInfoTableViewController : UITableViewController
- (instancetype)initForRoom:(NCRoom *)room;
- (instancetype)initForRoom:(NCRoom *)room fromChatViewController:(NCChatViewController *)chatViewController;
@end

Просмотреть файл

@ -71,6 +71,7 @@ typedef enum ModificationError {
@interface RoomInfoTableViewController () <UITextFieldDelegate, UIGestureRecognizerDelegate>
@property (nonatomic, strong) NCRoom *room;
@property (nonatomic, strong) NCChatViewController *chatViewController;
@property (nonatomic, strong) NSString *roomName;
@property (nonatomic, strong) NSMutableArray *roomParticipants;
@property (nonatomic, strong) UITextField *roomNameTextField;
@ -87,10 +88,16 @@ typedef enum ModificationError {
@implementation RoomInfoTableViewController
- (instancetype)initForRoom:(NCRoom *)room
{
return [self initForRoom:room fromChatViewController:nil];
}
- (instancetype)initForRoom:(NCRoom *)room fromChatViewController:(NCChatViewController *)chatViewController
{
self = [super init];
if (self) {
_room = room;
_chatViewController = chatViewController;
}
return self;
}
@ -621,6 +628,9 @@ typedef enum ModificationError {
{
[[NCAPIController sharedInstance] removeSelfFromRoom:_room.token withCompletionBlock:^(NSInteger errorCode, NSError *error) {
if (!error) {
if (_chatViewController) {
[_chatViewController leaveChat];
}
[[NCUserInterfaceController sharedInstance] presentConversationsList];
} else if (errorCode == 400) {
[self showRoomModificationError:kModificationErrorLeaveModeration];
@ -635,6 +645,9 @@ typedef enum ModificationError {
{
[[NCAPIController sharedInstance] deleteRoom:_room.token withCompletionBlock:^(NSError *error) {
if (!error) {
if (_chatViewController) {
[_chatViewController leaveChat];
}
[[NCUserInterfaceController sharedInstance] presentConversationsList];
} else {
NSLog(@"Error deleting the room: %@", error.description);