Bump SDK + Mention Badge fix (#2367)

This commit is contained in:
Mauro
2024-01-22 18:43:39 +01:00
committed by GitHub
parent 0fe52fe54b
commit dd28261e1f
21 changed files with 101 additions and 86 deletions
@@ -269,7 +269,7 @@ final class AppSettings {
@UserPreference(key: UserDefaultsKeys.swiftUITimelineEnabled, defaultValue: false, storageType: .volatile)
var swiftUITimelineEnabled
@UserPreference(key: UserDefaultsKeys.mentionsBadgeEnabled, defaultValue: false, storageType: .userDefaults(store))
@UserPreference(key: UserDefaultsKeys.mentionsBadgeEnabled, defaultValue: true, storageType: .userDefaults(store))
var mentionsBadgeEnabled
#endif
@@ -2159,25 +2159,25 @@ class RoomProxyMock: RoomProxyProtocol {
return uploadAvatarMediaReturnValue
}
}
//MARK: - canUserRedact
//MARK: - canUserRedactOther
var canUserRedactUserIDCallsCount = 0
var canUserRedactUserIDCalled: Bool {
return canUserRedactUserIDCallsCount > 0
var canUserRedactOtherUserIDCallsCount = 0
var canUserRedactOtherUserIDCalled: Bool {
return canUserRedactOtherUserIDCallsCount > 0
}
var canUserRedactUserIDReceivedUserID: String?
var canUserRedactUserIDReceivedInvocations: [String] = []
var canUserRedactUserIDReturnValue: Result<Bool, RoomProxyError>!
var canUserRedactUserIDClosure: ((String) async -> Result<Bool, RoomProxyError>)?
var canUserRedactOtherUserIDReceivedUserID: String?
var canUserRedactOtherUserIDReceivedInvocations: [String] = []
var canUserRedactOtherUserIDReturnValue: Result<Bool, RoomProxyError>!
var canUserRedactOtherUserIDClosure: ((String) async -> Result<Bool, RoomProxyError>)?
func canUserRedact(userID: String) async -> Result<Bool, RoomProxyError> {
canUserRedactUserIDCallsCount += 1
canUserRedactUserIDReceivedUserID = userID
canUserRedactUserIDReceivedInvocations.append(userID)
if let canUserRedactUserIDClosure = canUserRedactUserIDClosure {
return await canUserRedactUserIDClosure(userID)
func canUserRedactOther(userID: String) async -> Result<Bool, RoomProxyError> {
canUserRedactOtherUserIDCallsCount += 1
canUserRedactOtherUserIDReceivedUserID = userID
canUserRedactOtherUserIDReceivedInvocations.append(userID)
if let canUserRedactOtherUserIDClosure = canUserRedactOtherUserIDClosure {
return await canUserRedactOtherUserIDClosure(userID)
} else {
return canUserRedactUserIDReturnValue
return canUserRedactOtherUserIDReturnValue
}
}
//MARK: - canUserTriggerRoomNotification
+1 -1
View File
@@ -84,7 +84,7 @@ extension RoomProxyMock {
setNameClosure = { _ in .success(()) }
setTopicClosure = { _ in .success(()) }
getMemberUserIDReturnValue = .success(configuration.memberForID)
canUserRedactUserIDReturnValue = .success(false)
canUserRedactOtherUserIDReturnValue = .success(false)
canUserTriggerRoomNotificationUserIDReturnValue = .success(configuration.canUserTriggerRoomNotification)
canUserJoinCallUserIDReturnValue = .success(configuration.canUserJoinCall)
}
@@ -292,7 +292,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
return HomeScreenRoom(id: identifier,
roomId: details.id,
name: details.name,
hasUnreads: details.unreadMessagesCount > 0,
hasUnreads: details.unreadNotificationsCount > 0,
hasMentions: hasMentions,
hasOngoingCall: details.hasOngoingCall,
timestamp: details.lastMessageFormattedTimestamp,
@@ -225,7 +225,7 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview {
return HomeScreenRoom(id: UUID().uuidString,
roomId: details.id,
name: details.name,
hasUnreads: details.unreadMessagesCount > 0, hasMentions: details.unreadMentionsCount > 0,
hasUnreads: details.unreadNotificationsCount > 0, hasMentions: details.unreadMentionsCount > 0,
hasOngoingCall: details.hasOngoingCall,
timestamp: Date(timeIntervalSinceReferenceDate: 0).formattedMinimal(),
lastMessage: details.lastMessage,
@@ -73,7 +73,7 @@ struct InvitesScreen_Previews: PreviewProvider, TestablePreview {
NavigationView {
InvitesScreen(context: InvitesScreenViewModel.someInvite.context)
}
.snapshot(delay: 1.0)
.snapshot(delay: 2.0)
.previewDisplayName("Some Invite")
}
}
@@ -186,7 +186,7 @@ private extension InvitesScreenRoomDetails {
avatarURL: nil,
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
unreadNotificationsCount: 0,
unreadMentionsCount: 0,
notificationMode: nil,
canonicalAlias: "#footest:somewhere.org",
@@ -207,7 +207,7 @@ private extension InvitesScreenRoomDetails {
avatarURL: avatarURL,
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
unreadNotificationsCount: 0,
unreadMentionsCount: 0,
notificationMode: nil,
canonicalAlias: alias,
@@ -51,7 +51,7 @@ class RoomScreenInteractionHandler {
}
private var voiceMessageRecorderObserver: AnyCancellable?
private var canCurrentUserRedact = false
private var canCurrentUserRedactOthers = false
private var resumeVoiceMessagePlaybackAfterScrubbing = false
init(roomProxy: RoomProxyProtocol,
@@ -81,10 +81,10 @@ class RoomScreenInteractionHandler {
func showTimelineItemActionMenu(for itemID: TimelineItemIdentifier) {
Task {
if case let .success(value) = await roomProxy.canUserRedact(userID: roomProxy.ownUserID) {
canCurrentUserRedact = value
if case let .success(value) = await roomProxy.canUserRedactOther(userID: roomProxy.ownUserID) {
canCurrentUserRedactOthers = value
} else {
canCurrentUserRedact = false
canCurrentUserRedactOthers = false
}
guard let timelineItem = timelineController.timelineItems.firstUsingStableID(itemID),
@@ -604,7 +604,7 @@ class RoomScreenInteractionHandler {
// MARK: - Private
private func canRedactItem(_ item: EventBasedTimelineItemProtocol) -> Bool {
item.isOutgoing || (canCurrentUserRedact && !roomProxy.isDirect)
item.isOutgoing || (canCurrentUserRedactOthers && !roomProxy.isDirect)
}
private func buildReplyInfo(for item: EventBasedTimelineItemProtocol) -> ReplyInfo {
@@ -510,21 +510,24 @@ class ClientProxy: ClientProxyProtocol {
name: "AllRooms",
shouldUpdateVisibleRange: true,
notificationSettings: notificationSettings,
backgroundTaskService: backgroundTaskService)
backgroundTaskService: backgroundTaskService,
appSettings: appSettings)
try await roomSummaryProvider?.setRoomList(roomListService.allRooms())
messageForwardingRoomSummaryProvider = RoomSummaryProvider(roomListService: roomListService,
eventStringBuilder: eventStringBuilder,
name: "MessageForwarding",
notificationSettings: notificationSettings,
backgroundTaskService: backgroundTaskService)
backgroundTaskService: backgroundTaskService,
appSettings: appSettings)
try await messageForwardingRoomSummaryProvider?.setRoomList(roomListService.allRooms())
inviteSummaryProvider = RoomSummaryProvider(roomListService: roomListService,
eventStringBuilder: eventStringBuilder,
name: "Invites",
notificationSettings: notificationSettings,
backgroundTaskService: backgroundTaskService)
backgroundTaskService: backgroundTaskService,
appSettings: appSettings)
try await inviteSummaryProvider?.setRoomList(roomListService.invites())
self.syncService = syncService
@@ -328,9 +328,9 @@ class RoomProxy: RoomProxyProtocol {
}
}
func canUserRedact(userID: String) async -> Result<Bool, RoomProxyError> {
func canUserRedactOther(userID: String) async -> Result<Bool, RoomProxyError> {
do {
return try await .success(room.canUserRedact(userId: userID))
return try await .success(room.canUserRedactOther(userId: userID))
} catch {
MXLog.error("Failed checking if the user can redact with error: \(error)")
return .failure(.failedCheckingPermission)
@@ -97,7 +97,7 @@ protocol RoomProxyProtocol {
func uploadAvatar(media: MediaInfo) async -> Result<Void, RoomProxyError>
func canUserRedact(userID: String) async -> Result<Bool, RoomProxyError>
func canUserRedactOther(userID: String) async -> Result<Bool, RoomProxyError>
func canUserTriggerRoomNotification(userID: String) async -> Result<Bool, RoomProxyError>
@@ -83,7 +83,7 @@ extension Array where Element == RoomSummary {
avatarURL: nil,
lastMessage: AttributedString("I do not wish to take the trouble to understand mysticism"),
lastMessageFormattedTimestamp: "14:56",
unreadMessagesCount: 0,
unreadNotificationsCount: 0,
unreadMentionsCount: 0,
notificationMode: .allMessages,
canonicalAlias: nil,
@@ -95,7 +95,7 @@ extension Array where Element == RoomSummary {
avatarURL: URL.picturesDirectory,
lastMessage: AttributedString("How do you see the Emperor then? You think he keeps office hours?"),
lastMessageFormattedTimestamp: "2:56 PM",
unreadMessagesCount: 2,
unreadNotificationsCount: 2,
unreadMentionsCount: 0,
notificationMode: .mute,
canonicalAlias: nil,
@@ -107,7 +107,7 @@ extension Array where Element == RoomSummary {
avatarURL: nil,
lastMessage: try? AttributedString(markdown: "He certainly seemed no *mental genius* to me"),
lastMessageFormattedTimestamp: "Some time ago",
unreadMessagesCount: 3,
unreadNotificationsCount: 3,
unreadMentionsCount: 0,
notificationMode: .mentionsAndKeywordsOnly,
canonicalAlias: nil,
@@ -119,7 +119,7 @@ extension Array where Element == RoomSummary {
avatarURL: nil,
lastMessage: AttributedString("There's an archaic measure of time that's called the month"),
lastMessageFormattedTimestamp: "Just now",
unreadMessagesCount: 2,
unreadNotificationsCount: 2,
unreadMentionsCount: 2,
notificationMode: .allMessages,
canonicalAlias: nil,
@@ -131,7 +131,7 @@ extension Array where Element == RoomSummary {
avatarURL: nil,
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,
unreadNotificationsCount: 1,
unreadMentionsCount: 1,
notificationMode: .allMessages,
canonicalAlias: nil,
@@ -143,7 +143,7 @@ extension Array where Element == RoomSummary {
avatarURL: nil,
lastMessage: AttributedString("Are you groping for the word 'paranoia'?"),
lastMessageFormattedTimestamp: "きょうはじゅういちがつじゅういちにちです",
unreadMessagesCount: 6,
unreadNotificationsCount: 6,
unreadMentionsCount: 0,
notificationMode: .mute,
canonicalAlias: nil,
@@ -155,7 +155,7 @@ extension Array where Element == RoomSummary {
avatarURL: nil,
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
unreadNotificationsCount: 0,
unreadMentionsCount: 0,
notificationMode: nil,
canonicalAlias: nil,
@@ -167,51 +167,51 @@ extension Array where Element == RoomSummary {
static let mockRoomsWithNotificationsState: [Element] = [
.filled(details: RoomSummaryDetails(id: "1",
settingsMode: .allMessages,
hasUnreadMessages: false,
hasUnreadNotifications: false,
hasUnreadMentions: false)),
.filled(details: RoomSummaryDetails(id: "2",
settingsMode: .allMessages,
hasUnreadMessages: true,
hasUnreadNotifications: true,
hasUnreadMentions: false)),
.filled(details: RoomSummaryDetails(id: "3",
settingsMode: .allMessages,
hasUnreadMessages: true,
hasUnreadNotifications: true,
hasUnreadMentions: true)),
.filled(details: RoomSummaryDetails(id: "4",
settingsMode: .allMessages,
hasUnreadMessages: false,
hasUnreadNotifications: false,
hasUnreadMentions: true)),
.filled(details: RoomSummaryDetails(id: "5",
settingsMode: .mentionsAndKeywordsOnly,
hasUnreadMessages: false,
hasUnreadNotifications: false,
hasUnreadMentions: false)),
.filled(details: RoomSummaryDetails(id: "6",
settingsMode: .mentionsAndKeywordsOnly,
hasUnreadMessages: true,
hasUnreadNotifications: true,
hasUnreadMentions: false)),
.filled(details: RoomSummaryDetails(id: "7",
settingsMode: .mentionsAndKeywordsOnly,
hasUnreadMessages: true,
hasUnreadNotifications: true,
hasUnreadMentions: true)),
.filled(details: RoomSummaryDetails(id: "8",
settingsMode: .mentionsAndKeywordsOnly,
hasUnreadMessages: false,
hasUnreadNotifications: false,
hasUnreadMentions: true)),
.filled(details: RoomSummaryDetails(id: "9",
settingsMode: .mute,
hasUnreadMessages: false,
hasUnreadNotifications: false,
hasUnreadMentions: false)),
.filled(details: RoomSummaryDetails(id: "10",
settingsMode: .mute,
hasUnreadMessages: true,
hasUnreadNotifications: true,
hasUnreadMentions: false)),
.filled(details: RoomSummaryDetails(id: "11",
settingsMode: .mute,
hasUnreadMessages: true,
hasUnreadNotifications: true,
hasUnreadMentions: true)),
.filled(details: RoomSummaryDetails(id: "12",
settingsMode: .mute,
hasUnreadMessages: false,
hasUnreadNotifications: false,
hasUnreadMentions: true))
]
@@ -221,7 +221,7 @@ extension Array where Element == RoomSummary {
avatarURL: URL.picturesDirectory,
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
unreadNotificationsCount: 0,
unreadMentionsCount: 0,
notificationMode: nil,
canonicalAlias: "#footest:somewhere.org",
@@ -233,7 +233,7 @@ extension Array where Element == RoomSummary {
avatarURL: nil,
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
unreadNotificationsCount: 0,
unreadMentionsCount: 0,
notificationMode: nil,
canonicalAlias: nil,
@@ -24,7 +24,7 @@ struct RoomSummaryDetails {
let avatarURL: URL?
let lastMessage: AttributedString?
let lastMessageFormattedTimestamp: String?
let unreadMessagesCount: UInt
let unreadNotificationsCount: UInt
let unreadMentionsCount: UInt
let notificationMode: RoomNotificationModeProxy?
let canonicalAlias: String?
@@ -34,20 +34,20 @@ struct RoomSummaryDetails {
extension RoomSummaryDetails: CustomStringConvertible {
var description: String {
"RoomSummaryDetails: - id: \(id) - isDirect: \(isDirect) - unreadMessagesCount: \(unreadMessagesCount) - unreadMentionsCount: \(unreadMentionsCount) - notificationMode: \(notificationMode?.rawValue ?? "nil")"
"RoomSummaryDetails: - id: \(id) - isDirect: \(isDirect) - unreadNotificationsCount: \(unreadNotificationsCount) - unreadMentionsCount: \(unreadMentionsCount) - notificationMode: \(notificationMode?.rawValue ?? "nil")"
}
}
extension RoomSummaryDetails {
init(id: String, settingsMode: RoomNotificationModeProxy, hasUnreadMessages: Bool, hasUnreadMentions: Bool) {
init(id: String, settingsMode: RoomNotificationModeProxy, hasUnreadNotifications: Bool, hasUnreadMentions: Bool) {
self.id = id
let string = "\(settingsMode) - hasUnreadMessages: \(hasUnreadMessages) - hasUnreadMentions: \(hasUnreadMentions)"
let string = "\(settingsMode) - hasUnreadNotifications: \(hasUnreadNotifications) - hasUnreadMentions: \(hasUnreadMentions)"
name = string
isDirect = true
avatarURL = nil
lastMessage = AttributedString(string)
lastMessageFormattedTimestamp = "Now"
unreadMessagesCount = hasUnreadMessages ? 1 : 0
unreadNotificationsCount = hasUnreadNotifications ? 1 : 0
unreadMentionsCount = hasUnreadMentions ? 1 : 0
notificationMode = settingsMode
canonicalAlias = nil
@@ -25,6 +25,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
private let shouldUpdateVisibleRange: Bool
private let notificationSettings: NotificationSettingsProxyProtocol
private let backgroundTaskService: BackgroundTaskServiceProtocol
private let appSettings: AppSettings
private let roomListPageSize = 200
@@ -67,7 +68,8 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
name: String,
shouldUpdateVisibleRange: Bool = false,
notificationSettings: NotificationSettingsProxyProtocol,
backgroundTaskService: BackgroundTaskServiceProtocol) {
backgroundTaskService: BackgroundTaskServiceProtocol,
appSettings: AppSettings) {
self.roomListService = roomListService
serialDispatchQueue = DispatchQueue(label: "io.element.elementx.roomsummaryprovider", qos: .default)
self.eventStringBuilder = eventStringBuilder
@@ -75,6 +77,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
self.shouldUpdateVisibleRange = shouldUpdateVisibleRange
self.notificationSettings = notificationSettings
self.backgroundTaskService = backgroundTaskService
self.appSettings = appSettings
diffsPublisher
.receive(on: serialDispatchQueue)
@@ -245,7 +248,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
avatarURL: roomInfo.avatarUrl.flatMap(URL.init(string:)),
lastMessage: attributedLastMessage,
lastMessageFormattedTimestamp: lastMessageFormattedTimestamp,
unreadMessagesCount: UInt(roomInfo.notificationCount),
unreadNotificationsCount: appSettings.mentionsBadgeEnabled ? UInt(roomInfo.numUnreadNotifications) : UInt(roomInfo.notificationCount),
unreadMentionsCount: UInt(roomInfo.numUnreadMentions),
notificationMode: notificationMode,
canonicalAlias: roomInfo.canonicalAlias,