6103: Handle refreshing timeline with listner on beaconInfoSummary

This commit is contained in:
MaximeE
2022-05-10 11:36:54 +02:00
parent 334fb24c95
commit bfa845b881
2 changed files with 42 additions and 1 deletions
+41 -1
View File
@@ -41,6 +41,9 @@ const CGFloat kTypingCellHeight = 24;
// Observe key verification transaction changes
@property (nonatomic, weak) id keyVerificationTransactionDidChangeNotificationObserver;
// Listen to location beacon received
@property (nonatomic, weak) id beaconInfoSummaryListner;
// Timer used to debounce cells refresh
@property (nonatomic, strong) NSTimer *refreshCellsTimer;
@@ -100,6 +103,7 @@ const CGFloat kTypingCellHeight = 24;
[self registerKeyVerificationRequestNotification];
[self registerKeyVerificationTransactionNotification];
[self registerTrustLevelDidChangeNotifications];
[self registerBeaconInfoSummaryListner];
self.encryptionTrustLevel = RoomEncryptionTrustLevelUnknown;
}
@@ -178,9 +182,14 @@ const CGFloat kTypingCellHeight = 24;
{
[[NSNotificationCenter defaultCenter] removeObserver:self.keyVerificationTransactionDidChangeNotificationObserver];
}
[self.mxSession.threadingService removeDelegate:self];
if (self.beaconInfoSummaryListner)
{
[self.mxSession.aggregations.beaconAggregations removeListener:self.beaconInfoSummaryListner];
}
[super destroy];
}
@@ -753,6 +762,37 @@ const CGFloat kTypingCellHeight = 24;
}];
}
- (void)registerBeaconInfoSummaryListner
{
self.beaconInfoSummaryListner = [self.mxSession.aggregations.beaconAggregations listenToBeaconInfoSummaryUpdateInRoomWithId:self.roomId handler:^(id<MXBeaconInfoSummaryProtocol> beaconInfoSummary) {
@synchronized (self->bubbles)
{
[self refreshFirstCellWithBeaconInfoSummary:beaconInfoSummary];
}
}];
}
- (void)refreshFirstCellWithBeaconInfoSummary:(id<MXBeaconInfoSummaryProtocol>)beaconInfoSummary
{
NSUInteger cellIndex = [bubbles indexOfObjectPassingTest:^BOOL(id<MXKRoomBubbleCellDataStoring> _Nonnull cellData, NSUInteger idx, BOOL * _Nonnull stop) {
if ([cellData isKindOfClass:[RoomBubbleCellData class]])
{
RoomBubbleCellData *roomBubbleCellData = (RoomBubbleCellData*)cellData;
if ([roomBubbleCellData.beaconInfoSummary.id isEqualToString:beaconInfoSummary.id])
{
*stop = YES;
return YES;
}
}
return NO;
}];
if (cellIndex != NSNotFound)
{
[self refreshCells];
}
}
- (BOOL)shouldFetchKeyVerificationForEvent:(MXEvent*)event
{
if (!event)