Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #942 from matrix-org/steve/5055_roomvc_retain_cycles
Browse files Browse the repository at this point in the history
RoomVC: Retain cycles prevent RoomViewController to be deallocated
  • Loading branch information
SBiOSoftWhare authored Oct 28, 2021
2 parents c658cfa + 9222847 commit 359e376
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 16 deletions.
4 changes: 2 additions & 2 deletions MatrixKit/Controllers/MXKRecentListViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ limitations under the License.
/**
The fake top view displayed in case of vertical bounce.
*/
UIView *topview;
__weak UIView *topview;
}

@property (weak, nonatomic) IBOutlet UISearchBar *recentsSearchBar;
Expand All @@ -74,7 +74,7 @@ limitations under the License.
/**
The delegate for the view controller.
*/
@property (nonatomic) id<MXKRecentListViewControllerDelegate> delegate;
@property (nonatomic, weak) id<MXKRecentListViewControllerDelegate> delegate;

/**
Enable the search option by adding a navigation item in the navigation bar (YES by default).
Expand Down
2 changes: 1 addition & 1 deletion MatrixKit/Controllers/MXKRecentListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ @interface MXKRecentListViewController ()
/**
The reconnection animated view.
*/
UIView* reconnectingView;
__weak UIView* reconnectingView;

/**
The current table view header if any.
Expand Down
18 changes: 9 additions & 9 deletions MatrixKit/Controllers/MXKRoomViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ typedef NS_ENUM(NSUInteger, MXKRoomViewControllerJoinRoomResult) {
/**
Potential event details view.
*/
MXKEventDetailsView *eventDetailsView;
__weak MXKEventDetailsView *eventDetailsView;

/**
Current alert (if any).
*/
UIAlertController *currentAlert;
__weak UIAlertController *currentAlert;

/**
The document interaction Controller used to share attachment
Expand Down Expand Up @@ -138,12 +138,12 @@ typedef NS_ENUM(NSUInteger, MXKRoomViewControllerJoinRoomResult) {
/**
The current title view defined into the view controller.
*/
@property (nonatomic, readonly) MXKRoomTitleView* titleView;
@property (nonatomic, weak, readonly) MXKRoomTitleView* titleView;

/**
The current input toolbar view defined into the view controller.
*/
@property (nonatomic, readonly) MXKRoomInputToolbarView* inputToolbarView;
@property (nonatomic, weak, readonly) MXKRoomInputToolbarView* inputToolbarView;

/**
The current extra info view defined into the view controller.
Expand Down Expand Up @@ -197,12 +197,12 @@ typedef NS_ENUM(NSUInteger, MXKRoomViewControllerJoinRoomResult) {
This object is defined when the displayed room is left. It is added into the bubbles table header.
This label is used to display the reason why the room has been left.
*/
@property (nonatomic, readonly) UILabel *leftRoomReasonLabel;
@property (nonatomic, weak, readonly) UILabel *leftRoomReasonLabel;

@property (nonatomic) IBOutlet UITableView *bubblesTableView;
@property (nonatomic) IBOutlet UIView *roomTitleViewContainer;
@property (nonatomic) IBOutlet UIView *roomInputToolbarContainer;
@property (nonatomic) IBOutlet UIView *roomActivitiesContainer;
@property (weak, nonatomic) IBOutlet UITableView *bubblesTableView;
@property (weak, nonatomic) IBOutlet UIView *roomTitleViewContainer;
@property (weak, nonatomic) IBOutlet UIView *roomInputToolbarContainer;
@property (weak, nonatomic) IBOutlet UIView *roomActivitiesContainer;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bubblesTableViewTopConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bubblesTableViewBottomConstraint;
Expand Down
31 changes: 29 additions & 2 deletions MatrixKit/Controllers/MXKRoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ - (void)viewDidLoad
{
[self shareEncryptionKeys];
}

self.navigationController.delegate = self;
}

- (BOOL)prefersStatusBarHidden
Expand Down Expand Up @@ -911,10 +909,15 @@ - (void)joinRoomWithRoomIdOrAlias:(NSString*)roomIdOrAlias
self->joinRoomRequest = nil;
[self stopActivityIndicator];

MXWeakify(self);

// The room is now part of the user's room
MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:self.mainSession];

[roomDataSourceManager roomDataSourceForRoom:room.roomId create:YES onComplete:^(MXKRoomDataSource *newRoomDataSource) {

MXStrongifyAndReturnIfNil(self);

// And can be displayed
[self displayRoom:newRoomDataSource];

Expand Down Expand Up @@ -1799,12 +1802,16 @@ - (void)triggerInitialBackPagination
// Trigger back pagination to fill all the screen
CGRect frame = [[UIScreen mainScreen] bounds];

MXWeakify(self);

isPaginationInProgress = YES;
[self startActivityIndicator];
[roomDataSource paginateToFillRect:frame
direction:MXTimelineDirectionBackwards
withMinRequestMessagesCount:_paginationLimit
success:^{

MXStrongifyAndReturnIfNil(self);

// Stop spinner
self->isPaginationInProgress = NO;
Expand Down Expand Up @@ -1866,6 +1873,8 @@ - (void)triggerInitialBackPagination
self.bubbleTableViewDisplayInTransition = NO;
}
failure:^(NSError *error) {

MXStrongifyAndReturnIfNil(self);

// Stop spinner
self->isPaginationInProgress = NO;
Expand Down Expand Up @@ -1906,9 +1915,13 @@ - (void)triggerPagination:(NSUInteger)limit direction:(MXTimelineDirection)direc

isPaginationInProgress = YES;

MXWeakify(self);

// Trigger pagination
[roomDataSource paginate:limit direction:direction onlyFromStore:NO success:^(NSUInteger addedCellNumber) {

MXStrongifyAndReturnIfNil(self);

// We will adjust the vertical offset in order to unchange the current display (pagination should be inconspicuous)
CGFloat verticalOffset = 0;

Expand Down Expand Up @@ -1979,6 +1992,8 @@ - (void)triggerPagination:(NSUInteger)limit direction:(MXTimelineDirection)direc

} failure:^(NSError *error) {

MXStrongifyAndReturnIfNil(self);

self.bubbleTableViewDisplayInTransition = YES;

// Reload table on failure because some changes may have been ignored during pagination (see[dataSource:didCellChange:])
Expand All @@ -2002,9 +2017,13 @@ - (void)triggerAttachmentBackPagination:(NSString*)eventId

isPaginationInProgress = YES;

MXWeakify(self);

// Trigger back pagination to find previous attachments
[roomDataSource paginate:_paginationLimit direction:MXTimelineDirectionBackwards onlyFromStore:NO success:^(NSUInteger addedCellNumber) {

MXStrongifyAndReturnIfNil(self);

// Check whether attachments viewer is still visible
if (self.attachmentsViewer)
{
Expand Down Expand Up @@ -2052,6 +2071,8 @@ - (void)triggerAttachmentBackPagination:(NSString*)eventId

} failure:^(NSError *error) {

MXStrongifyAndReturnIfNil(self);

// Reload table on failure because some changes may have been ignored during back pagination (see[dataSource:didCellChange:])
self.bubbleTableViewDisplayInTransition = YES;
self->isPaginationInProgress = NO;
Expand Down Expand Up @@ -3521,14 +3542,20 @@ - (void)handleTypingNotification:(BOOL)typing
lastTypingDate = nil;
}

MXWeakify(self);

// Send typing notification to server
[roomDataSource.room sendTypingNotification:typing
timeout:notificationTimeoutMS
success:^{

MXStrongifyAndReturnIfNil(self);
// Reset last typing date
self->lastTypingDate = nil;
} failure:^(NSError *error)
{
MXStrongifyAndReturnIfNil(self);

MXLogDebug(@"[MXKRoomVC] Failed to send typing notification (%d)", typing);

// Cancel timer (if any)
Expand Down
2 changes: 1 addition & 1 deletion MatrixKit/Models/Room/MXKRoomBubbleCellData.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/**
The data source owner of this instance.
*/
MXKRoomDataSource *roomDataSource;
__weak MXKRoomDataSource *roomDataSource;

/**
Array of bubble components. Each bubble is supposed to have at least one component.
Expand Down
6 changes: 5 additions & 1 deletion MatrixKit/Views/RoomTitle/MXKRoomTitleView.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@interface MXKRoomTitleView ()
{
// Observer kMXRoomSummaryDidChangeNotification to keep updated the room name.
id mxRoomSummaryDidChangeObserver;
__weak id mxRoomSummaryDidChangeObserver;
}
@end

Expand Down Expand Up @@ -120,9 +120,13 @@ - (void)setMxRoom:(MXRoom *)mxRoom

if (mxRoom)
{
MXWeakify(self);

// Register a listener to handle the room name change
mxRoomSummaryDidChangeObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXRoomSummaryDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {

MXStrongifyAndReturnIfNil(self);

// Check whether the text field is editing before refreshing title view
if (!self.isEditing)
{
Expand Down
1 change: 1 addition & 0 deletions changelog.d/5055.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MXKRoomViewController: Fix retain cycles that prevents deallocation.

0 comments on commit 359e376

Please sign in to comment.