Skip to content

Commit

Permalink
Fix unhandled callback when the session is nil. (matrix-org#1833)
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave authored Nov 23, 2023
1 parent c91b556 commit f72d833
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
38 changes: 23 additions & 15 deletions MatrixSDK/Data/MXRoomState.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,31 @@ + (void)loadRoomStateFromStore:(id<MXStore>)store
{
[store stateOfRoom:roomId success:^(NSArray<MXEvent *> * _Nonnull stateEvents) {
if (!stateEvents.count) {
MXLogWarning(@"[MXRoomState] loadRoomStateFromStore(%@): No state events stored, loading from api", logId);
MXLogWarning(@"[MXRoomState] loadRoomStateFromStore(%@): No state events stored, loading from API", logId);

[matrixSession.matrixRestClient stateOfRoom:roomId success:^(NSArray *JSONData) {
NSArray<MXEvent *> *events = [MXEvent modelsFromJSON:JSONData];
MXLogDebug(@"[MXRoomState] loadRoomStateFromStore(%@): Loaded %lu events from api", logId, events.count);

[roomState handleStateEvents:events];
onComplete(roomState);
} failure:^(NSError *error) {
NSDictionary *details = @{
@"log_id": logId ?: @"unknown",
@"error": error ?: @"unknown"
};
MXLogErrorDetails(@"[MXRoomState] loadRoomStateFromStore: Failed to load any events from api", details);

if (!matrixSession)
{
MXLogError(@"[MXRoomState] loadRoomStateFromStore: Missing session, unable to load from API")
onComplete(roomState);
}];
}
else
{
[matrixSession.matrixRestClient stateOfRoom:roomId success:^(NSArray *JSONData) {
NSArray<MXEvent *> *events = [MXEvent modelsFromJSON:JSONData];
MXLogDebug(@"[MXRoomState] loadRoomStateFromStore(%@): Loaded %lu events from api", logId, events.count);

[roomState handleStateEvents:events];
onComplete(roomState);
} failure:^(NSError *error) {
NSDictionary *details = @{
@"log_id": logId ?: @"unknown",
@"error": error ?: @"unknown"
};
MXLogErrorDetails(@"[MXRoomState] loadRoomStateFromStore: Failed to load any events from API", details);

onComplete(roomState);
}];
}
} else {
MXLogDebug(@"[MXRoomState] loadRoomStateFromStore(%@): Initializing with %lu state events", logId, stateEvents.count);

Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-1833.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix unhandled callback when the session is nil.

0 comments on commit f72d833

Please sign in to comment.