Skip to content

Commit

Permalink
Small tidy up post rebase/review.
Browse files Browse the repository at this point in the history
- Remove unused invalidated property.
- Rename some RoomSummary instances to summary instead of details.
- Fix tests with missing roomListItem's.
  • Loading branch information
pixlwave committed Jul 4, 2024
1 parent 13045ae commit 40fa132
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 73 deletions.
2 changes: 1 addition & 1 deletion ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7417,7 +7417,7 @@
repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift";
requirement = {
kind = exactVersion;
version = 1.0.21;
version = 1.0.22;
};
};
701C7BEF8F70F7A83E852DCC /* XCRemoteSwiftPackageReference "GZIP" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/element-hq/matrix-rust-components-swift",
"state" : {
"revision" : "e920922314385cbf7a1dc8ad06cd5fd121aa1b59",
"version" : "1.0.21"
"revision" : "5a8b528c916a46009225517d2ee81296e2eddbfd",
"version" : "1.0.22"
}
},
{
Expand Down
39 changes: 19 additions & 20 deletions ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ struct HomeScreenRoom: Identifiable, Equatable {

static let placeholderLastMessage = AttributedString("Hidden last message")

/// The list item identifier can be a real room identifier, a custom one for invalidated entries
/// or a completely unique one for empty items and skeletons
/// The list item identifier is it's room identifier.
let id: String

/// The real room identifier this item points to
Expand Down Expand Up @@ -205,39 +204,39 @@ struct HomeScreenRoom: Identifiable, Equatable {
}

extension HomeScreenRoom {
init(details: RoomSummary, invalidated: Bool, hideUnreadMessagesBadge: Bool) {
let identifier = invalidated ? "invalidated-" + details.id : details.id
init(summary: RoomSummary, hideUnreadMessagesBadge: Bool) {
let identifier = summary.id

let hasUnreadMessages = hideUnreadMessagesBadge ? false : details.hasUnreadMessages
let hasUnreadMessages = hideUnreadMessagesBadge ? false : summary.hasUnreadMessages

let isDotShown = hasUnreadMessages || details.hasUnreadMentions || details.hasUnreadNotifications || details.isMarkedUnread
let isMentionShown = details.hasUnreadMentions && !details.isMuted
let isMuteShown = details.isMuted
let isCallShown = details.hasOngoingCall
let isHighlighted = details.isMarkedUnread || (!details.isMuted && (details.hasUnreadNotifications || details.hasUnreadMentions))
let isDotShown = hasUnreadMessages || summary.hasUnreadMentions || summary.hasUnreadNotifications || summary.isMarkedUnread
let isMentionShown = summary.hasUnreadMentions && !summary.isMuted
let isMuteShown = summary.isMuted
let isCallShown = summary.hasOngoingCall
let isHighlighted = summary.isMarkedUnread || (!summary.isMuted && (summary.hasUnreadNotifications || summary.hasUnreadMentions))

var inviter: InviterDetails?
if let roomMemberProxy = details.inviter {
if let roomMemberProxy = summary.inviter {
inviter = .init(userID: roomMemberProxy.userID,
displayName: roomMemberProxy.displayName,
avatarURL: roomMemberProxy.avatarURL)
}

self.init(id: identifier,
roomID: details.id,
type: details.isInvite ? .invite : .room,
roomID: summary.id,
type: summary.isInvite ? .invite : .room,
badges: .init(isDotShown: isDotShown,
isMentionShown: isMentionShown,
isMuteShown: isMuteShown,
isCallShown: isCallShown),
name: details.name,
isDirect: details.isDirect,
name: summary.name,
isDirect: summary.isDirect,
isHighlighted: isHighlighted,
isFavourite: details.isFavourite,
timestamp: details.lastMessageFormattedTimestamp,
lastMessage: details.lastMessage,
avatar: details.avatar,
isFavourite: summary.isFavourite,
timestamp: summary.lastMessageFormattedTimestamp,
lastMessage: summary.lastMessage,
avatar: summary.avatar,
inviter: inviter,
canonicalAlias: details.canonicalAlias)
canonicalAlias: summary.canonicalAlias)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
var rooms = [HomeScreenRoom]()

for summary in roomSummaryProvider.roomListPublisher.value {
let room = HomeScreenRoom(details: summary, invalidated: false, hideUnreadMessagesBadge: appSettings.hideUnreadMessagesBadge)
let room = HomeScreenRoom(summary: summary, hideUnreadMessagesBadge: appSettings.hideUnreadMessagesBadge)
rooms.append(room)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private extension HomeScreenRoom {
inviter.displayName = "Jack"
inviter.userID = "@jack:somewhere.com"

let details = RoomSummary(roomListItem: RoomListItemSDKMock(),
let summary = RoomSummary(roomListItem: RoomListItemSDKMock(),
id: "@someone:somewhere.com",
isInvite: false,
inviter: inviter,
Expand All @@ -226,7 +226,7 @@ private extension HomeScreenRoom {
isMarkedUnread: false,
isFavourite: false)

return .init(details: details, invalidated: false, hideUnreadMessagesBadge: false)
return .init(summary: summary, hideUnreadMessagesBadge: false)
}

static func roomInvite(alias: String? = nil, avatarURL: URL? = nil) -> HomeScreenRoom {
Expand All @@ -235,7 +235,7 @@ private extension HomeScreenRoom {
inviter.userID = "@jack:somewhi.nl"
inviter.avatarURL = avatarURL

let details = RoomSummary(roomListItem: RoomListItemSDKMock(),
let summary = RoomSummary(roomListItem: RoomListItemSDKMock(),
id: "@someone:somewhere.com",
isInvite: false,
inviter: inviter,
Expand All @@ -254,6 +254,6 @@ private extension HomeScreenRoom {
isMarkedUnread: false,
isFavourite: false)

return .init(details: details, invalidated: false, hideUnreadMessagesBadge: false)
return .init(summary: summary, hideUnreadMessagesBadge: false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview {
}()

static func mockRoom(summary: RoomSummary) -> HomeScreenRoom? {
HomeScreenRoom(details: summary, invalidated: false, hideUnreadMessagesBadge: false)
HomeScreenRoom(summary: summary, hideUnreadMessagesBadge: false)
}

static var previews: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ class NotificationSettingsEditScreenViewModel: NotificationSettingsEditScreenVie
}
}

private func buildRoom(with details: RoomSummary) async -> NotificationSettingsEditScreenRoom {
let notificationMode = try? await notificationSettingsProxy.getUserDefinedRoomNotificationMode(roomId: details.id)
return NotificationSettingsEditScreenRoom(id: details.id,
roomId: details.id,
name: details.name,
avatar: details.avatar,
private func buildRoom(with summary: RoomSummary) async -> NotificationSettingsEditScreenRoom {
let notificationMode = try? await notificationSettingsProxy.getUserDefinedRoomNotificationMode(roomId: summary.id)
return NotificationSettingsEditScreenRoom(id: summary.id,
roomId: summary.id,
name: summary.name,
avatar: summary.avatar,
notificationMode: notificationMode)
}

Expand Down
1 change: 0 additions & 1 deletion ElementX/Sources/Services/Client/ClientProxyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ enum ClientProxyError: Error {

enum SlidingSyncConstants {
static let defaultTimelineLimit: UInt = 20
static let maximumVisibleRangeSize = 30
}

/// This struct represents the configuration that we are using to register the application through Pusher to Sygnal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
let roomDetails = fetchRoomDetailsFromRoomListItem(roomListItem)

guard let roomInfo = roomDetails.roomInfo else {
fatalError("")
fatalError("Missing room info for \(roomListItem.id())")
}

var attributedLastMessage: AttributedString?
Expand Down
59 changes: 30 additions & 29 deletions UnitTests/Sources/HomeScreenRoomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import XCTest

@MainActor
class HomeScreenRoomTests: XCTestCase {
var roomSummaryDetails: RoomSummary!
var roomSummary: RoomSummary!

// swiftlint:disable:next function_parameter_count
func setupRoomSummary(isMarkedUnread: Bool,
Expand All @@ -30,23 +30,24 @@ class HomeScreenRoomTests: XCTestCase {
unreadNotificationsCount: UInt,
notificationMode: RoomNotificationModeProxy,
hasOngoingCall: Bool) {
roomSummaryDetails = RoomSummary(id: "Test room",
isInvite: false,
inviter: nil,
name: "Test room",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: unreadMessagesCount,
unreadMentionsCount: unreadMentionsCount,
unreadNotificationsCount: unreadNotificationsCount,
notificationMode: notificationMode,
canonicalAlias: nil,
hasOngoingCall: hasOngoingCall,
isMarkedUnread: isMarkedUnread,
isFavourite: false)
roomSummary = RoomSummary(roomListItem: .init(noPointer: .init()),
id: "Test room",
isInvite: false,
inviter: nil,
name: "Test room",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: unreadMessagesCount,
unreadMentionsCount: unreadMentionsCount,
unreadNotificationsCount: unreadNotificationsCount,
notificationMode: notificationMode,
canonicalAlias: nil,
hasOngoingCall: hasOngoingCall,
isMarkedUnread: isMarkedUnread,
isFavourite: false)
}

func testNoBadge() {
Expand All @@ -57,7 +58,7 @@ class HomeScreenRoomTests: XCTestCase {
notificationMode: .allMessages,
hasOngoingCall: false)

let room = HomeScreenRoom(details: roomSummaryDetails, invalidated: false, hideUnreadMessagesBadge: false)
let room = HomeScreenRoom(summary: roomSummary, invalidated: false, hideUnreadMessagesBadge: false)

XCTAssertFalse(room.isHighlighted)
XCTAssertFalse(room.badges.isDotShown)
Expand All @@ -74,7 +75,7 @@ class HomeScreenRoomTests: XCTestCase {
notificationMode: .allMessages,
hasOngoingCall: true)

let room = HomeScreenRoom(details: roomSummaryDetails, invalidated: false, hideUnreadMessagesBadge: false)
let room = HomeScreenRoom(summary: roomSummary, invalidated: false, hideUnreadMessagesBadge: false)

XCTAssertTrue(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
Expand All @@ -91,7 +92,7 @@ class HomeScreenRoomTests: XCTestCase {
notificationMode: .allMessages,
hasOngoingCall: false)

let room = HomeScreenRoom(details: roomSummaryDetails, invalidated: false, hideUnreadMessagesBadge: false)
let room = HomeScreenRoom(summary: roomSummary, invalidated: false, hideUnreadMessagesBadge: false)

XCTAssertFalse(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
Expand All @@ -108,7 +109,7 @@ class HomeScreenRoomTests: XCTestCase {
notificationMode: .allMessages,
hasOngoingCall: false)

let room = HomeScreenRoom(details: roomSummaryDetails, invalidated: false, hideUnreadMessagesBadge: false)
let room = HomeScreenRoom(summary: roomSummary, invalidated: false, hideUnreadMessagesBadge: false)

XCTAssertTrue(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
Expand All @@ -125,7 +126,7 @@ class HomeScreenRoomTests: XCTestCase {
notificationMode: .allMessages,
hasOngoingCall: false)

let room = HomeScreenRoom(details: roomSummaryDetails, invalidated: false, hideUnreadMessagesBadge: false)
let room = HomeScreenRoom(summary: roomSummary, invalidated: false, hideUnreadMessagesBadge: false)

XCTAssertTrue(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
Expand All @@ -142,7 +143,7 @@ class HomeScreenRoomTests: XCTestCase {
notificationMode: .allMessages,
hasOngoingCall: true)

let room = HomeScreenRoom(details: roomSummaryDetails, invalidated: false, hideUnreadMessagesBadge: false)
let room = HomeScreenRoom(summary: roomSummary, invalidated: false, hideUnreadMessagesBadge: false)

XCTAssertFalse(room.isHighlighted)
XCTAssertFalse(room.badges.isDotShown)
Expand All @@ -159,7 +160,7 @@ class HomeScreenRoomTests: XCTestCase {
notificationMode: .mentionsAndKeywordsOnly,
hasOngoingCall: false)

let room = HomeScreenRoom(details: roomSummaryDetails, invalidated: false, hideUnreadMessagesBadge: false)
let room = HomeScreenRoom(summary: roomSummary, invalidated: false, hideUnreadMessagesBadge: false)

XCTAssertFalse(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
Expand All @@ -176,7 +177,7 @@ class HomeScreenRoomTests: XCTestCase {
notificationMode: .mentionsAndKeywordsOnly,
hasOngoingCall: false)

let room = HomeScreenRoom(details: roomSummaryDetails, invalidated: false, hideUnreadMessagesBadge: true)
let room = HomeScreenRoom(summary: roomSummary, invalidated: false, hideUnreadMessagesBadge: true)

XCTAssertFalse(room.isHighlighted)
XCTAssertFalse(room.badges.isDotShown)
Expand All @@ -195,7 +196,7 @@ class HomeScreenRoomTests: XCTestCase {
notificationMode: .allMessages,
hasOngoingCall: false)

let room = HomeScreenRoom(details: roomSummaryDetails, invalidated: false, hideUnreadMessagesBadge: false)
let room = HomeScreenRoom(summary: roomSummary, invalidated: false, hideUnreadMessagesBadge: false)

XCTAssertTrue(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
Expand All @@ -212,7 +213,7 @@ class HomeScreenRoomTests: XCTestCase {
notificationMode: .allMessages,
hasOngoingCall: false)

let room = HomeScreenRoom(details: roomSummaryDetails, invalidated: false, hideUnreadMessagesBadge: false)
let room = HomeScreenRoom(summary: roomSummary, invalidated: false, hideUnreadMessagesBadge: false)

XCTAssertTrue(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
Expand All @@ -229,7 +230,7 @@ class HomeScreenRoomTests: XCTestCase {
notificationMode: .mute,
hasOngoingCall: true)

let room = HomeScreenRoom(details: roomSummaryDetails, invalidated: false, hideUnreadMessagesBadge: false)
let room = HomeScreenRoom(summary: roomSummary, invalidated: false, hideUnreadMessagesBadge: false)

XCTAssertTrue(room.isHighlighted)
XCTAssertTrue(room.badges.isDotShown)
Expand Down
3 changes: 2 additions & 1 deletion UnitTests/Sources/LoggingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class LoggingTests: XCTestCase {
let roomName = "Private Conversation"
let lastMessage = "Secret information"
let heroName = "Pseudonym"
let roomSummary = RoomSummary(id: "myroomid",
let roomSummary = RoomSummary(roomListItem: .init(noPointer: .init()),
id: "myroomid",
isInvite: false,
inviter: nil,
name: roomName,
Expand Down
11 changes: 6 additions & 5 deletions UnitTests/Sources/RoomSummaryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RoomSummaryTests: XCTestCase {
let heroes = [UserProfileProxy(userID: "hero_1", displayName: "Hero 1", avatarURL: "mxc://hs.tld/user/avatar")]

func testRoomAvatar() {
let details = makeDetails(isDirect: false, hasRoomAvatar: true)
let details = makeSummary(isDirect: false, hasRoomAvatar: true)

switch details.avatar {
case .room(let id, let name, let avatarURL):
Expand All @@ -37,7 +37,7 @@ class RoomSummaryTests: XCTestCase {
}

func testDMAvatarSet() {
let details = makeDetails(isDirect: true, hasRoomAvatar: true)
let details = makeSummary(isDirect: true, hasRoomAvatar: true)

switch details.avatar {
case .room(let id, let name, let avatarURL):
Expand All @@ -50,7 +50,7 @@ class RoomSummaryTests: XCTestCase {
}

func testDMAvatarNotSet() {
let details = makeDetails(isDirect: true, hasRoomAvatar: false)
let details = makeSummary(isDirect: true, hasRoomAvatar: false)

switch details.avatar {
case .room:
Expand All @@ -62,8 +62,9 @@ class RoomSummaryTests: XCTestCase {

// MARK: - Helpers

func makeDetails(isDirect: Bool, hasRoomAvatar: Bool) -> RoomSummary {
RoomSummary(id: roomDetails.id,
func makeSummary(isDirect: Bool, hasRoomAvatar: Bool) -> RoomSummary {
RoomSummary(roomListItem: .init(noPointer: .init()),
id: roomDetails.id,
isInvite: false,
inviter: nil,
name: roomDetails.name,
Expand Down
2 changes: 1 addition & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ packages:
# Element/Matrix dependencies
MatrixRustSDK:
url: https://github.com/element-hq/matrix-rust-components-swift
exactVersion: 1.0.21
exactVersion: 1.0.22
# path: ../matrix-rust-sdk
Compound:
url: https://github.com/element-hq/compound-ios
Expand Down

0 comments on commit 40fa132

Please sign in to comment.