Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when roomSummary is nil #1731

Merged
merged 5 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions MatrixSDK/Background/Store/MXSyncResponseStoreManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,18 @@ public class MXSyncResponseStoreManager: NSObject {
for event in eventsToProcess {
switch event.eventType {
case .roomAliases:
if summary.displayname == nil {
summary.displayname = (event.content["aliases"] as? [String])?.first
if summary.displayName == nil {
summary.displayName = (event.content["aliases"] as? [String])?.first
}
case .roomCanonicalAlias:
if summary.displayname == nil {
summary.displayname = event.content["alias"] as? String
if summary.displayname == nil {
summary.displayname = (event.content["alt_aliases"] as? [String])?.first
if summary.displayName == nil {
summary.displayName = event.content["alias"] as? String
if summary.displayName == nil {
summary.displayName = (event.content["alt_aliases"] as? [String])?.first
}
}
case .roomName:
summary.displayname = event.content["name"] as? String
summary.displayName = event.content["name"] as? String
default:
break
}
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Data/MXRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -3870,7 +3870,7 @@ - (void)membersTrustLevelSummaryWithForceDownload:(BOOL)forceDownload success:(v

- (NSString *)description
{
return [NSString stringWithFormat:@"<MXRoom: %p> %@: %@ - %@", self, self.roomId, self.summary.displayname, self.summary.topic];
return [NSString stringWithFormat:@"<MXRoom: %p> %@: %@ - %@", self, self.roomId, self.summary.displayName, self.summary.topic];
}

- (NSComparisonResult)compareLastMessageEventOriginServerTs:(MXRoom *)otherRoom
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Data/MXRoomSummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ FOUNDATION_EXPORT NSUInteger const MXRoomSummaryPaginationChunkSize;
/**
The computed display name of the room.
*/
@property (nonatomic) NSString *displayname;
@property (nonatomic) NSString *displayName;

/**
The topic of the room.
Expand Down
14 changes: 7 additions & 7 deletions MatrixSDK/Data/MXRoomSummary.m
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ - (void)updateWith:(id<MXRoomSummaryProtocol>)summary
_roomTypeString = summary.roomTypeString;
_roomType = summary.roomType;
_avatar = summary.avatar;
_displayname = summary.displayname;
_displayName = summary.displayName;
_topic = summary.topic;
_creatorUserId = summary.creatorUserId;
_aliases = summary.aliases;
Expand Down Expand Up @@ -286,7 +286,7 @@ - (void)resetRoomStateData
MXRoom *room = self.room;

_avatar = nil;
_displayname = nil;
_displayName = nil;
_topic = nil;
_aliases = nil;

Expand All @@ -296,7 +296,7 @@ - (void)resetRoomStateData

BOOL updated = [self.mxSession.roomSummaryUpdateDelegate session:self.mxSession updateRoomSummary:self withStateEvents:roomState.stateEvents roomState:roomState];

if (self.displayname == nil || self.avatar == nil)
if (self.displayName == nil || self.avatar == nil)
{
// Avatar and displayname may not be recomputed from the state event list if
// the latter does not contain any `name` or `avatar` event. So, in this case,
Expand Down Expand Up @@ -971,7 +971,7 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder
_roomTypeString = [aDecoder decodeObjectForKey:@"roomTypeString"];
_roomType = [aDecoder decodeIntegerForKey:@"roomType"];
_avatar = [aDecoder decodeObjectForKey:@"avatar"];
_displayname = [aDecoder decodeObjectForKey:@"displayname"];
_displayName = [aDecoder decodeObjectForKey:@"displayname"];
_topic = [aDecoder decodeObjectForKey:@"topic"];
_creatorUserId = [aDecoder decodeObjectForKey:@"creatorUserId"];
_aliases = [aDecoder decodeObjectForKey:@"aliases"];
Expand Down Expand Up @@ -1021,7 +1021,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder
[aCoder encodeObject:_roomTypeString forKey:@"roomTypeString"];
[aCoder encodeInteger:_roomType forKey:@"roomType"];
[aCoder encodeObject:_avatar forKey:@"avatar"];
[aCoder encodeObject:_displayname forKey:@"displayname"];
[aCoder encodeObject:_displayName forKey:@"displayname"];
[aCoder encodeObject:_topic forKey:@"topic"];
[aCoder encodeObject:_creatorUserId forKey:@"creatorUserId"];
[aCoder encodeObject:_aliases forKey:@"aliases"];
Expand Down Expand Up @@ -1059,7 +1059,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder

- (NSString *)description
{
return [NSString stringWithFormat:@"%@ %@: %@ - %@", super.description, _roomId, _displayname, _lastMessage.eventId];
return [NSString stringWithFormat:@"%@ %@: %@ - %@", super.description, _roomId, _displayName, _lastMessage.eventId];
}

- (NSUInteger)hash
Expand All @@ -1070,7 +1070,7 @@ - (NSUInteger)hash
result = prime * result + [_roomId hash];
result = prime * result + [_roomTypeString hash];
result = prime * result + [_avatar hash];
result = prime * result + [_displayname hash];
result = prime * result + [_displayName hash];
result = prime * result + [_topic hash];
result = prime * result + [_creatorUserId hash];
result = prime * result + [_aliases hash];
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Data/MXRoomSummaryProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSString * _Nullable avatar;

/// The computed display name of the room.
@property (nonatomic, readonly) NSString * _Nullable displayname;
@property (nonatomic, readonly) NSString * _Nullable displayName;

/// The topic of the room.
@property (nonatomic, readonly) NSString * _Nullable topic;
Expand Down
12 changes: 6 additions & 6 deletions MatrixSDK/Data/MXRoomSummaryUpdater.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ - (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary
switch (event.eventType)
{
case MXEventTypeRoomName:
summary.displayname = roomState.name;
summary.displayName = roomState.name;
updated = YES;
break;

Expand Down Expand Up @@ -186,7 +186,7 @@ - (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary
// If m.room.canonical_alias is set, use it if there is no m.room.name
if (!roomState.name && roomState.canonicalAlias)
{
summary.displayname = roomState.canonicalAlias;
summary.displayName = roomState.canonicalAlias;
updated = YES;
}
// If canonicalAlias is set, add it to the aliases array
Expand Down Expand Up @@ -300,11 +300,11 @@ - (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary

NSUInteger memberCount = roomState.membersCount.members;
if (memberCount > 1
&& (!summary.displayname || [summary.displayname isEqualToString:_roomNameStringLocalizer.emptyRoom]))
&& (!summary.displayName || [summary.displayName isEqualToString:_roomNameStringLocalizer.emptyRoom]))
{
// Data are missing to compute the display name
MXLogDebug(@"[MXRoomSummaryUpdater] updateRoomSummary: Computed an unexpected \"Empty Room\" name. memberCount: %@", @(memberCount));
summary.displayname = [self fixUnexpectedEmptyRoomDisplayname:memberCount
summary.displayName = [self fixUnexpectedEmptyRoomDisplayname:memberCount
session:session
roomState:roomState];
updated = YES;
Expand Down Expand Up @@ -524,9 +524,9 @@ - (BOOL)updateSummaryDisplayname:(MXRoomSummary *)summary session:(MXSession *)s
}
}

if (displayName != summary.displayname || ![displayName isEqualToString:summary.displayname])
if (displayName != summary.displayName || ![displayName isEqualToString:summary.displayName])
{
summary.displayname = displayName;
summary.displayName = displayName;
return YES;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ internal class MXBreadcrumbsRoomListDataFetcher: NSObject, MXRoomListDataFetcher

if let query = fetchOptions.filterOptions.query?.lowercased(), !query.isEmpty {
recentRoomIds = recentRoomIds.filter({ roomId in
guard let displayname = session?.roomSummary(withRoomId: roomId).displayname else {
guard let displayName = session?.roomSummary(withRoomId: roomId)?.displayName else {
return false
}
return displayname.lowercased().contains(query)
return displayName.lowercased().contains(query)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ extension MXRoomListDataFilterable {

if let query = filterOptions.query, !query.isEmpty {
let predicate1 = NSPredicate(format: "%K CONTAINS[cd] %@",
#keyPath(MXRoomSummaryProtocol.displayname),
#keyPath(MXRoomSummaryProtocol.displayName),
query)
let predicate2 = NSPredicate(format: "%K CONTAINS[cd] %@",
#keyPath(MXRoomSummaryProtocol.spaceChildInfo.displayName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension MXRoomListDataSortable {
// }

if sortOptions.alphabetical {
result.append(NSSortDescriptor(keyPath: \MXRoomSummaryProtocol.displayname, ascending: true))
result.append(NSSortDescriptor(keyPath: \MXRoomSummaryProtocol.displayName, ascending: true))
}

if sortOptions.invitesFirst {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ private class RoomSummaryForTotalCounts: NSObject, MXRoomSummaryProtocol {
var roomTypeString: String?
var roomType: MXRoomType = .room
var avatar: String?
var displayname: String?
var displayName: String?
var topic: String?
var creatorUserId: String = ""
var aliases: [String] = []
Expand Down Expand Up @@ -465,7 +465,7 @@ private class RoomSummaryForTotalCounts: NSObject, MXRoomSummaryProtocol {
}

override var description: String {
return "<RoomSummaryForTotalCounts: \(roomId) \(String(describing: displayname))>"
return "<RoomSummaryForTotalCounts: \(roomId) \(String(describing: displayName))>"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class MXRoomSummaryMO: NSManagedObject {
s_typeString = summary.roomTypeString
s_typeInt = Int16(summary.roomType.rawValue)
s_avatar = summary.avatar
s_displayName = summary.displayname
s_displayName = summary.displayName
s_topic = summary.topic
s_creatorUserId = summary.creatorUserId
s_aliases = summary.aliases.joined(separator: StringArrayDelimiter)
Expand Down Expand Up @@ -186,7 +186,7 @@ extension MXRoomSummaryMO: MXRoomSummaryProtocol {
return s_avatar
}

public var displayname: String? {
public var displayName: String? {
return s_displayName
}

Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/MXSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ typedef void (^MXOnBackgroundSyncFail)(NSError *error);

@return the MXRoomSummary instance.
*/
- (MXRoomSummary *)roomSummaryWithRoomId:(NSString*)roomId;
- (nullable MXRoomSummary *)roomSummaryWithRoomId:(NSString*)roomId;
stefanceriu marked this conversation as resolved.
Show resolved Hide resolved

/**
Recompute all room summaries last message.
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/MXSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -3320,7 +3320,7 @@ - (MXHTTPOperation*)eventWithEventId:(NSString*)eventId


#pragma mark - Rooms summaries
- (MXRoomSummary *)roomSummaryWithRoomId:(NSString*)roomId
- (nullable MXRoomSummary *)roomSummaryWithRoomId:(NSString*)roomId
{
MXRoomSummary *roomSummary;

Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/Space/MXSpaceService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ public class MXSpaceService: NSObject {
membersCount.members = joinedMembersCount

roomSummary.membersCount = membersCount
roomSummary.displayname = spaceChildSummaryResponse.name
roomSummary.displayName = spaceChildSummaryResponse.name
roomSummary.topic = spaceChildSummaryResponse.topic
roomSummary.avatar = spaceChildSummaryResponse.avatarUrl
roomSummary.isEncrypted = false
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/VoIP/CallKit/MXCallKitAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ - (void)contactIdentifierForCall:(MXCall *)call onComplete:(void (^)(NSString *c
{
if (call.isConferenceCall)
{
onComplete(call.room.summary.displayname);
onComplete(call.room.summary.displayName);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/VoIP/MXCall.m
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ - (void)handleCallInvite:(MXEvent *)event
}
else
{
_callerName = nativeRoom.summary.displayname;
_callerName = nativeRoom.summary.displayName;
}
}
calleeId = callManager.mxSession.myUserId;
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDKTests/MXBackgroundSyncServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class MXBackgroundSyncServiceTests: XCTestCase {
case .success:
let roomSummary = self.bgSyncService?.roomSummary(forRoomId: roomId)
XCTAssertNotNil(roomSummary, "Room summary should be fetched")
XCTAssertEqual(roomSummary?.displayname, newName, "Room name change should be reflected")
XCTAssertEqual(roomSummary?.displayName, newName, "Room name change should be reflected")
expectation?.fulfill()
case .failure(let error):
XCTFail("Cannot fetch the event from background sync service - error: \(error)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class MXCoreDataRoomListDataManagerUnitTests: XCTestCase {

// rename rooms by index
for (index, summary) in result.enumerated() {
summary.displayname = "Room \(index + 1)"
summary.displayName = "Room \(index + 1)"
if let event = MXEvent(fromJSON: [
"event_id": MXTools.generateTransactionId() as Any,
"room_id": summary.roomId,
Expand Down
20 changes: 10 additions & 10 deletions MatrixSDKTests/MXLazyLoadingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,8 @@ - (void)checkRoomSummaryDisplayNameFromHeroesWithLazyLoading:(BOOL)lazyLoading

MXRoomSummary *roomSummary = [aliceSession roomSummaryWithRoomId:roomId];

XCTAssertTrue(roomSummary.displayname.length
&& ![roomSummary.displayname isEqualToString:@"Empty room"], @"Unexpected null room name: %@", roomSummary.displayname);
XCTAssertTrue(roomSummary.displayName.length
&& ![roomSummary.displayName isEqualToString:@"Empty room"], @"Unexpected null room name: %@", roomSummary.displayName);

[expectation fulfill];
}];
Expand Down Expand Up @@ -1079,8 +1079,8 @@ - (void)checkRoomSummaryDisplayNameWhenNoMoreNameWithLazyLoading:(BOOL)lazyLoadi

// -> The room name should be "Bob & 2 others"
MXRoomSummary *roomSummary = [aliceSession roomSummaryWithRoomId:roomId];
XCTAssertTrue(roomSummary.displayname.length
&& ![roomSummary.displayname isEqualToString:@"Empty room"], @"Unexpected null room name: %@", roomSummary.displayname);
XCTAssertTrue(roomSummary.displayName.length
&& ![roomSummary.displayName isEqualToString:@"Empty room"], @"Unexpected null room name: %@", roomSummary.displayName);


// Make alice do an initial sync
Expand All @@ -1100,8 +1100,8 @@ - (void)checkRoomSummaryDisplayNameWhenNoMoreNameWithLazyLoading:(BOOL)lazyLoadi

// -> The room name should be "Bob & 2 others"
MXRoomSummary *roomSummary2 = [aliceSession2 roomSummaryWithRoomId:roomId];
XCTAssertTrue(roomSummary2.displayname.length
&& ![roomSummary2.displayname isEqualToString:@"Empty room"], @"Unexpected null room name: %@", roomSummary2.displayname);
XCTAssertTrue(roomSummary2.displayName.length
&& ![roomSummary2.displayName isEqualToString:@"Empty room"], @"Unexpected null room name: %@", roomSummary2.displayName);


[expectation fulfill];
Expand Down Expand Up @@ -1145,10 +1145,10 @@ - (void)checkRoomSummaryDisplayNameInDirectChatWithLazyLoading:(BOOL)lazyLoading
[self createDirectChatScenarioWithLazyLoading:lazyLoading readyToTest:^(MXSession *aliceSession, MXSession *bobSession, NSString *roomId, XCTestExpectation *expectation) {

MXRoomSummary *roomSummary = [aliceSession roomSummaryWithRoomId:roomId];
XCTAssertTrue(roomSummary.displayname.length
&& ![roomSummary.displayname isEqualToString:@"Empty room"], @"Unexpected null room name: %@", roomSummary.displayname);
XCTAssertTrue(roomSummary.displayName.length
&& ![roomSummary.displayName isEqualToString:@"Empty room"], @"Unexpected null room name: %@", roomSummary.displayName);

NSString *roomDisplayName = roomSummary.displayname;
NSString *roomDisplayName = roomSummary.displayName;

[aliceSession pause];

Expand All @@ -1160,7 +1160,7 @@ - (void)checkRoomSummaryDisplayNameInDirectChatWithLazyLoading:(BOOL)lazyLoading

// -> The room name should be still the same
MXRoomSummary *roomSummary2 = [aliceSession roomSummaryWithRoomId:roomId];
XCTAssertEqualObjects(roomSummary2.displayname, roomDisplayName);
XCTAssertEqualObjects(roomSummary2.displayName, roomDisplayName);

[expectation fulfill];
}];
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDKTests/MXPeekingRoomTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ - (void)testPeekingSummary

XCTAssertNotNil(peekingRoom.summary);

XCTAssertNotNil(peekingRoom.summary.displayname);
XCTAssertNotNil(peekingRoom.summary.displayName);
XCTAssertNotNil(peekingRoom.summary.topic);
XCTAssertEqual(peekingRoom.summary.membersCount.members, 1, @"The MXPeekingRoom state must be known now");

Expand Down
8 changes: 4 additions & 4 deletions MatrixSDKTests/MXRoomSummaryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ - (void)testDisplaynameUpdate

observer = [[NSNotificationCenter defaultCenter] addObserverForName:kMXRoomSummaryDidChangeNotification object:summary queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {

XCTAssertEqualObjects(summary.displayname, displayName, @"Room summary must be updated");
XCTAssertEqualObjects(summary.displayName, displayName, @"Room summary must be updated");

[expectation fulfill];
}];
Expand All @@ -479,13 +479,13 @@ - (void)testRoomDisplaynameExcludingUsers

[room state:^(MXRoomState *roomState) {
// Given a room with two users.
XCTAssertEqualObjects(summary.displayname, @"mxAlice", @"A room with one other user should be given the name of that user.");
XCTAssertEqualObjects(summary.displayName, @"mxAlice", @"A room with one other user should be given the name of that user.");

// When excluding the other user during a display name update.
[updater updateSummaryDisplayname:summary session:bobSession withServerRoomSummary:nil roomState:roomState excludingUserIDs: @[aliceRestClient.credentials.userId]];

// Then the name of the room should no longer include the other user.
XCTAssertEqualObjects(summary.displayname, @"Empty room", @"The name of the room should not include the other user when they are excluded.");
XCTAssertEqualObjects(summary.displayName, @"Empty room", @"The name of the room should not include the other user when they are excluded.");
[expectation fulfill];
}];
}];
Expand Down Expand Up @@ -1107,7 +1107,7 @@ - (void)testStatePassedToMXRoomSummaryUpdating
[room state:^(MXRoomState *roomState) {

XCTAssertEqualObjects(roomState.name, displayName);
XCTAssertEqualObjects(summary.displayname, displayName, @"Room summary must be updated");
XCTAssertEqualObjects(summary.displayName, displayName, @"Room summary must be updated");

[expectation fulfill];
}];
Expand Down
Loading