mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
* Fixes #2360 - Add support for manually marking rooms as unread * Add analytics for marking rooms as (un)read * Remove unnecessary analytics abstraction levels * Fix breaking API changes following SDK bump * Add changelog * Handle PR comments * Fix unit tests
This commit is contained in:
@@ -47,6 +47,7 @@ final class AppSettings {
|
||||
case userSuggestionsEnabled
|
||||
case mentionsBadgeEnabled
|
||||
case roomListFiltersEnabled
|
||||
case markAsUnreadEnabled
|
||||
}
|
||||
|
||||
private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier
|
||||
@@ -275,6 +276,9 @@ final class AppSettings {
|
||||
@UserPreference(key: UserDefaultsKeys.roomListFiltersEnabled, defaultValue: false, storageType: .userDefaults(store))
|
||||
var roomListFiltersEnabled
|
||||
|
||||
@UserPreference(key: UserDefaultsKeys.markAsUnreadEnabled, defaultValue: false, storageType: .userDefaults(store))
|
||||
var markAsUnreadEnabled
|
||||
|
||||
#endif
|
||||
|
||||
// MARK: - Shared
|
||||
|
||||
@@ -417,6 +417,12 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
||||
|
||||
self.roomProxy = roomProxy
|
||||
|
||||
Task {
|
||||
// Mark the room as read on entering but don't send read receipts
|
||||
// as those will be handled by the timeline
|
||||
await roomProxy.markAsRead(sendReadReceipts: false, receiptType: appSettings.sendReadReceiptsEnabled ? .read : .readPrivate)
|
||||
}
|
||||
|
||||
let userID = userSession.clientProxy.userID
|
||||
|
||||
let timelineItemFactory = RoomTimelineItemFactory(userID: userID,
|
||||
@@ -772,7 +778,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
||||
self.analytics.trackComposer(inThread: false,
|
||||
isEditing: false,
|
||||
isReply: false,
|
||||
messageType: isUserLocation ? .location(.user) : .location(.pin),
|
||||
messageType: isUserLocation ? .LocationUser : .LocationPin,
|
||||
startsThread: nil)
|
||||
case .close:
|
||||
self.navigationSplitCoordinator.setSheetCoordinator(nil)
|
||||
@@ -833,7 +839,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
||||
self.analytics.trackComposer(inThread: false,
|
||||
isEditing: false,
|
||||
isReply: false,
|
||||
messageType: .poll,
|
||||
messageType: .Poll,
|
||||
startsThread: nil)
|
||||
|
||||
self.analytics.trackPollCreated(isUndisclosed: pollKind == .undisclosed, numberOfAnswers: options.count)
|
||||
|
||||
@@ -1847,11 +1847,6 @@ class RoomProxyMock: RoomProxyProtocol {
|
||||
}
|
||||
var underlyingHasOngoingCall: Bool!
|
||||
var canonicalAlias: String?
|
||||
var hasUnreadNotifications: Bool {
|
||||
get { return underlyingHasUnreadNotifications }
|
||||
set(value) { underlyingHasUnreadNotifications = value }
|
||||
}
|
||||
var underlyingHasUnreadNotifications: Bool!
|
||||
var ownUserID: String {
|
||||
get { return underlyingOwnUserID }
|
||||
set(value) { underlyingOwnUserID = value }
|
||||
@@ -2222,6 +2217,44 @@ class RoomProxyMock: RoomProxyProtocol {
|
||||
return canUserTriggerRoomNotificationUserIDReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - markAsUnread
|
||||
|
||||
var markAsUnreadCallsCount = 0
|
||||
var markAsUnreadCalled: Bool {
|
||||
return markAsUnreadCallsCount > 0
|
||||
}
|
||||
var markAsUnreadReturnValue: Result<Void, RoomProxyError>!
|
||||
var markAsUnreadClosure: (() async -> Result<Void, RoomProxyError>)?
|
||||
|
||||
func markAsUnread() async -> Result<Void, RoomProxyError> {
|
||||
markAsUnreadCallsCount += 1
|
||||
if let markAsUnreadClosure = markAsUnreadClosure {
|
||||
return await markAsUnreadClosure()
|
||||
} else {
|
||||
return markAsUnreadReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - markAsRead
|
||||
|
||||
var markAsReadSendReadReceiptsReceiptTypeCallsCount = 0
|
||||
var markAsReadSendReadReceiptsReceiptTypeCalled: Bool {
|
||||
return markAsReadSendReadReceiptsReceiptTypeCallsCount > 0
|
||||
}
|
||||
var markAsReadSendReadReceiptsReceiptTypeReceivedArguments: (sendReadReceipts: Bool, receiptType: ReceiptType)?
|
||||
var markAsReadSendReadReceiptsReceiptTypeReceivedInvocations: [(sendReadReceipts: Bool, receiptType: ReceiptType)] = []
|
||||
var markAsReadSendReadReceiptsReceiptTypeReturnValue: Result<Void, RoomProxyError>!
|
||||
var markAsReadSendReadReceiptsReceiptTypeClosure: ((Bool, ReceiptType) async -> Result<Void, RoomProxyError>)?
|
||||
|
||||
func markAsRead(sendReadReceipts: Bool, receiptType: ReceiptType) async -> Result<Void, RoomProxyError> {
|
||||
markAsReadSendReadReceiptsReceiptTypeCallsCount += 1
|
||||
markAsReadSendReadReceiptsReceiptTypeReceivedArguments = (sendReadReceipts: sendReadReceipts, receiptType: receiptType)
|
||||
markAsReadSendReadReceiptsReceiptTypeReceivedInvocations.append((sendReadReceipts: sendReadReceipts, receiptType: receiptType))
|
||||
if let markAsReadSendReadReceiptsReceiptTypeClosure = markAsReadSendReadReceiptsReceiptTypeClosure {
|
||||
return await markAsReadSendReadReceiptsReceiptTypeClosure(sendReadReceipts, receiptType)
|
||||
} else {
|
||||
return markAsReadSendReadReceiptsReceiptTypeReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - canUserJoinCall
|
||||
|
||||
var canUserJoinCallUserIDCallsCount = 0
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated using Sourcery 2.1.2 — https://github.com/krzysztofzablocki/Sourcery
|
||||
// Generated using Sourcery 2.1.3 — https://github.com/krzysztofzablocki/Sourcery
|
||||
// DO NOT EDIT
|
||||
|
||||
// swiftlint:disable all
|
||||
|
||||
@@ -29,7 +29,6 @@ struct RoomProxyMockConfiguration {
|
||||
var isEncrypted = true
|
||||
var hasOngoingCall = true
|
||||
var canonicalAlias: String?
|
||||
var hasUnreadNotifications = Bool.random()
|
||||
|
||||
var timeline = {
|
||||
let mock = TimelineProxyMock()
|
||||
@@ -64,7 +63,6 @@ extension RoomProxyMock {
|
||||
isEncrypted = configuration.isEncrypted
|
||||
hasOngoingCall = configuration.hasOngoingCall
|
||||
canonicalAlias = configuration.canonicalAlias
|
||||
hasUnreadNotifications = configuration.hasUnreadNotifications
|
||||
|
||||
timeline = configuration.timeline
|
||||
|
||||
|
||||
@@ -14,13 +14,14 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import AnalyticsEvents
|
||||
import SwiftUI
|
||||
|
||||
/// `ScreenTrackerViewModifier` is a helper class used to track PostHog screen from SwiftUI screens.
|
||||
struct ScreenTrackerViewModifier: ViewModifier {
|
||||
@Environment(\.analyticsService) private var analyticsService
|
||||
|
||||
let screen: AnalyticsScreen
|
||||
let screen: AnalyticsEvent.MobileScreen.ScreenName
|
||||
|
||||
@ViewBuilder
|
||||
func body(content: Content) -> some View {
|
||||
@@ -32,7 +33,7 @@ struct ScreenTrackerViewModifier: ViewModifier {
|
||||
}
|
||||
|
||||
extension View {
|
||||
func track(screen: AnalyticsScreen) -> some View {
|
||||
func track(screen: AnalyticsEvent.MobileScreen.ScreenName) -> some View {
|
||||
modifier(ScreenTrackerViewModifier(screen: screen))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ private extension View {
|
||||
case .edit:
|
||||
self
|
||||
case .new:
|
||||
track(screen: .createPoll)
|
||||
track(screen: .CreatePollView)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ struct CreateRoomScreen: View {
|
||||
securitySection
|
||||
}
|
||||
.compoundList()
|
||||
.track(screen: .createRoom)
|
||||
.track(screen: .CreateRoom)
|
||||
.scrollDismissesKeyboard(.immediately)
|
||||
.navigationTitle(L10n.screenCreateRoomTitle)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
|
||||
@@ -51,6 +51,8 @@ enum HomeScreenViewAction {
|
||||
case updateVisibleItemRange(range: Range<Int>, isScrolling: Bool)
|
||||
case selectInvites
|
||||
case globalSearch
|
||||
case markRoomAsUnread(roomIdentifier: String)
|
||||
case markRoomAsRead(roomIdentifier: String)
|
||||
}
|
||||
|
||||
enum HomeScreenRoomListMode: CustomStringConvertible {
|
||||
@@ -102,7 +104,9 @@ struct HomeScreenViewState: BindableState {
|
||||
|
||||
var rooms: [HomeScreenRoom] = []
|
||||
var roomListMode: HomeScreenRoomListMode = .skeletons
|
||||
|
||||
var shouldShowFilters = false
|
||||
var markAsUnreadEnabled = false
|
||||
|
||||
var hasPendingInvitations = false
|
||||
var hasUnreadPendingInvitations = false
|
||||
@@ -153,6 +157,8 @@ struct HomeScreenRoom: Identifiable, Equatable {
|
||||
|
||||
var name = ""
|
||||
|
||||
var isMarkedUnread: Bool
|
||||
|
||||
var hasUnreadMessages = false
|
||||
|
||||
var hasUnreadMentions = false
|
||||
@@ -171,10 +177,15 @@ struct HomeScreenRoom: Identifiable, Equatable {
|
||||
|
||||
var isPlaceholder = false
|
||||
|
||||
var hasNewContent: Bool {
|
||||
hasUnreadMessages || hasUnreadMentions || hasUnreadNotifications || isMarkedUnread
|
||||
}
|
||||
|
||||
static func placeholder() -> HomeScreenRoom {
|
||||
HomeScreenRoom(id: UUID().uuidString,
|
||||
roomId: nil,
|
||||
name: "Placeholder room name",
|
||||
isMarkedUnread: false,
|
||||
hasUnreadMessages: false,
|
||||
hasUnreadMentions: false,
|
||||
hasUnreadNotifications: false,
|
||||
|
||||
@@ -86,6 +86,10 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
.weakAssign(to: \.state.shouldShowFilters, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
appSettings.$markAsUnreadEnabled
|
||||
.weakAssign(to: \.state.markAsUnreadEnabled, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
let isSearchFieldFocused = context.$viewState.map(\.bindings.isSearchFieldFocused)
|
||||
let searchQuery = context.$viewState.map(\.bindings.searchQuery)
|
||||
isSearchFieldFocused
|
||||
@@ -143,6 +147,34 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
actionsSubject.send(.presentInvitesScreen)
|
||||
case .globalSearch:
|
||||
actionsSubject.send(.presentGlobalSearch)
|
||||
case .markRoomAsUnread(let roomIdentifier):
|
||||
Task {
|
||||
guard let roomProxy = await userSession.clientProxy.roomForIdentifier(roomIdentifier) else {
|
||||
MXLog.error("Failed retrieving room for identifier: \(roomIdentifier)")
|
||||
return
|
||||
}
|
||||
|
||||
switch await roomProxy.markAsUnread() {
|
||||
case .success:
|
||||
ServiceLocator.shared.analytics.trackInteraction(name: .MobileRoomListRoomContextMenuUnreadToggle)
|
||||
case .failure(let error):
|
||||
MXLog.error("Failed marking room \(roomIdentifier) as unread with error: \(error)")
|
||||
}
|
||||
}
|
||||
case .markRoomAsRead(let roomIdentifier):
|
||||
Task {
|
||||
guard let roomProxy = await userSession.clientProxy.roomForIdentifier(roomIdentifier) else {
|
||||
MXLog.error("Failed retrieving room for identifier: \(roomIdentifier)")
|
||||
return
|
||||
}
|
||||
|
||||
switch await roomProxy.markAsRead(sendReadReceipts: true, receiptType: appSettings.sendReadReceiptsEnabled ? .read : .readPrivate) {
|
||||
case .success:
|
||||
ServiceLocator.shared.analytics.trackInteraction(name: .MobileRoomListRoomContextMenuUnreadToggle)
|
||||
case .failure(let error):
|
||||
MXLog.error("Failed marking room \(roomIdentifier) as read with error: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,6 +359,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
return HomeScreenRoom(id: identifier,
|
||||
roomId: details.id,
|
||||
name: details.name,
|
||||
isMarkedUnread: details.isMarkedUnread,
|
||||
hasUnreadMessages: details.unreadMessagesCount > 0,
|
||||
hasUnreadMentions: details.unreadMentionsCount > 0,
|
||||
hasUnreadNotifications: details.unreadNotificationsCount > 0,
|
||||
|
||||
@@ -40,7 +40,7 @@ struct HomeScreen: View {
|
||||
.navigationTitle(L10n.screenRoomlistMainSpaceTitle)
|
||||
.toolbar { toolbar }
|
||||
.background(Color.compound.bgCanvasDefault.ignoresSafeArea())
|
||||
.track(screen: .home)
|
||||
.track(screen: .Home)
|
||||
.introspect(.viewController, on: .supportedVersions) { controller in
|
||||
Task {
|
||||
if bloomView == nil {
|
||||
|
||||
@@ -133,7 +133,7 @@ struct HomeScreenRoomCell: View {
|
||||
.foregroundColor(.compound.iconAccentTertiary)
|
||||
}
|
||||
|
||||
if hasNewContent {
|
||||
if room.hasNewContent {
|
||||
Circle()
|
||||
.frame(width: 12, height: 12)
|
||||
.foregroundColor(isHighlighted ? .compound.iconAccentTertiary : .compound.iconQuaternary)
|
||||
@@ -141,21 +141,15 @@ struct HomeScreenRoomCell: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var hasNewContent: Bool {
|
||||
room.hasUnreadMessages ||
|
||||
room.hasUnreadMentions ||
|
||||
room.hasUnreadNotifications
|
||||
}
|
||||
|
||||
|
||||
private var isHighlighted: Bool {
|
||||
guard !room.isPlaceholder &&
|
||||
room.notificationMode != .mute else {
|
||||
guard !room.isPlaceholder && room.notificationMode != .mute else {
|
||||
return false
|
||||
}
|
||||
return room.hasUnreadNotifications || room.hasUnreadMentions
|
||||
}
|
||||
|
||||
return room.hasUnreadNotifications || room.hasUnreadMentions || room.isMarkedUnread
|
||||
}
|
||||
|
||||
private var mentionIcon: some View {
|
||||
CompoundIcon(\.mention, size: .custom(15), relativeTo: .compound.bodyMD)
|
||||
.accessibilityLabel(L10n.a11yNotificationsMentionsOnly)
|
||||
@@ -223,6 +217,7 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview {
|
||||
return HomeScreenRoom(id: UUID().uuidString,
|
||||
roomId: details.id,
|
||||
name: details.name,
|
||||
isMarkedUnread: details.isMarkedUnread,
|
||||
hasUnreadMessages: details.unreadMessagesCount > 0,
|
||||
hasUnreadMentions: details.unreadMentionsCount > 0,
|
||||
hasUnreadNotifications: details.unreadNotificationsCount > 0,
|
||||
|
||||
@@ -44,8 +44,25 @@ struct HomeScreenRoomList: View {
|
||||
.redacted(reason: .placeholder)
|
||||
} else {
|
||||
let isSelected = context.viewState.selectedRoomID == room.id
|
||||
|
||||
HomeScreenRoomCell(room: room, context: context, isSelected: isSelected)
|
||||
.contextMenu {
|
||||
if context.viewState.markAsUnreadEnabled {
|
||||
if room.hasNewContent {
|
||||
Button {
|
||||
context.send(viewAction: .markRoomAsRead(roomIdentifier: room.id))
|
||||
} label: {
|
||||
Text(L10n.screenRoomlistMarkAsRead)
|
||||
}
|
||||
} else {
|
||||
Button {
|
||||
context.send(viewAction: .markRoomAsUnread(roomIdentifier: room.id))
|
||||
} label: {
|
||||
Text(L10n.screenRoomlistMarkAsUnread)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
context.send(viewAction: .showRoomDetails(roomIdentifier: room.id))
|
||||
} label: {
|
||||
|
||||
@@ -24,7 +24,7 @@ struct InvitesScreen: View {
|
||||
.background(Color.compound.bgCanvasDefault.ignoresSafeArea())
|
||||
.navigationTitle(L10n.actionInvitesList)
|
||||
.alert(item: $context.alertInfo)
|
||||
.track(screen: .invites)
|
||||
.track(screen: .Invites)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@@ -186,6 +186,7 @@ private extension InvitesScreenRoomDetails {
|
||||
avatarURL: nil,
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
isMarkedUnread: false,
|
||||
unreadMessagesCount: 0,
|
||||
unreadMentionsCount: 0,
|
||||
unreadNotificationsCount: 0,
|
||||
@@ -208,6 +209,7 @@ private extension InvitesScreenRoomDetails {
|
||||
avatarURL: avatarURL,
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
isMarkedUnread: false,
|
||||
unreadMessagesCount: 0,
|
||||
unreadMentionsCount: 0,
|
||||
unreadNotificationsCount: 0,
|
||||
|
||||
@@ -34,7 +34,7 @@ struct StaticLocationScreen: View {
|
||||
}
|
||||
mapView
|
||||
}
|
||||
.track(screen: context.viewState.isLocationPickerMode ? .locationSend : .locationView)
|
||||
.track(screen: context.viewState.isLocationPickerMode ? .LocationSend : .LocationView)
|
||||
.navigationTitle(context.viewState.navigationTitle)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar { toolbar }
|
||||
|
||||
@@ -37,7 +37,7 @@ struct RoomDetailsEditScreen: View {
|
||||
.navigationTitle(L10n.screenRoomDetailsEditRoomTitle)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar { toolbar }
|
||||
.track(screen: .roomSettings)
|
||||
.track(screen: .RoomSettings)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@@ -61,7 +61,7 @@ struct RoomDetailsScreen: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.track(screen: .roomDetails)
|
||||
.track(screen: .RoomDetails)
|
||||
.interactiveQuickLook(item: $context.mediaPreviewItem, shouldHideControls: true)
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ struct RoomMemberDetailsScreen: View {
|
||||
.compoundList()
|
||||
.alert(item: $context.ignoreUserAlert, actions: blockUserAlertActions, message: blockUserAlertMessage)
|
||||
.alert(item: $context.alertInfo)
|
||||
.track(screen: .user)
|
||||
.track(screen: .User)
|
||||
.interactiveQuickLook(item: $context.mediaPreviewItem, shouldHideControls: true)
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ struct RoomMembersListScreen: View {
|
||||
inviteButton
|
||||
}
|
||||
}
|
||||
.track(screen: .roomMembers)
|
||||
.track(screen: .RoomMembers)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ struct RoomNotificationSettingsScreen: View {
|
||||
.compoundList()
|
||||
.navigationTitle(context.viewState.navigationTitle)
|
||||
.alert(item: $context.alertInfo)
|
||||
.track(screen: .roomNotifications)
|
||||
.track(screen: .RoomNotifications)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ struct RoomNotificationSettingsUserDefinedScreen: View {
|
||||
.compoundList()
|
||||
.navigationTitle(context.viewState.navigationTitle)
|
||||
.alert(item: $context.alertInfo)
|
||||
.track(screen: .roomNotifications)
|
||||
.track(screen: .RoomNotifications)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@@ -428,7 +428,7 @@ class RoomScreenInteractionHandler {
|
||||
analyticsService.trackComposer(inThread: false,
|
||||
isEditing: false,
|
||||
isReply: false,
|
||||
messageType: .voiceMessage,
|
||||
messageType: .VoiceMessage,
|
||||
startsThread: nil)
|
||||
|
||||
actionsSubject.send(.composer(action: .setMode(mode: .previewVoiceMessage(state: audioPlayerState, waveform: .url(recordingURL), isUploading: true))))
|
||||
|
||||
@@ -70,7 +70,7 @@ struct RoomScreen: View {
|
||||
.environmentObject(context)
|
||||
}
|
||||
.interactiveQuickLook(item: $context.mediaPreviewItem)
|
||||
.track(screen: .room)
|
||||
.track(screen: .Room)
|
||||
.onDrop(of: ["public.item", "public.file-url"], isTargeted: $dragOver) { providers -> Bool in
|
||||
guard let provider = providers.first,
|
||||
provider.isSupportedForPasteOrDrop else {
|
||||
|
||||
+1
@@ -50,6 +50,7 @@ protocol DeveloperOptionsProtocol: AnyObject {
|
||||
var userSuggestionsEnabled: Bool { get set }
|
||||
var mentionsBadgeEnabled: Bool { get set }
|
||||
var roomListFiltersEnabled: Bool { get set }
|
||||
var markAsUnreadEnabled: Bool { get set }
|
||||
|
||||
var elementCallBaseURL: URL { get set }
|
||||
}
|
||||
|
||||
+4
@@ -55,6 +55,10 @@ struct DeveloperOptionsScreen: View {
|
||||
Toggle(isOn: $context.roomListFiltersEnabled) {
|
||||
Text("Show filters")
|
||||
}
|
||||
|
||||
Toggle(isOn: $context.markAsUnreadEnabled) {
|
||||
Text("Mark as unread")
|
||||
}
|
||||
}
|
||||
|
||||
Section("Element Call") {
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ struct NotificationSettingsEditScreen: View {
|
||||
.compoundList()
|
||||
.navigationTitle(context.viewState.strings.navigationTitle)
|
||||
.alert(item: $context.alertInfo)
|
||||
.track(screen: .settingsDefaultNotifications)
|
||||
.track(screen: .SettingsDefaultNotifications)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ struct NotificationSettingsScreen: View {
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar { toolbar }
|
||||
.alert(item: $context.alertInfo)
|
||||
.track(screen: .settingsNotifications)
|
||||
.track(screen: .SettingsNotifications)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@@ -29,7 +29,7 @@ struct StartChatScreen: View {
|
||||
}
|
||||
}
|
||||
.compoundList()
|
||||
.track(screen: .startChat)
|
||||
.track(screen: .StartChat)
|
||||
.scrollDismissesKeyboard(.immediately)
|
||||
.navigationTitle(L10n.actionStartChat)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import AnalyticsEvents
|
||||
|
||||
enum AnalyticsMessageType {
|
||||
case location(LocationType)
|
||||
case poll
|
||||
case text
|
||||
case voiceMessage
|
||||
|
||||
enum LocationType {
|
||||
case pin
|
||||
case user
|
||||
}
|
||||
}
|
||||
|
||||
extension AnalyticsEvent.Composer.MessageType {
|
||||
init(_ analyticsMessageType: AnalyticsMessageType) {
|
||||
switch analyticsMessageType {
|
||||
case .location(let locationType):
|
||||
self = .init(locationType)
|
||||
case .poll:
|
||||
self = .Poll
|
||||
case .text:
|
||||
self = .Text
|
||||
case .voiceMessage:
|
||||
self = .VoiceMessage
|
||||
}
|
||||
}
|
||||
|
||||
private init(_ locationType: AnalyticsMessageType.LocationType) {
|
||||
switch locationType {
|
||||
case .pin:
|
||||
self = .LocationPin
|
||||
case .user:
|
||||
self = .LocationUser
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import AnalyticsEvents
|
||||
import Foundation
|
||||
|
||||
enum AnalyticsScreen: Int {
|
||||
case welcome
|
||||
case login
|
||||
case register
|
||||
case forgotPassword
|
||||
case sidebar
|
||||
case home
|
||||
case favourites
|
||||
case people
|
||||
case rooms
|
||||
case searchRooms
|
||||
case searchMessages
|
||||
case searchPeople
|
||||
case searchFiles
|
||||
case room
|
||||
case roomPreview
|
||||
case roomDetails
|
||||
case roomMembers
|
||||
case user
|
||||
case roomSearch
|
||||
case roomUploads
|
||||
case roomSettings
|
||||
case roomNotifications
|
||||
case roomDirectory
|
||||
case switchDirectory
|
||||
case startChat
|
||||
case createRoom
|
||||
case settings
|
||||
case settingsSecurity
|
||||
case settingsDefaultNotifications
|
||||
case settingsMentionsAndKeywords
|
||||
case settingsNotifications
|
||||
case deactivateAccount
|
||||
case inviteFriends
|
||||
case threadList
|
||||
case spaceMenu
|
||||
case spaceMembers
|
||||
case spaceExploreRooms
|
||||
case dialpad
|
||||
case spaceBottomSheet
|
||||
case invites
|
||||
case createSpace
|
||||
case locationSend
|
||||
case locationView
|
||||
case createPoll
|
||||
|
||||
/// The screen name reported to the AnalyticsEvent.
|
||||
var screenName: AnalyticsEvent.MobileScreen.ScreenName {
|
||||
switch self {
|
||||
case .welcome:
|
||||
return .Welcome
|
||||
case .login:
|
||||
return .Login
|
||||
case .register:
|
||||
return .Register
|
||||
case .forgotPassword:
|
||||
return .ForgotPassword
|
||||
case .sidebar:
|
||||
return .Sidebar
|
||||
case .home:
|
||||
return .Home
|
||||
case .favourites:
|
||||
return .Favourites
|
||||
case .people:
|
||||
return .People
|
||||
case .rooms:
|
||||
return .Rooms
|
||||
case .searchRooms:
|
||||
return .SearchRooms
|
||||
case .searchMessages:
|
||||
return .SearchMessages
|
||||
case .searchPeople:
|
||||
return .SearchPeople
|
||||
case .searchFiles:
|
||||
return .SearchFiles
|
||||
case .room:
|
||||
return .Room
|
||||
case .roomDetails:
|
||||
return .RoomDetails
|
||||
case .roomMembers:
|
||||
return .RoomMembers
|
||||
case .user:
|
||||
return .User
|
||||
case .roomPreview:
|
||||
return .RoomPreview
|
||||
case .roomSearch:
|
||||
return .RoomSearch
|
||||
case .roomUploads:
|
||||
return .RoomUploads
|
||||
case .roomSettings:
|
||||
return .RoomSettings
|
||||
case .roomNotifications:
|
||||
return .RoomNotifications
|
||||
case .roomDirectory:
|
||||
return .RoomDirectory
|
||||
case .switchDirectory:
|
||||
return .SwitchDirectory
|
||||
case .startChat:
|
||||
return .StartChat
|
||||
case .createRoom:
|
||||
return .CreateRoom
|
||||
case .settings:
|
||||
return .Settings
|
||||
case .settingsSecurity:
|
||||
return .SettingsSecurity
|
||||
case .settingsDefaultNotifications:
|
||||
return .SettingsDefaultNotifications
|
||||
case .settingsMentionsAndKeywords:
|
||||
return .SettingsMentionsAndKeywords
|
||||
case .settingsNotifications:
|
||||
return .SettingsNotifications
|
||||
case .deactivateAccount:
|
||||
return .DeactivateAccount
|
||||
case .inviteFriends:
|
||||
return .InviteFriends
|
||||
case .threadList:
|
||||
return .ThreadList
|
||||
case .spaceMenu:
|
||||
return .SpaceMenu
|
||||
case .spaceMembers:
|
||||
return .SpaceMembers
|
||||
case .spaceExploreRooms:
|
||||
return .SpaceExploreRooms
|
||||
case .dialpad:
|
||||
return .Dialpad
|
||||
case .spaceBottomSheet:
|
||||
return .SpaceBottomSheet
|
||||
case .invites:
|
||||
return .Invites
|
||||
case .createSpace:
|
||||
return .CreateSpace
|
||||
case .locationSend:
|
||||
return .LocationSend
|
||||
case .locationView:
|
||||
return .LocationView
|
||||
case .createPoll:
|
||||
return .CreatePollView
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,11 +121,15 @@ extension AnalyticsService {
|
||||
/// Track the presentation of a screen
|
||||
/// - Parameter screen: The screen that was shown
|
||||
/// - Parameter duration: An optional value representing how long the screen was shown for in milliseconds.
|
||||
func track(screen: AnalyticsScreen, duration milliseconds: Int? = nil) {
|
||||
func track(screen: AnalyticsEvent.MobileScreen.ScreenName, duration milliseconds: Int? = nil) {
|
||||
MXLog.debug("\(screen)")
|
||||
let event = AnalyticsEvent.MobileScreen(durationMs: milliseconds, screenName: screen.screenName)
|
||||
let event = AnalyticsEvent.MobileScreen(durationMs: milliseconds, screenName: screen)
|
||||
client.screen(event)
|
||||
}
|
||||
|
||||
func trackInteraction(index: Int? = nil, name: AnalyticsEvent.Interaction.Name) {
|
||||
capture(event: AnalyticsEvent.Interaction(index: index, interactionType: .Touch, name: name))
|
||||
}
|
||||
|
||||
/// Track the creation of a room
|
||||
/// - Parameter isDM: true if the created room is a direct message, false otherwise
|
||||
@@ -143,12 +147,12 @@ extension AnalyticsService {
|
||||
func trackComposer(inThread: Bool,
|
||||
isEditing: Bool,
|
||||
isReply: Bool,
|
||||
messageType: AnalyticsMessageType = .text,
|
||||
messageType: AnalyticsEvent.Composer.MessageType = .Text,
|
||||
startsThread: Bool?) {
|
||||
capture(event: AnalyticsEvent.Composer(inThread: inThread,
|
||||
isEditing: isEditing,
|
||||
isReply: isReply,
|
||||
messageType: .init(messageType),
|
||||
messageType: messageType,
|
||||
startsThread: startsThread))
|
||||
}
|
||||
|
||||
|
||||
@@ -587,20 +587,20 @@ class ClientProxy: ClientProxyProtocol {
|
||||
}
|
||||
|
||||
private let eventFilters: TimelineEventTypeFilter = {
|
||||
let stateEventFilters: [FilterStateEventType] = [.roomAliases,
|
||||
.roomCanonicalAlias,
|
||||
.roomGuestAccess,
|
||||
.roomHistoryVisibility,
|
||||
.roomJoinRules,
|
||||
.roomPinnedEvents,
|
||||
.roomPowerLevels,
|
||||
.roomServerAcl,
|
||||
.roomTombstone,
|
||||
.spaceChild,
|
||||
.spaceParent,
|
||||
.policyRuleRoom,
|
||||
.policyRuleServer,
|
||||
.policyRuleUser]
|
||||
let stateEventFilters: [StateEventType] = [.roomAliases,
|
||||
.roomCanonicalAlias,
|
||||
.roomGuestAccess,
|
||||
.roomHistoryVisibility,
|
||||
.roomJoinRules,
|
||||
.roomPinnedEvents,
|
||||
.roomPowerLevels,
|
||||
.roomServerAcl,
|
||||
.roomTombstone,
|
||||
.spaceChild,
|
||||
.spaceParent,
|
||||
.policyRuleRoom,
|
||||
.policyRuleServer,
|
||||
.policyRuleUser]
|
||||
|
||||
return .exclude(eventTypes: stateEventFilters.map { FilterTimelineEventType.state(eventType: $0) })
|
||||
}()
|
||||
|
||||
@@ -45,18 +45,24 @@ class RoomProxy: RoomProxyProtocol {
|
||||
var actions: AnyPublisher<RoomProxyAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
|
||||
var ownUserID: String {
|
||||
room.ownUserId()
|
||||
}
|
||||
|
||||
init(roomListItem: RoomListItemProtocol,
|
||||
room: RoomProtocol,
|
||||
backgroundTaskService: BackgroundTaskServiceProtocol) async {
|
||||
|
||||
init?(roomListItem: RoomListItemProtocol,
|
||||
room: RoomProtocol,
|
||||
backgroundTaskService: BackgroundTaskServiceProtocol) async {
|
||||
self.roomListItem = roomListItem
|
||||
self.room = room
|
||||
self.backgroundTaskService = backgroundTaskService
|
||||
timeline = await TimelineProxy(timeline: room.timeline(), backgroundTaskService: backgroundTaskService)
|
||||
|
||||
do {
|
||||
timeline = try await TimelineProxy(timeline: room.timeline(), backgroundTaskService: backgroundTaskService)
|
||||
} catch {
|
||||
MXLog.error("Failed creating timeline with error: \(error)")
|
||||
return nil
|
||||
}
|
||||
|
||||
Task {
|
||||
await updateMembers()
|
||||
@@ -124,11 +130,7 @@ class RoomProxy: RoomProxyProtocol {
|
||||
var canonicalAlias: String? {
|
||||
room.canonicalAlias()
|
||||
}
|
||||
|
||||
var hasUnreadNotifications: Bool {
|
||||
roomListItem.hasUnreadNotifications()
|
||||
}
|
||||
|
||||
|
||||
var avatarURL: URL? {
|
||||
roomListItem.avatarUrl().flatMap(URL.init(string:))
|
||||
}
|
||||
@@ -352,6 +354,37 @@ class RoomProxy: RoomProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func markAsUnread() async -> Result<Void, RoomProxyError> {
|
||||
MXLog.info("Marking room \(id) as unread")
|
||||
|
||||
do {
|
||||
try await room.markAsUnread()
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed marking room \(id) as unread with error: \(error)")
|
||||
return .failure(.failedMarkingAsUnread)
|
||||
}
|
||||
}
|
||||
|
||||
func markAsRead(sendReadReceipts: Bool, receiptType: ReceiptType) async -> Result<Void, RoomProxyError> {
|
||||
MXLog.info("Marking room \(id) as read, sending read receipts: \(sendReadReceipts)")
|
||||
|
||||
do {
|
||||
if sendReadReceipts {
|
||||
try await room.markAsReadAndSendReadReceipt(receiptType: receiptType)
|
||||
} else {
|
||||
try await room.markAsRead()
|
||||
}
|
||||
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed marking room \(id) as read with error: \(error)")
|
||||
return .failure(.failedMarkingAsRead)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Element Call
|
||||
|
||||
func canUserJoinCall(userID: String) async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.canUserSendState(userId: userID, stateEvent: .callMember))
|
||||
@@ -361,8 +394,6 @@ class RoomProxy: RoomProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Element Call
|
||||
|
||||
func elementCallWidgetDriver() -> ElementCallWidgetDriverProtocol {
|
||||
ElementCallWidgetDriver(room: room)
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ enum RoomProxyError: Error, Equatable {
|
||||
case failedRemovingAvatar
|
||||
case failedUploadingAvatar
|
||||
case failedCheckingPermission
|
||||
case failedMarkingAsRead
|
||||
case failedMarkingAsUnread
|
||||
}
|
||||
|
||||
enum RoomProxyAction {
|
||||
@@ -47,7 +49,6 @@ protocol RoomProxyProtocol {
|
||||
var membership: Membership { get }
|
||||
var hasOngoingCall: Bool { get }
|
||||
var canonicalAlias: String? { get }
|
||||
var hasUnreadNotifications: Bool { get }
|
||||
var ownUserID: String { get }
|
||||
|
||||
var name: String? { get }
|
||||
@@ -103,10 +104,14 @@ protocol RoomProxyProtocol {
|
||||
|
||||
func canUserTriggerRoomNotification(userID: String) async -> Result<Bool, RoomProxyError>
|
||||
|
||||
func canUserJoinCall(userID: String) async -> Result<Bool, RoomProxyError>
|
||||
func markAsUnread() async -> Result<Void, RoomProxyError>
|
||||
|
||||
func markAsRead(sendReadReceipts: Bool, receiptType: ReceiptType) async -> Result<Void, RoomProxyError>
|
||||
|
||||
// MARK: - Element Call
|
||||
|
||||
func canUserJoinCall(userID: String) async -> Result<Bool, RoomProxyError>
|
||||
|
||||
func elementCallWidgetDriver() -> ElementCallWidgetDriverProtocol
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +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",
|
||||
isMarkedUnread: false,
|
||||
unreadMessagesCount: 0,
|
||||
unreadMentionsCount: 0,
|
||||
unreadNotificationsCount: 0,
|
||||
@@ -96,6 +97,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",
|
||||
isMarkedUnread: false,
|
||||
unreadMessagesCount: 2,
|
||||
unreadMentionsCount: 0,
|
||||
unreadNotificationsCount: 2,
|
||||
@@ -109,6 +111,7 @@ extension Array where Element == RoomSummary {
|
||||
avatarURL: nil,
|
||||
lastMessage: try? AttributedString(markdown: "He certainly seemed no *mental genius* to me"),
|
||||
lastMessageFormattedTimestamp: "Some time ago",
|
||||
isMarkedUnread: false,
|
||||
unreadMessagesCount: 3,
|
||||
unreadMentionsCount: 0,
|
||||
unreadNotificationsCount: 0,
|
||||
@@ -122,6 +125,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",
|
||||
isMarkedUnread: false,
|
||||
unreadMessagesCount: 2,
|
||||
unreadMentionsCount: 2,
|
||||
unreadNotificationsCount: 2,
|
||||
@@ -135,6 +139,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",
|
||||
isMarkedUnread: false,
|
||||
unreadMessagesCount: 1,
|
||||
unreadMentionsCount: 1,
|
||||
unreadNotificationsCount: 1,
|
||||
@@ -148,6 +153,7 @@ extension Array where Element == RoomSummary {
|
||||
avatarURL: nil,
|
||||
lastMessage: AttributedString("Are you groping for the word 'paranoia'?"),
|
||||
lastMessageFormattedTimestamp: "きょうはじゅういちがつじゅういちにちです",
|
||||
isMarkedUnread: false,
|
||||
unreadMessagesCount: 6,
|
||||
unreadMentionsCount: 0,
|
||||
unreadNotificationsCount: 0,
|
||||
@@ -161,6 +167,7 @@ extension Array where Element == RoomSummary {
|
||||
avatarURL: nil,
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
isMarkedUnread: false,
|
||||
unreadMessagesCount: 0,
|
||||
unreadMentionsCount: 0,
|
||||
unreadNotificationsCount: 0,
|
||||
@@ -206,6 +213,7 @@ extension Array where Element == RoomSummary {
|
||||
avatarURL: URL.picturesDirectory,
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
isMarkedUnread: false,
|
||||
unreadMessagesCount: 0,
|
||||
unreadMentionsCount: 0,
|
||||
unreadNotificationsCount: 0,
|
||||
@@ -219,6 +227,7 @@ extension Array where Element == RoomSummary {
|
||||
avatarURL: nil,
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
isMarkedUnread: false,
|
||||
unreadMessagesCount: 0,
|
||||
unreadMentionsCount: 0,
|
||||
unreadNotificationsCount: 0,
|
||||
|
||||
@@ -24,6 +24,7 @@ struct RoomSummaryDetails {
|
||||
let avatarURL: URL?
|
||||
let lastMessage: AttributedString?
|
||||
let lastMessageFormattedTimestamp: String?
|
||||
let isMarkedUnread: Bool
|
||||
let unreadMessagesCount: UInt
|
||||
let unreadMentionsCount: UInt
|
||||
let unreadNotificationsCount: UInt
|
||||
@@ -54,6 +55,7 @@ extension RoomSummaryDetails {
|
||||
avatarURL = nil
|
||||
lastMessage = AttributedString(string)
|
||||
lastMessageFormattedTimestamp = "Now"
|
||||
isMarkedUnread = false
|
||||
unreadMessagesCount = hasUnreadMessages ? 1 : 0
|
||||
unreadMentionsCount = hasUnreadMentions ? 1 : 0
|
||||
unreadNotificationsCount = hasUnreadNotifications ? 1 : 0
|
||||
|
||||
@@ -248,6 +248,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
avatarURL: roomInfo.avatarUrl.flatMap(URL.init(string:)),
|
||||
lastMessage: attributedLastMessage,
|
||||
lastMessageFormattedTimestamp: lastMessageFormattedTimestamp,
|
||||
isMarkedUnread: appSettings.markAsUnreadEnabled ? roomInfo.isMarkedUnread : false,
|
||||
unreadMessagesCount: appSettings.mentionsBadgeEnabled ? UInt(roomInfo.numUnreadMessages) : 0,
|
||||
unreadMentionsCount: appSettings.mentionsBadgeEnabled ? UInt(roomInfo.numUnreadMentions) : 0,
|
||||
unreadNotificationsCount: appSettings.mentionsBadgeEnabled ? UInt(roomInfo.numUnreadNotifications) : UInt(roomInfo.notificationCount),
|
||||
|
||||
@@ -92,8 +92,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
}
|
||||
|
||||
func sendReadReceipt(for itemID: TimelineItemIdentifier) async -> Result<Void, RoomTimelineControllerError> {
|
||||
guard roomProxy.hasUnreadNotifications,
|
||||
let eventID = itemID.eventID
|
||||
guard let eventID = itemID.eventID
|
||||
else { return .success(()) }
|
||||
|
||||
switch await roomProxy.timeline.sendReadReceipt(for: eventID,
|
||||
|
||||
Reference in New Issue
Block a user