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:
Stefan Ceriu
2024-07-05 12:10:53 +03:00
committed by GitHub
parent c024702d50
commit d71c8c4e83
26 changed files with 556 additions and 608 deletions
+1 -8
View File
@@ -92,14 +92,7 @@ extension ClientProxyMock {
return nil
}
let roomID = room.id ?? UUID().uuidString
switch room {
case .empty:
return await RoomProxyMock(.init(name: "Empty room"))
case .filled(let details), .invalidated(let details):
return await RoomProxyMock(.init(id: roomID, name: details.name))
}
return await RoomProxyMock(.init(id: room.id, name: room.name))
}
}
}
@@ -14022,13 +14022,13 @@ open class RoomListSDKMock: MatrixRustSDK.RoomList {
open var entriesListenerReceivedListener: RoomListEntriesListener?
open var entriesListenerReceivedInvocations: [RoomListEntriesListener] = []
var entriesListenerUnderlyingReturnValue: RoomListEntriesResult!
open var entriesListenerReturnValue: RoomListEntriesResult! {
var entriesListenerUnderlyingReturnValue: TaskHandle!
open var entriesListenerReturnValue: TaskHandle! {
get {
if Thread.isMainThread {
return entriesListenerUnderlyingReturnValue
} else {
var returnValue: RoomListEntriesResult? = nil
var returnValue: TaskHandle? = nil
DispatchQueue.main.sync {
returnValue = entriesListenerUnderlyingReturnValue
}
@@ -14046,9 +14046,9 @@ open class RoomListSDKMock: MatrixRustSDK.RoomList {
}
}
}
open var entriesListenerClosure: ((RoomListEntriesListener) -> RoomListEntriesResult)?
open var entriesListenerClosure: ((RoomListEntriesListener) -> TaskHandle)?
open override func entries(listener: RoomListEntriesListener) -> RoomListEntriesResult {
open override func entries(listener: RoomListEntriesListener) -> TaskHandle {
entriesListenerCallsCount += 1
entriesListenerReceivedListener = listener
DispatchQueue.main.async {
@@ -14436,6 +14436,147 @@ open class RoomListDynamicEntriesControllerSDKMock: MatrixRustSDK.RoomListDynami
}
}
}
open class RoomListEntriesWithDynamicAdaptersResultSDKMock: MatrixRustSDK.RoomListEntriesWithDynamicAdaptersResult {
init() {
super.init(noPointer: .init())
}
public required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
fatalError("init(unsafeFromRawPointer:) has not been implemented")
}
fileprivate var pointer: UnsafeMutableRawPointer!
//MARK: - controller
var controllerUnderlyingCallsCount = 0
open var controllerCallsCount: Int {
get {
if Thread.isMainThread {
return controllerUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = controllerUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
controllerUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
controllerUnderlyingCallsCount = newValue
}
}
}
}
open var controllerCalled: Bool {
return controllerCallsCount > 0
}
var controllerUnderlyingReturnValue: RoomListDynamicEntriesController!
open var controllerReturnValue: RoomListDynamicEntriesController! {
get {
if Thread.isMainThread {
return controllerUnderlyingReturnValue
} else {
var returnValue: RoomListDynamicEntriesController? = nil
DispatchQueue.main.sync {
returnValue = controllerUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
controllerUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
controllerUnderlyingReturnValue = newValue
}
}
}
}
open var controllerClosure: (() -> RoomListDynamicEntriesController)?
open override func controller() -> RoomListDynamicEntriesController {
controllerCallsCount += 1
if let controllerClosure = controllerClosure {
return controllerClosure()
} else {
return controllerReturnValue
}
}
//MARK: - entriesStream
var entriesStreamUnderlyingCallsCount = 0
open var entriesStreamCallsCount: Int {
get {
if Thread.isMainThread {
return entriesStreamUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = entriesStreamUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
entriesStreamUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
entriesStreamUnderlyingCallsCount = newValue
}
}
}
}
open var entriesStreamCalled: Bool {
return entriesStreamCallsCount > 0
}
var entriesStreamUnderlyingReturnValue: TaskHandle!
open var entriesStreamReturnValue: TaskHandle! {
get {
if Thread.isMainThread {
return entriesStreamUnderlyingReturnValue
} else {
var returnValue: TaskHandle? = nil
DispatchQueue.main.sync {
returnValue = entriesStreamUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
entriesStreamUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
entriesStreamUnderlyingReturnValue = newValue
}
}
}
}
open var entriesStreamClosure: (() -> TaskHandle)?
open override func entriesStream() -> TaskHandle {
entriesStreamCallsCount += 1
if let entriesStreamClosure = entriesStreamClosure {
return entriesStreamClosure()
} else {
return entriesStreamReturnValue
}
}
}
open class RoomListItemSDKMock: MatrixRustSDK.RoomListItem {
init() {
super.init(noPointer: .init())
@@ -15309,52 +15450,6 @@ open class RoomListServiceSDKMock: MatrixRustSDK.RoomListService {
}
}
//MARK: - applyInput
open var applyInputInputThrowableError: Error?
var applyInputInputUnderlyingCallsCount = 0
open var applyInputInputCallsCount: Int {
get {
if Thread.isMainThread {
return applyInputInputUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = applyInputInputUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
applyInputInputUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
applyInputInputUnderlyingCallsCount = newValue
}
}
}
}
open var applyInputInputCalled: Bool {
return applyInputInputCallsCount > 0
}
open var applyInputInputReceivedInput: RoomListInput?
open var applyInputInputReceivedInvocations: [RoomListInput] = []
open var applyInputInputClosure: ((RoomListInput) async throws -> Void)?
open override func applyInput(input: RoomListInput) async throws {
if let error = applyInputInputThrowableError {
throw error
}
applyInputInputCallsCount += 1
applyInputInputReceivedInput = input
DispatchQueue.main.async {
self.applyInputInputReceivedInvocations.append(input)
}
try await applyInputInputClosure?(input)
}
//MARK: - room
open var roomRoomIdThrowableError: Error?
@@ -54,7 +54,7 @@ extension RoomSummaryProviderMock {
var rooms = initialRooms
if !query.isEmpty {
rooms = rooms.filter { $0.name?.localizedCaseInsensitiveContains(query) ?? false }
rooms = rooms.filter { $0.name.localizedCaseInsensitiveContains(query) }
}
roomListSubject.send(rooms)
@@ -78,126 +78,132 @@ extension RoomSummaryProviderMock {
extension Array where Element == RoomSummary {
static let mockRooms: [Element] = [
.filled(details: RoomSummaryDetails(id: "1",
isInvite: false,
inviter: nil,
name: "Foundation 🔭🪐🌌",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: AttributedString("I do not wish to take the trouble to understand mysticism"),
lastMessageFormattedTimestamp: "14:56",
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .allMessages,
canonicalAlias: nil,
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false)),
.filled(details: RoomSummaryDetails(id: "2",
isInvite: false,
inviter: nil,
name: "Foundation and Empire",
isDirect: false,
avatarURL: URL.picturesDirectory,
heroes: [],
lastMessage: AttributedString("How do you see the Emperor then? You think he keeps office hours?"),
lastMessageFormattedTimestamp: "2:56 PM",
unreadMessagesCount: 2,
unreadMentionsCount: 0,
unreadNotificationsCount: 2,
notificationMode: .mute,
canonicalAlias: nil,
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false)),
.filled(details: RoomSummaryDetails(id: "3",
isInvite: false,
inviter: nil,
name: "Second Foundation",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: try? AttributedString(markdown: "He certainly seemed no *mental genius* to me"),
lastMessageFormattedTimestamp: "Some time ago",
unreadMessagesCount: 3,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .mentionsAndKeywordsOnly,
canonicalAlias: nil,
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false)),
.filled(details: RoomSummaryDetails(id: "4",
isInvite: false,
inviter: nil,
name: "Foundation's Edge",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: AttributedString("There's an archaic measure of time that's called the month"),
lastMessageFormattedTimestamp: "Just now",
unreadMessagesCount: 2,
unreadMentionsCount: 2,
unreadNotificationsCount: 2,
notificationMode: .allMessages,
canonicalAlias: nil,
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false)),
.filled(details: RoomSummaryDetails(id: "5",
isInvite: false,
inviter: nil,
name: "Foundation and Earth",
isDirect: true,
avatarURL: nil,
heroes: [],
lastMessage: AttributedString("Clearly, if Earth is powerful enough to do that, it might also be capable of adjusting minds in order to force belief in its radioactivity"),
lastMessageFormattedTimestamp: "1986",
unreadMessagesCount: 1,
unreadMentionsCount: 1,
unreadNotificationsCount: 1,
notificationMode: .allMessages,
canonicalAlias: nil,
hasOngoingCall: true,
isMarkedUnread: false,
isFavourite: false)),
.filled(details: RoomSummaryDetails(id: "6",
isInvite: false,
inviter: nil,
name: "Prelude to Foundation",
isDirect: true,
avatarURL: nil,
heroes: [],
lastMessage: AttributedString("Are you groping for the word 'paranoia'?"),
lastMessageFormattedTimestamp: "きょうはじゅういちがつじゅういちにちです",
unreadMessagesCount: 6,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .mute,
canonicalAlias: nil,
hasOngoingCall: true,
isMarkedUnread: false,
isFavourite: false)),
.filled(details: RoomSummaryDetails(id: "0",
isInvite: false,
inviter: nil,
name: "Unknown",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: nil,
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false)),
.empty
RoomSummary(roomListItem: RoomListItemSDKMock(),
id: "1",
isInvite: false,
inviter: nil,
name: "Foundation 🔭🪐🌌",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: AttributedString("I do not wish to take the trouble to understand mysticism"),
lastMessageFormattedTimestamp: "14:56",
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .allMessages,
canonicalAlias: nil,
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false),
RoomSummary(roomListItem: RoomListItemSDKMock(),
id: "2",
isInvite: false,
inviter: nil,
name: "Foundation and Empire",
isDirect: false,
avatarURL: URL.picturesDirectory,
heroes: [],
lastMessage: AttributedString("How do you see the Emperor then? You think he keeps office hours?"),
lastMessageFormattedTimestamp: "2:56 PM",
unreadMessagesCount: 2,
unreadMentionsCount: 0,
unreadNotificationsCount: 2,
notificationMode: .mute,
canonicalAlias: nil,
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false),
RoomSummary(roomListItem: RoomListItemSDKMock(),
id: "3",
isInvite: false,
inviter: nil,
name: "Second Foundation",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: try? AttributedString(markdown: "He certainly seemed no *mental genius* to me"),
lastMessageFormattedTimestamp: "Some time ago",
unreadMessagesCount: 3,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .mentionsAndKeywordsOnly,
canonicalAlias: nil,
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false),
RoomSummary(roomListItem: RoomListItemSDKMock(),
id: "4",
isInvite: false,
inviter: nil,
name: "Foundation's Edge",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: AttributedString("There's an archaic measure of time that's called the month"),
lastMessageFormattedTimestamp: "Just now",
unreadMessagesCount: 2,
unreadMentionsCount: 2,
unreadNotificationsCount: 2,
notificationMode: .allMessages,
canonicalAlias: nil,
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false),
RoomSummary(roomListItem: RoomListItemSDKMock(),
id: "5",
isInvite: false,
inviter: nil,
name: "Foundation and Earth",
isDirect: true,
avatarURL: nil,
heroes: [],
lastMessage: AttributedString("Clearly, if Earth is powerful enough to do that, it might also be capable of adjusting minds in order to force belief in its radioactivity"),
lastMessageFormattedTimestamp: "1986",
unreadMessagesCount: 1,
unreadMentionsCount: 1,
unreadNotificationsCount: 1,
notificationMode: .allMessages,
canonicalAlias: nil,
hasOngoingCall: true,
isMarkedUnread: false,
isFavourite: false),
RoomSummary(roomListItem: RoomListItemSDKMock(),
id: "6",
isInvite: false,
inviter: nil,
name: "Prelude to Foundation",
isDirect: true,
avatarURL: nil,
heroes: [],
lastMessage: AttributedString("Are you groping for the word 'paranoia'?"),
lastMessageFormattedTimestamp: "きょうはじゅういちがつじゅういちにちです",
unreadMessagesCount: 6,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .mute,
canonicalAlias: nil,
hasOngoingCall: true,
isMarkedUnread: false,
isFavourite: false),
RoomSummary(roomListItem: RoomListItemSDKMock(),
id: "0",
isInvite: false,
inviter: nil,
name: "Unknown",
isDirect: false,
avatarURL: nil,
heroes: [],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: nil,
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false)
]
static let mockRoomsWithNotificationsState: [Element] = {
@@ -213,56 +219,59 @@ extension Array where Element == RoomSummary {
for hasUnreadNotifications in [false, true] {
// Incrementing id value for each combination
let id = result.count + 1
let room = RoomSummary.filled(details: RoomSummaryDetails(id: "\(id)",
settingsMode: mode,
hasUnreadMessages: hasUnreadMessages,
hasUnreadMentions: hasUnreadMentions,
hasUnreadNotifications: hasUnreadNotifications))
let room = RoomSummary(roomListItem: RoomListItemSDKMock(),
id: "\(id)",
settingsMode: mode,
hasUnreadMessages: hasUnreadMessages,
hasUnreadMentions: hasUnreadMentions,
hasUnreadNotifications: hasUnreadNotifications)
result.append(room)
}
}
}
}
return result
}()
static let mockInvites: [Element] = [
.filled(details: RoomSummaryDetails(id: "someAwesomeRoomId1",
isInvite: false,
inviter: RoomMemberProxyMock.mockCharlie,
name: "First room",
isDirect: false,
avatarURL: URL.picturesDirectory,
heroes: [],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: "#footest:somewhere.org",
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false)),
.filled(details: RoomSummaryDetails(id: "someAwesomeRoomId2",
isInvite: false,
inviter: RoomMemberProxyMock.mockCharlie,
name: "Second room",
isDirect: true,
avatarURL: nil,
heroes: [],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: nil,
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false))
RoomSummary(roomListItem: RoomListItemSDKMock(),
id: "someAwesomeRoomId1",
isInvite: false,
inviter: RoomMemberProxyMock.mockCharlie,
name: "First room",
isDirect: false,
avatarURL: URL.picturesDirectory,
heroes: [],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: "#footest:somewhere.org",
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false),
RoomSummary(roomListItem: RoomListItemSDKMock(),
id: "someAwesomeRoomId2",
isInvite: false,
inviter: RoomMemberProxyMock.mockCharlie,
name: "Second room",
isDirect: true,
avatarURL: nil,
heroes: [],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: nil,
hasOngoingCall: false,
isMarkedUnread: false,
isFavourite: false)
]
}