From 9fec550a98155c2ae173c4177bcf05135197f199 Mon Sep 17 00:00:00 2001 From: JanNiklas Grabowski Date: Wed, 19 Apr 2023 12:48:53 +0200 Subject: [PATCH] update breadcrumb list when leaving a room --- MatrixSDK/MXSession.m | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/MatrixSDK/MXSession.m b/MatrixSDK/MXSession.m index 051b41d12..d1d1242bc 100644 --- a/MatrixSDK/MXSession.m +++ b/MatrixSDK/MXSession.m @@ -3199,6 +3199,8 @@ - (void)removeRoom:(NSString *)roomId // And remove the room and its summary from the list [rooms removeObjectForKey:roomId]; [roomSummaries removeObjectForKey:roomId]; + // remove room from breadcrub list + [self removeBreadcrumbWithRoomId: roomId]; // Broadcast the left room [[NSNotificationCenter defaultCenter] postNotificationName:kMXSessionDidLeaveRoomNotification @@ -4758,6 +4760,24 @@ - (void)updateBreadcrumbsWithRoomWithId:(NSString *)roomId }]; } +// update breadcrub list when leaving a room +- (void)removeBreadcrumbWithRoomId:(NSString *)roomId +{ + NSDictionary *breadcrumbs = [self.accountData accountDataForEventType:kMXAccountDataTypeBreadcrumbs]; + + NSMutableArray *recentRoomIds = breadcrumbs[kMXAccountDataTypeRecentRoomsKey] ? [NSMutableArray arrayWithArray:breadcrumbs[kMXAccountDataTypeRecentRoomsKey]] : [NSMutableArray array]; + + NSInteger index = [recentRoomIds indexOfObject:roomId]; + if (index != NSNotFound) + { + [recentRoomIds removeObjectAtIndex:index]; + } + + [self setAccountData:@{kMXAccountDataTypeRecentRoomsKey : recentRoomIds} + forType:kMXAccountDataTypeBreadcrumbs + success: nil failure: nil]; +} + #pragma mark - Homeserver information - (MXWellKnown *)homeserverWellknown {