Skip to content

Commit

Permalink
Fix unhandled callback when the session is nil.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Nov 22, 2023
1 parent c91b556 commit 9525cdc
Showing 1 changed file with 23 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

0 comments on commit 9525cdc

Please sign in to comment.