mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Use local room list sorting from Rust. (#2978)
* Switch to the new local room list sorting API * Get rid of the RoomSummary enum, replace it by the inner RoomSummaryDetails * And finally, rename RoomSummaryDetails to RoomSummary * Fix a bunch of warnings * Small tidy up post rebase/review. - Remove unused invalidated property. - Rename some RoomSummary instances to summary instead of details. - Fix tests with missing roomListItem's. * Update snapshots --------- Co-authored-by: Doug <douglase@element.io>
This commit is contained in:
@@ -74,15 +74,10 @@ class GlobalSearchScreenViewModel: GlobalSearchScreenViewModelType, GlobalSearch
|
||||
|
||||
private func updateRooms(with summaries: [RoomSummary]) {
|
||||
state.rooms = summaries.compactMap { summary in
|
||||
switch summary {
|
||||
case .empty:
|
||||
return nil
|
||||
case .invalidated(let details), .filled(let details):
|
||||
return GlobalSearchRoom(id: details.id,
|
||||
name: details.name,
|
||||
alias: details.canonicalAlias,
|
||||
avatar: details.avatar)
|
||||
}
|
||||
GlobalSearchRoom(id: summary.id,
|
||||
name: summary.name,
|
||||
alias: summary.canonicalAlias,
|
||||
avatar: summary.avatar)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -205,39 +204,39 @@ struct HomeScreenRoom: Identifiable, Equatable {
|
||||
}
|
||||
|
||||
extension HomeScreenRoom {
|
||||
init(details: RoomSummaryDetails, 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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,16 +348,8 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
var rooms = [HomeScreenRoom]()
|
||||
|
||||
for summary in roomSummaryProvider.roomListPublisher.value {
|
||||
switch summary {
|
||||
case .empty:
|
||||
rooms.append(HomeScreenRoom.placeholder())
|
||||
case .filled(let details):
|
||||
let room = HomeScreenRoom(details: details, invalidated: false, hideUnreadMessagesBadge: appSettings.hideUnreadMessagesBadge)
|
||||
rooms.append(room)
|
||||
case .invalidated(let details):
|
||||
let room = HomeScreenRoom(details: details, invalidated: true, hideUnreadMessagesBadge: appSettings.hideUnreadMessagesBadge)
|
||||
rooms.append(room)
|
||||
}
|
||||
let room = HomeScreenRoom(summary: summary, hideUnreadMessagesBadge: appSettings.hideUnreadMessagesBadge)
|
||||
rooms.append(room)
|
||||
}
|
||||
|
||||
state.rooms = rooms
|
||||
|
||||
@@ -207,25 +207,26 @@ private extension HomeScreenRoom {
|
||||
inviter.displayName = "Jack"
|
||||
inviter.userID = "@jack:somewhere.com"
|
||||
|
||||
let details = RoomSummaryDetails(id: "@someone:somewhere.com",
|
||||
isInvite: false,
|
||||
inviter: inviter,
|
||||
name: "Some Guy",
|
||||
isDirect: true,
|
||||
avatarURL: nil,
|
||||
heroes: [.init(userID: "@someone:somewhere.com")],
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
unreadMessagesCount: 0,
|
||||
unreadMentionsCount: 0,
|
||||
unreadNotificationsCount: 0,
|
||||
notificationMode: nil,
|
||||
canonicalAlias: "#footest:somewhere.org",
|
||||
hasOngoingCall: false,
|
||||
isMarkedUnread: false,
|
||||
isFavourite: false)
|
||||
let summary = RoomSummary(roomListItem: RoomListItemSDKMock(),
|
||||
id: "@someone:somewhere.com",
|
||||
isInvite: false,
|
||||
inviter: inviter,
|
||||
name: "Some Guy",
|
||||
isDirect: true,
|
||||
avatarURL: nil,
|
||||
heroes: [.init(userID: "@someone:somewhere.com")],
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
unreadMessagesCount: 0,
|
||||
unreadMentionsCount: 0,
|
||||
unreadNotificationsCount: 0,
|
||||
notificationMode: nil,
|
||||
canonicalAlias: "#footest:somewhere.org",
|
||||
hasOngoingCall: false,
|
||||
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 {
|
||||
@@ -234,24 +235,25 @@ private extension HomeScreenRoom {
|
||||
inviter.userID = "@jack:somewhi.nl"
|
||||
inviter.avatarURL = avatarURL
|
||||
|
||||
let details = RoomSummaryDetails(id: "@someone:somewhere.com",
|
||||
isInvite: false,
|
||||
inviter: inviter,
|
||||
name: "Awesome Room",
|
||||
isDirect: false,
|
||||
avatarURL: avatarURL,
|
||||
heroes: [.init(userID: "@someone:somewhere.com")],
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
unreadMessagesCount: 0,
|
||||
unreadMentionsCount: 0,
|
||||
unreadNotificationsCount: 0,
|
||||
notificationMode: nil,
|
||||
canonicalAlias: alias,
|
||||
hasOngoingCall: false,
|
||||
isMarkedUnread: false,
|
||||
isFavourite: false)
|
||||
let summary = RoomSummary(roomListItem: RoomListItemSDKMock(),
|
||||
id: "@someone:somewhere.com",
|
||||
isInvite: false,
|
||||
inviter: inviter,
|
||||
name: "Awesome Room",
|
||||
isDirect: false,
|
||||
avatarURL: avatarURL,
|
||||
heroes: [.init(userID: "@someone:somewhere.com")],
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
unreadMessagesCount: 0,
|
||||
unreadMentionsCount: 0,
|
||||
unreadNotificationsCount: 0,
|
||||
notificationMode: nil,
|
||||
canonicalAlias: alias,
|
||||
hasOngoingCall: false,
|
||||
isMarkedUnread: false,
|
||||
isFavourite: false)
|
||||
|
||||
return .init(details: details, invalidated: false, hideUnreadMessagesBadge: false)
|
||||
return .init(summary: summary, hideUnreadMessagesBadge: false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,14 +195,7 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview {
|
||||
}()
|
||||
|
||||
static func mockRoom(summary: RoomSummary) -> HomeScreenRoom? {
|
||||
switch summary {
|
||||
case .empty:
|
||||
nil
|
||||
case .invalidated(let details):
|
||||
HomeScreenRoom(details: details, invalidated: true, hideUnreadMessagesBadge: false)
|
||||
case .filled(let details):
|
||||
HomeScreenRoom(details: details, invalidated: false, hideUnreadMessagesBadge: false)
|
||||
}
|
||||
HomeScreenRoom(summary: summary, hideUnreadMessagesBadge: false)
|
||||
}
|
||||
|
||||
static var previews: some View {
|
||||
|
||||
+5
-10
@@ -84,19 +84,14 @@ class MessageForwardingScreenViewModel: MessageForwardingScreenViewModelType, Me
|
||||
MXLog.verbose("Updating rooms")
|
||||
|
||||
var rooms = [MessageForwardingRoom]()
|
||||
|
||||
|
||||
for summary in roomSummaryProvider.roomListPublisher.value {
|
||||
switch summary {
|
||||
case .empty, .invalidated:
|
||||
if summary.id == forwardingItem.roomID {
|
||||
continue
|
||||
case .filled(let details):
|
||||
if details.id == forwardingItem.roomID {
|
||||
continue
|
||||
}
|
||||
|
||||
let room = MessageForwardingRoom(id: details.id, name: details.name, alias: details.canonicalAlias, avatar: details.avatar)
|
||||
rooms.append(room)
|
||||
}
|
||||
|
||||
let room = MessageForwardingRoom(id: summary.id, name: summary.name, alias: summary.canonicalAlias, avatar: summary.avatar)
|
||||
rooms.append(room)
|
||||
}
|
||||
|
||||
state.rooms = rooms
|
||||
|
||||
+14
-20
@@ -138,21 +138,15 @@ class NotificationSettingsEditScreenViewModel: NotificationSettingsEditScreenVie
|
||||
var roomsWithUserDefinedMode: [NotificationSettingsEditScreenRoom] = []
|
||||
|
||||
for roomSummary in filteredRoomsSummary {
|
||||
switch roomSummary {
|
||||
case .empty, .invalidated:
|
||||
guard let roomProxy = await userSession.clientProxy.roomForIdentifier(roomSummary.id) else { continue }
|
||||
// `isOneToOneRoom` here is not the same as `isDirect` on the room. From the point of view of the push rule, a one-to-one room is a room with exactly two active members.
|
||||
let isOneToOneRoom = roomProxy.activeMembersCount == 2
|
||||
// display only the rooms we're interested in
|
||||
switch chatType {
|
||||
case .oneToOneChat where isOneToOneRoom, .groupChat where !isOneToOneRoom:
|
||||
await roomsWithUserDefinedMode.append(buildRoom(with: roomSummary))
|
||||
default:
|
||||
break
|
||||
case .filled(let details):
|
||||
guard let roomProxy = await userSession.clientProxy.roomForIdentifier(details.id) else { continue }
|
||||
// `isOneToOneRoom` here is not the same as `isDirect` on the room. From the point of view of the push rule, a one-to-one room is a room with exactly two active members.
|
||||
let isOneToOneRoom = roomProxy.activeMembersCount == 2
|
||||
// display only the rooms we're interested in
|
||||
switch chatType {
|
||||
case .oneToOneChat where isOneToOneRoom,
|
||||
.groupChat where !isOneToOneRoom:
|
||||
await roomsWithUserDefinedMode.append(buildRoom(with: details))
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,12 +157,12 @@ class NotificationSettingsEditScreenViewModel: NotificationSettingsEditScreenVie
|
||||
}
|
||||
}
|
||||
|
||||
private func buildRoom(with details: RoomSummaryDetails) 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)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -72,7 +72,7 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider, TestablePreview
|
||||
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init())
|
||||
notificationSettingsProxy.getDefaultRoomNotificationModeIsEncryptedIsOneToOneReturnValue = .allMessages
|
||||
|
||||
notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = [RoomSummary].mockRooms.compactMap(\.id)
|
||||
notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = [RoomSummary].mockRooms.map(\.id)
|
||||
let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@alice:example.com",
|
||||
roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms)))))))
|
||||
var viewModel = NotificationSettingsEditScreenViewModel(chatType: .groupChat,
|
||||
@@ -113,7 +113,7 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider, TestablePreview
|
||||
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init(canPushEncryptedEvents: true))
|
||||
notificationSettingsProxy.getDefaultRoomNotificationModeIsEncryptedIsOneToOneReturnValue = .allMessages
|
||||
|
||||
notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = [RoomSummary].mockRooms.compactMap(\.id)
|
||||
notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = [RoomSummary].mockRooms.map(\.id)
|
||||
let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@alice:example.com",
|
||||
roomSummaryProvider: RoomSummaryProviderMock(.init(state: .loaded(.mockRooms)))))))
|
||||
var viewModel = NotificationSettingsEditScreenViewModel(chatType: .groupChat,
|
||||
|
||||
+5
-10
@@ -68,17 +68,12 @@ struct NotificationSettingsEditScreenRoomCell_Previews: PreviewProvider, Testabl
|
||||
notificationSettingsProxy: notificationSettingsProxy)
|
||||
|
||||
let rooms: [NotificationSettingsEditScreenRoom] = summaryProvider.roomListPublisher.value.compactMap { summary -> NotificationSettingsEditScreenRoom? in
|
||||
switch summary {
|
||||
case .empty, .invalidated:
|
||||
return nil
|
||||
case .filled(let details):
|
||||
return NotificationSettingsEditScreenRoom(id: UUID().uuidString,
|
||||
roomId: details.id,
|
||||
name: details.name,
|
||||
avatar: details.avatar)
|
||||
}
|
||||
NotificationSettingsEditScreenRoom(id: UUID().uuidString,
|
||||
roomId: summary.id,
|
||||
name: summary.name,
|
||||
avatar: summary.avatar)
|
||||
}
|
||||
|
||||
|
||||
return VStack(spacing: 0) {
|
||||
ForEach(rooms) { room in
|
||||
NotificationSettingsEditScreenRoomCell(room: room, context: viewModel.context)
|
||||
|
||||
Reference in New Issue
Block a user