mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-01 13:46:57 +02:00
Contact Details: Refresh display on contact change notifications
This commit is contained in:
@@ -189,35 +189,34 @@
|
||||
[self addMatrixSession:mxSession];
|
||||
}
|
||||
|
||||
// Force refresh
|
||||
self.contact = _contact;
|
||||
if (_contact)
|
||||
{
|
||||
// Register on notifications related to the contact change
|
||||
[self registerOnContactChangeNotifications];
|
||||
|
||||
// Force refresh
|
||||
[self refreshContactDetails];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewWillDisappear:animated];
|
||||
|
||||
// Remove any pending observers
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
if (mxPresenceObserver)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:mxPresenceObserver];
|
||||
mxPresenceObserver = nil;
|
||||
}
|
||||
[self cancelRegistrationOnContactChangeNotifications];
|
||||
|
||||
// Restore navigation bar display
|
||||
[self hideNavigationBarBorder:NO];
|
||||
|
||||
self.bottomImageView.hidden = YES;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXKContactThumbnailUpdateNotification object:nil];
|
||||
}
|
||||
|
||||
- (void)destroy
|
||||
{
|
||||
[super destroy];
|
||||
|
||||
[self cancelRegistrationOnContactChangeNotifications];
|
||||
|
||||
if (UIApplicationWillChangeStatusBarOrientationNotificationObserver)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:UIApplicationWillChangeStatusBarOrientationNotificationObserver];
|
||||
@@ -259,17 +258,25 @@
|
||||
|
||||
- (void)setContact:(MXKContact *)contact
|
||||
{
|
||||
// Remove any pending observers
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
if (mxPresenceObserver)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:mxPresenceObserver];
|
||||
mxPresenceObserver = nil;
|
||||
}
|
||||
[self cancelRegistrationOnContactChangeNotifications];
|
||||
|
||||
_contact = contact;
|
||||
|
||||
[self registerOnContactChangeNotifications];
|
||||
|
||||
if (!_contact.isMatrixContact)
|
||||
{
|
||||
// Refresh matrix info of the contact
|
||||
[[MXKContactManager sharedManager] updateMatrixIDsForLocalContact:_contact];
|
||||
}
|
||||
|
||||
[self refreshContactDetails];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)registerOnContactChangeNotifications
|
||||
{
|
||||
// Be warned when the thumbnail is updated
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onThumbnailUpdate:) name:kMXKContactThumbnailUpdateNotification object:nil];
|
||||
|
||||
@@ -284,19 +291,55 @@
|
||||
}
|
||||
}];
|
||||
|
||||
if (!_contact.isMatrixContact)
|
||||
// Observe 'MXKContactManager' notifications
|
||||
if (_contact.isMatrixContact)
|
||||
{
|
||||
// Refresh matrix info of the contact
|
||||
[[MXKContactManager sharedManager] updateMatrixIDsForLocalContact:_contact];
|
||||
// Observe 'MXKContactManager' notification on Matrix contacts to refresh details.
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onContactManagerNotification:) name:kMXKContactManagerDidUpdateMatrixContactsNotification object:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Observe 'MXKContactManager' notifications on Local contacts to refresh details.
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onContactManagerNotification:) name:kMXKContactManagerDidUpdateLocalContactsNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onContactManagerNotification:) name:kMXKContactManagerDidUpdateLocalContactMatrixIDsNotification object:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cancelRegistrationOnContactChangeNotifications
|
||||
{
|
||||
// Remove any pending observers
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
if (mxPresenceObserver)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:mxPresenceObserver];
|
||||
mxPresenceObserver = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onContactManagerNotification:(NSNotification *)notif
|
||||
{
|
||||
// Check whether a contact Id is provided
|
||||
if (notif.object)
|
||||
{
|
||||
NSString* contactID = notif.object;
|
||||
if (![contactID isEqualToString:_contact.contactID])
|
||||
{
|
||||
// Ignore
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[self refreshContactDetails];
|
||||
}
|
||||
|
||||
- (void)refreshContactDetails
|
||||
{
|
||||
[self refreshContactDisplayName];
|
||||
[self refreshContactPresence];
|
||||
[self refreshContactThumbnail];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (NSString*)firstMatrixId
|
||||
{
|
||||
NSString* matrixId = nil;
|
||||
@@ -413,7 +456,7 @@
|
||||
{
|
||||
[actionsArray removeAllObjects];
|
||||
|
||||
if (_contact.isMatrixContact)
|
||||
if (_contact.matrixIdentifiers.count)
|
||||
{
|
||||
// Consider the case of the user himself
|
||||
if ([_contact.matrixIdentifiers indexOfObject:self.mainSession.myUser.userId] != NSNotFound)
|
||||
|
||||
Reference in New Issue
Block a user