Filters, Mark Unread/Read/Favourites FF removals + code and tests clean up (#2541)

This commit is contained in:
Mauro
2024-03-07 17:56:09 +01:00
committed by GitHub
parent da0fcfe052
commit c66ddfb71e
69 changed files with 105 additions and 374 deletions
@@ -18,16 +18,9 @@ import Foundation
import MatrixRustSDK
final class RoomMemberProxy: RoomMemberProxyProtocol {
private let backgroundTaskService: BackgroundTaskServiceProtocol
private let member: RoomMember
private let backgroundAccountDataTaskName = "SendAccountDataEvent"
private var sendAccountDataEventBackgroundTask: BackgroundTaskProtocol?
private let userInitiatedDispatchQueue = DispatchQueue(label: "io.element.elementx.roommemberproxy.userinitiated", qos: .userInitiated)
init(member: RoomMember, backgroundTaskService: BackgroundTaskServiceProtocol) {
self.backgroundTaskService = backgroundTaskService
init(member: RoomMember) {
self.member = member
}
@@ -17,11 +17,6 @@
import Foundation
import MatrixRustSDK
enum RoomMemberProxyError: Error {
case ignoreUserFailed
case unignoreUserFailed
}
// sourcery: AutoMockable
protocol RoomMemberProxyProtocol: AnyObject {
var userID: String { get }
@@ -195,9 +195,7 @@ class RoomProxy: RoomProxyProtocol {
do {
let membersNoSyncIterator = try await room.membersNoSync()
if let members = membersNoSyncIterator.nextChunk(chunkSize: membersNoSyncIterator.len()) {
membersSubject.value = members.map {
RoomMemberProxy(member: $0, backgroundTaskService: self.backgroundTaskService)
}
membersSubject.value = members.map(RoomMemberProxy.init)
}
} catch {
MXLog.error("[RoomProxy] Failed to update members using no sync API: \(error)")
@@ -207,9 +205,7 @@ class RoomProxy: RoomProxyProtocol {
// Then we update members using the sync API, this is slower but will get us the latest members
let membersIterator = try await room.members()
if let members = membersIterator.nextChunk(chunkSize: membersIterator.len()) {
membersSubject.value = members.map {
RoomMemberProxy(member: $0, backgroundTaskService: self.backgroundTaskService)
}
membersSubject.value = members.map(RoomMemberProxy.init)
}
} catch {
MXLog.error("[RoomProxy] Failed to update members using sync API: \(error)")
@@ -228,7 +224,7 @@ class RoomProxy: RoomProxyProtocol {
do {
let member = try await room.member(userId: userID)
return .success(RoomMemberProxy(member: member, backgroundTaskService: backgroundTaskService))
return .success(RoomMemberProxy(member: member))
} catch {
return .failure(.failedRetrievingMember)
}
@@ -21,7 +21,6 @@ import MatrixRustSDK
enum RoomProxyError: Error, Equatable {
case failedRedactingEvent
case failedReportingContent
case failedIgnoringUser
case failedRetrievingMember
case failedLeavingRoom
case failedAcceptingInvite
@@ -24,9 +24,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
private let name: String
private let shouldUpdateVisibleRange: Bool
private let notificationSettings: NotificationSettingsProxyProtocol
private let backgroundTaskService: BackgroundTaskServiceProtocol
private let appSettings: AppSettings
private let roomListPageSize = 200
private let serialDispatchQueue: DispatchQueue
@@ -67,17 +65,13 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
eventStringBuilder: RoomEventStringBuilder,
name: String,
shouldUpdateVisibleRange: Bool = false,
notificationSettings: NotificationSettingsProxyProtocol,
backgroundTaskService: BackgroundTaskServiceProtocol,
appSettings: AppSettings) {
notificationSettings: NotificationSettingsProxyProtocol) {
self.roomListService = roomListService
serialDispatchQueue = DispatchQueue(label: "io.element.elementx.roomsummaryprovider", qos: .default)
self.eventStringBuilder = eventStringBuilder
self.name = name
self.shouldUpdateVisibleRange = shouldUpdateVisibleRange
self.notificationSettings = notificationSettings
self.backgroundTaskService = backgroundTaskService
self.appSettings = appSettings
diffsPublisher
.receive(on: serialDispatchQueue)
@@ -240,7 +234,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
var inviterProxy: RoomMemberProxyProtocol?
if let inviter = roomInfo.inviter {
inviterProxy = RoomMemberProxy(member: inviter, backgroundTaskService: backgroundTaskService)
inviterProxy = RoomMemberProxy(member: inviter)
}
let notificationMode = roomInfo.userDefinedNotificationMode.flatMap { RoomNotificationModeProxy.from(roomNotificationMode: $0) }
@@ -251,14 +245,14 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
avatarURL: roomInfo.avatarUrl.flatMap(URL.init(string:)),
lastMessage: attributedLastMessage,
lastMessageFormattedTimestamp: lastMessageFormattedTimestamp,
unreadMessagesCount: appSettings.mentionsBadgeEnabled ? UInt(roomInfo.numUnreadMessages) : 0,
unreadMentionsCount: appSettings.mentionsBadgeEnabled ? UInt(roomInfo.numUnreadMentions) : 0,
unreadNotificationsCount: appSettings.mentionsBadgeEnabled ? UInt(roomInfo.numUnreadNotifications) : UInt(roomInfo.notificationCount),
unreadMessagesCount: UInt(roomInfo.numUnreadMessages),
unreadMentionsCount: UInt(roomInfo.numUnreadMentions),
unreadNotificationsCount: UInt(roomInfo.numUnreadNotifications),
notificationMode: notificationMode,
canonicalAlias: roomInfo.canonicalAlias,
inviter: inviterProxy,
hasOngoingCall: roomInfo.hasRoomCall,
isMarkedUnread: appSettings.markAsUnreadEnabled ? roomInfo.isMarkedUnread : false,
isMarkedUnread: roomInfo.isMarkedUnread,
isFavourite: roomInfo.isFavourite)
return invalidated ? .invalidated(details: details) : .filled(details: details)