diff --git a/MatrixSDK/Data/EventTimeline/Room/MXRoomEventTimeline.m b/MatrixSDK/Data/EventTimeline/Room/MXRoomEventTimeline.m index 300ab9934a..8404748bb6 100644 --- a/MatrixSDK/Data/EventTimeline/Room/MXRoomEventTimeline.m +++ b/MatrixSDK/Data/EventTimeline/Room/MXRoomEventTimeline.m @@ -125,11 +125,24 @@ - (instancetype)initWithRoom:(MXRoom*)theRoom initialEventId:(NSString*)initialE _state = [[MXRoomState alloc] initWithRoomId:room.roomId andMatrixSession:room.mxSession andDirection:YES]; - // If the event stream runs with lazy loading, the timeline must do the same - if (room.mxSession.syncWithLazyLoadOfRoomMembers) + // During startup, if a cached filterId exists, this code will execute to fetch and create a filter. + // However, if a filter is explicitly provided to start(), that filter will overwrite the one allocated here. + // Additionally, this code runs when loadRoom() is called after start() to ensure the filter is always initialized. + if (!_roomEventFilter && room.mxSession.syncFilterId) { - _roomEventFilter = [MXRoomEventFilter new]; - _roomEventFilter.lazyLoadMembers = YES; + [room.mxSession filterWithFilterId:room.mxSession.syncFilterId success:^(MXFilterJSONModel *filter) { + _roomEventFilter = filter.room.timeline; + + // If the event stream runs with lazy loading, the timeline must do the same + if (filter.room.state.lazyLoadMembers) + { + if (!_roomEventFilter) + { + _roomEventFilter = [MXRoomEventFilter new]; + } + _roomEventFilter.lazyLoadMembers = YES; + } + } failure:nil]; } } return self; diff --git a/MatrixSDK/MXSession.m b/MatrixSDK/MXSession.m index 18550d042f..7d2c13f2d6 100644 --- a/MatrixSDK/MXSession.m +++ b/MatrixSDK/MXSession.m @@ -946,6 +946,18 @@ - (void)startWithSyncFilterId:(NSString *)syncFilterId onServerSyncDone:(void (^ MXLogDebug(@"[MXSession] Set syncWithLazyLoadOfRoomMembers to YES"); self->_syncWithLazyLoadOfRoomMembers = YES; } + + for (MXRoom *room in self.rooms) { + [room liveTimeline:^(id liveTimeline) { + liveTimeline.roomEventFilter = filter.room.timeline; + + // If the event stream runs with lazy loading, the timeline must do the same + if (self->_syncWithLazyLoadOfRoomMembers) + { + liveTimeline.roomEventFilter.lazyLoadMembers = YES; + } + }]; + } } failure:nil]; } diff --git a/changelog.d/pr-1912.bugfix b/changelog.d/pr-1912.bugfix new file mode 100644 index 0000000000..a8e8690c98 --- /dev/null +++ b/changelog.d/pr-1912.bugfix @@ -0,0 +1,2 @@ +- Lazy member loading flag was not applied in timeline filter due to init order (setStore before start). +- Support for additional timeline filters.