From d7d3c509b868cc67d29559b86eb781975cdb0114 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Fri, 23 Dec 2016 10:56:55 +0100 Subject: [PATCH] Fix crash onPresenceChanged --- Classes/ContactDetailsView.m | 3 ++- Classes/LinphoneUI/UIContactCell.m | 7 ++++--- Classes/PhoneMainView.h | 1 + Classes/PhoneMainView.m | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Classes/ContactDetailsView.m b/Classes/ContactDetailsView.m index 28dccac48..18b802743 100644 --- a/Classes/ContactDetailsView.m +++ b/Classes/ContactDetailsView.m @@ -186,7 +186,7 @@ _editButton.hidden = TRUE; _deleteButton.hidden = TRUE; } - + PhoneMainView.instance.currentName = _nameLabel.text; // Update presence for contact for (NSInteger j = 0; j < [self.tableController.tableView numberOfSections]; ++j) { for (NSInteger i = 0; i < [self.tableController.tableView numberOfRowsInSection:j]; ++i) { @@ -222,6 +222,7 @@ - (void)viewWillDisappear:(BOOL)animated { [_tableController.tableView removeObserver:self forKeyPath:@"contentSize"]; [super viewWillDisappear:animated]; + PhoneMainView.instance.currentName = NULL; if (self.tmpContact) { _contact.firstName = _tmpContact.firstName.copy; _contact.lastName = _tmpContact.lastName.copy; diff --git a/Classes/LinphoneUI/UIContactCell.m b/Classes/LinphoneUI/UIContactCell.m index ce779d8ef..860f84b04 100644 --- a/Classes/LinphoneUI/UIContactCell.m +++ b/Classes/LinphoneUI/UIContactCell.m @@ -20,6 +20,7 @@ #import "UIContactCell.h" #import "ContactsListTableView.h" #import "FastAddressBook.h" +#import "PhoneMainView.h" #import "UILabel+Boldify.h" #import "Utils.h" @@ -37,7 +38,7 @@ UIView *sub = ((UIView *)[arrayOfViews objectAtIndex:0]); [self setFrame:CGRectMake(0, 0, sub.frame.size.width, sub.frame.size.height)]; [self addSubview:sub]; - + _contact = NULL; // Sections are wider on iPad and overlap linphone image - let's move it a bit if (IPAD) { CGRect frame = _linphoneImage.frame; @@ -63,12 +64,12 @@ - (void)onPresenceChanged:(NSNotification *)k { LinphoneFriend *f = [[k.userInfo valueForKey:@"friend"] pointerValue]; // only consider event if it's about us - if (_contact) { + if (_contact && (_nameLabel.text == PhoneMainView.instance.currentName || !PhoneMainView.instance.currentName)) { if (!_contact.friend || f != _contact.friend) { return; } + [self setContact:_contact]; } - [self setContact:_contact]; } #pragma mark - Property Functions diff --git a/Classes/PhoneMainView.h b/Classes/PhoneMainView.h index d7d7f1218..0ccf21b9b 100644 --- a/Classes/PhoneMainView.h +++ b/Classes/PhoneMainView.h @@ -78,6 +78,7 @@ @property(nonatomic, strong) IBOutlet UIView *statusBarBG; @property(nonatomic, strong) IBOutlet UICompositeView *mainViewController; +@property(nonatomic, strong) NSString *currentName; @property(nonatomic, strong) NSString *name; @property(weak, readonly) UICompositeViewDescription *currentView; @property LinphoneChatRoom* currentRoom; diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 174715ad3..c7b461f27 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -127,6 +127,7 @@ static RootViewManager *rootViewManagerInstance = nil; - (void)initPhoneMainView { currentView = nil; _currentRoom = NULL; + _currentName = NULL; inhibitedEvents = [[NSMutableArray alloc] init]; }