mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
added an alert before creating a new DM
This commit is contained in:
@@ -840,6 +840,9 @@
|
|||||||
"screen_room_error_failed_retrieving_user_details" = "Could not retrieve user details";
|
"screen_room_error_failed_retrieving_user_details" = "Could not retrieve user details";
|
||||||
"screen_room_invite_again_alert_message" = "Would you like to invite them back?";
|
"screen_room_invite_again_alert_message" = "Would you like to invite them back?";
|
||||||
"screen_room_invite_again_alert_title" = "You are alone in this chat";
|
"screen_room_invite_again_alert_title" = "You are alone in this chat";
|
||||||
|
"screen_room_member_details_alert_create_dm_confirmation_title" = "Send invite";
|
||||||
|
"screen_room_member_details_alert_create_dm_message" = "Would you like to start a chat with %1$@?";
|
||||||
|
"screen_room_member_details_alert_create_dm_title" = "Send invite?";
|
||||||
"screen_room_member_details_block_alert_action" = "Block";
|
"screen_room_member_details_block_alert_action" = "Block";
|
||||||
"screen_room_member_details_block_alert_description" = "Blocked users won't be able to send you messages and all their messages will be hidden. You can unblock them anytime.";
|
"screen_room_member_details_block_alert_description" = "Blocked users won't be able to send you messages and all their messages will be hidden. You can unblock them anytime.";
|
||||||
"screen_room_member_details_block_user" = "Block user";
|
"screen_room_member_details_block_user" = "Block user";
|
||||||
|
|||||||
@@ -840,6 +840,9 @@
|
|||||||
"screen_room_error_failed_retrieving_user_details" = "Could not retrieve user details";
|
"screen_room_error_failed_retrieving_user_details" = "Could not retrieve user details";
|
||||||
"screen_room_invite_again_alert_message" = "Would you like to invite them back?";
|
"screen_room_invite_again_alert_message" = "Would you like to invite them back?";
|
||||||
"screen_room_invite_again_alert_title" = "You are alone in this chat";
|
"screen_room_invite_again_alert_title" = "You are alone in this chat";
|
||||||
|
"screen_room_member_details_alert_create_dm_confirmation_title" = "Send invite";
|
||||||
|
"screen_room_member_details_alert_create_dm_message" = "Would you like to start a chat with %1$@?";
|
||||||
|
"screen_room_member_details_alert_create_dm_title" = "Send invite?";
|
||||||
"screen_room_member_details_block_alert_action" = "Block";
|
"screen_room_member_details_block_alert_action" = "Block";
|
||||||
"screen_room_member_details_block_alert_description" = "Blocked users won't be able to send you messages and all their messages will be hidden. You can unblock them anytime.";
|
"screen_room_member_details_block_alert_description" = "Blocked users won't be able to send you messages and all their messages will be hidden. You can unblock them anytime.";
|
||||||
"screen_room_member_details_block_user" = "Block user";
|
"screen_room_member_details_block_user" = "Block user";
|
||||||
|
|||||||
@@ -1938,6 +1938,14 @@ internal enum L10n {
|
|||||||
internal static var screenRoomInviteAgainAlertMessage: String { return L10n.tr("Localizable", "screen_room_invite_again_alert_message") }
|
internal static var screenRoomInviteAgainAlertMessage: String { return L10n.tr("Localizable", "screen_room_invite_again_alert_message") }
|
||||||
/// You are alone in this chat
|
/// You are alone in this chat
|
||||||
internal static var screenRoomInviteAgainAlertTitle: String { return L10n.tr("Localizable", "screen_room_invite_again_alert_title") }
|
internal static var screenRoomInviteAgainAlertTitle: String { return L10n.tr("Localizable", "screen_room_invite_again_alert_title") }
|
||||||
|
/// Send invite
|
||||||
|
internal static var screenRoomMemberDetailsAlertCreateDmConfirmationTitle: String { return L10n.tr("Localizable", "screen_room_member_details_alert_create_dm_confirmation_title") }
|
||||||
|
/// Would you like to start a chat with %1$@?
|
||||||
|
internal static func screenRoomMemberDetailsAlertCreateDmMessage(_ p1: Any) -> String {
|
||||||
|
return L10n.tr("Localizable", "screen_room_member_details_alert_create_dm_message", String(describing: p1))
|
||||||
|
}
|
||||||
|
/// Send invite?
|
||||||
|
internal static var screenRoomMemberDetailsAlertCreateDmTitle: String { return L10n.tr("Localizable", "screen_room_member_details_alert_create_dm_title") }
|
||||||
/// Block
|
/// Block
|
||||||
internal static var screenRoomMemberDetailsBlockAlertAction: String { return L10n.tr("Localizable", "screen_room_member_details_block_alert_action") }
|
internal static var screenRoomMemberDetailsBlockAlertAction: String { return L10n.tr("Localizable", "screen_room_member_details_block_alert_action") }
|
||||||
/// Blocked users won't be able to send you messages and all their messages will be hidden. You can unblock them anytime.
|
/// Blocked users won't be able to send you messages and all their messages will be hidden. You can unblock them anytime.
|
||||||
|
|||||||
@@ -2455,76 +2455,6 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
|
|||||||
return accountURLActionReturnValue
|
return accountURLActionReturnValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//MARK: - createDirectRoomIfNeeded
|
|
||||||
|
|
||||||
var createDirectRoomIfNeededWithExpectedRoomNameUnderlyingCallsCount = 0
|
|
||||||
var createDirectRoomIfNeededWithExpectedRoomNameCallsCount: Int {
|
|
||||||
get {
|
|
||||||
if Thread.isMainThread {
|
|
||||||
return createDirectRoomIfNeededWithExpectedRoomNameUnderlyingCallsCount
|
|
||||||
} else {
|
|
||||||
var returnValue: Int? = nil
|
|
||||||
DispatchQueue.main.sync {
|
|
||||||
returnValue = createDirectRoomIfNeededWithExpectedRoomNameUnderlyingCallsCount
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
if Thread.isMainThread {
|
|
||||||
createDirectRoomIfNeededWithExpectedRoomNameUnderlyingCallsCount = newValue
|
|
||||||
} else {
|
|
||||||
DispatchQueue.main.sync {
|
|
||||||
createDirectRoomIfNeededWithExpectedRoomNameUnderlyingCallsCount = newValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var createDirectRoomIfNeededWithExpectedRoomNameCalled: Bool {
|
|
||||||
return createDirectRoomIfNeededWithExpectedRoomNameCallsCount > 0
|
|
||||||
}
|
|
||||||
var createDirectRoomIfNeededWithExpectedRoomNameReceivedArguments: (userID: String, expectedRoomName: String?)?
|
|
||||||
var createDirectRoomIfNeededWithExpectedRoomNameReceivedInvocations: [(userID: String, expectedRoomName: String?)] = []
|
|
||||||
|
|
||||||
var createDirectRoomIfNeededWithExpectedRoomNameUnderlyingReturnValue: Result<(roomID: String, isNewRoom: Bool), ClientProxyError>!
|
|
||||||
var createDirectRoomIfNeededWithExpectedRoomNameReturnValue: Result<(roomID: String, isNewRoom: Bool), ClientProxyError>! {
|
|
||||||
get {
|
|
||||||
if Thread.isMainThread {
|
|
||||||
return createDirectRoomIfNeededWithExpectedRoomNameUnderlyingReturnValue
|
|
||||||
} else {
|
|
||||||
var returnValue: Result<(roomID: String, isNewRoom: Bool), ClientProxyError>? = nil
|
|
||||||
DispatchQueue.main.sync {
|
|
||||||
returnValue = createDirectRoomIfNeededWithExpectedRoomNameUnderlyingReturnValue
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
if Thread.isMainThread {
|
|
||||||
createDirectRoomIfNeededWithExpectedRoomNameUnderlyingReturnValue = newValue
|
|
||||||
} else {
|
|
||||||
DispatchQueue.main.sync {
|
|
||||||
createDirectRoomIfNeededWithExpectedRoomNameUnderlyingReturnValue = newValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var createDirectRoomIfNeededWithExpectedRoomNameClosure: ((String, String?) async -> Result<(roomID: String, isNewRoom: Bool), ClientProxyError>)?
|
|
||||||
|
|
||||||
func createDirectRoomIfNeeded(with userID: String, expectedRoomName: String?) async -> Result<(roomID: String, isNewRoom: Bool), ClientProxyError> {
|
|
||||||
createDirectRoomIfNeededWithExpectedRoomNameCallsCount += 1
|
|
||||||
createDirectRoomIfNeededWithExpectedRoomNameReceivedArguments = (userID: userID, expectedRoomName: expectedRoomName)
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.createDirectRoomIfNeededWithExpectedRoomNameReceivedInvocations.append((userID: userID, expectedRoomName: expectedRoomName))
|
|
||||||
}
|
|
||||||
if let createDirectRoomIfNeededWithExpectedRoomNameClosure = createDirectRoomIfNeededWithExpectedRoomNameClosure {
|
|
||||||
return await createDirectRoomIfNeededWithExpectedRoomNameClosure(userID, expectedRoomName)
|
|
||||||
} else {
|
|
||||||
return createDirectRoomIfNeededWithExpectedRoomNameReturnValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//MARK: - directRoomForUserID
|
//MARK: - directRoomForUserID
|
||||||
|
|
||||||
var directRoomForUserIDUnderlyingCallsCount = 0
|
var directRoomForUserIDUnderlyingCallsCount = 0
|
||||||
|
|||||||
@@ -90,5 +90,6 @@ enum RoomMemberDetailsScreenViewAction {
|
|||||||
|
|
||||||
enum RoomMemberDetailsScreenError: Hashable {
|
enum RoomMemberDetailsScreenError: Hashable {
|
||||||
case failedOpeningDirectChat
|
case failedOpeningDirectChat
|
||||||
|
case createDirectChatConfirmation
|
||||||
case unknown
|
case unknown
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-4
@@ -181,11 +181,36 @@ class RoomMemberDetailsScreenViewModel: RoomMemberDetailsScreenViewModelType, Ro
|
|||||||
persistent: true))
|
persistent: true))
|
||||||
defer { userIndicatorController.retractIndicatorWithId(loadingIndicatorIdentifier) }
|
defer { userIndicatorController.retractIndicatorWithId(loadingIndicatorIdentifier) }
|
||||||
|
|
||||||
switch await clientProxy.createDirectRoomIfNeeded(with: roomMemberProxy.userID, expectedRoomName: roomMemberProxy.displayName) {
|
switch await clientProxy.directRoomForUserID(roomMemberProxy.userID) {
|
||||||
case .success((let roomID, let isNewRoom)):
|
case .success(let roomID):
|
||||||
if isNewRoom {
|
if let roomID = roomID {
|
||||||
analytics.trackCreatedRoom(isDM: true)
|
actionsSubject.send(.openDirectChat(roomID: roomID))
|
||||||
|
} else {
|
||||||
|
let string = roomMemberProxy.displayName ?? roomMemberProxy.userID
|
||||||
|
state.bindings.alertInfo = .init(id: .createDirectChatConfirmation,
|
||||||
|
title: L10n.screenRoomMemberDetailsAlertCreateDmTitle,
|
||||||
|
message: L10n.screenRoomMemberDetailsAlertCreateDmMessage(string),
|
||||||
|
primaryButton: .init(title: L10n.screenRoomMemberDetailsAlertCreateDmConfirmationTitle) { [weak self] in Task { await self?.createDirectChat() }},
|
||||||
|
secondaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil))
|
||||||
}
|
}
|
||||||
|
case .failure:
|
||||||
|
state.bindings.alertInfo = .init(id: .failedOpeningDirectChat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func createDirectChat() async {
|
||||||
|
guard let roomMemberProxy else { fatalError() }
|
||||||
|
|
||||||
|
let loadingIndicatorIdentifier = "createDirectChatLoadingIndicator"
|
||||||
|
userIndicatorController.submitIndicator(UserIndicator(id: loadingIndicatorIdentifier,
|
||||||
|
type: .modal(progress: .indeterminate, interactiveDismissDisabled: true, allowsInteraction: false),
|
||||||
|
title: L10n.commonLoading,
|
||||||
|
persistent: true))
|
||||||
|
defer { userIndicatorController.retractIndicatorWithId(loadingIndicatorIdentifier) }
|
||||||
|
|
||||||
|
switch await clientProxy.createDirectRoom(with: roomMemberProxy.userID, expectedRoomName: roomMemberProxy.displayName) {
|
||||||
|
case .success(let roomID):
|
||||||
|
analytics.trackCreatedRoom(isDM: true)
|
||||||
actionsSubject.send(.openDirectChat(roomID: roomID))
|
actionsSubject.send(.openDirectChat(roomID: roomID))
|
||||||
case .failure:
|
case .failure:
|
||||||
state.bindings.alertInfo = .init(id: .failedOpeningDirectChat)
|
state.bindings.alertInfo = .init(id: .failedOpeningDirectChat)
|
||||||
|
|||||||
@@ -51,4 +51,5 @@ enum UserProfileScreenViewAction {
|
|||||||
enum UserProfileScreenError: Hashable {
|
enum UserProfileScreenError: Hashable {
|
||||||
case failedOpeningDirectChat
|
case failedOpeningDirectChat
|
||||||
case unknown
|
case unknown
|
||||||
|
case createDirectChatConfirmation
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,12 +115,33 @@ class UserProfileScreenViewModel: UserProfileScreenViewModelType, UserProfileScr
|
|||||||
|
|
||||||
showLoadingIndicator(allowsInteraction: false)
|
showLoadingIndicator(allowsInteraction: false)
|
||||||
defer { hideLoadingIndicator() }
|
defer { hideLoadingIndicator() }
|
||||||
|
|
||||||
switch await clientProxy.createDirectRoomIfNeeded(with: userProfile.userID, expectedRoomName: userProfile.displayName) {
|
switch await clientProxy.directRoomForUserID(userProfile.userID) {
|
||||||
case .success((let roomID, let isNewRoom)):
|
case .success(let roomID):
|
||||||
if isNewRoom {
|
if let roomID = roomID {
|
||||||
analytics.trackCreatedRoom(isDM: true)
|
actionsSubject.send(.openDirectChat(roomID: roomID))
|
||||||
|
} else {
|
||||||
|
let string = userProfile.displayName ?? userProfile.userID
|
||||||
|
state.bindings.alertInfo = .init(id: .createDirectChatConfirmation,
|
||||||
|
title: L10n.screenRoomMemberDetailsAlertCreateDmTitle,
|
||||||
|
message: L10n.screenRoomMemberDetailsAlertCreateDmMessage(string),
|
||||||
|
primaryButton: .init(title: L10n.screenRoomMemberDetailsAlertCreateDmConfirmationTitle) { [weak self] in Task { await self?.createDirectChat() }},
|
||||||
|
secondaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil))
|
||||||
}
|
}
|
||||||
|
case .failure:
|
||||||
|
state.bindings.alertInfo = .init(id: .failedOpeningDirectChat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func createDirectChat() async {
|
||||||
|
guard let userProfile = state.userProfile else { fatalError() }
|
||||||
|
|
||||||
|
showLoadingIndicator(allowsInteraction: false)
|
||||||
|
defer { hideLoadingIndicator() }
|
||||||
|
|
||||||
|
switch await clientProxy.createDirectRoom(with: userProfile.userID, expectedRoomName: userProfile.displayName) {
|
||||||
|
case .success(let roomID):
|
||||||
|
analytics.trackCreatedRoom(isDM: true)
|
||||||
actionsSubject.send(.openDirectChat(roomID: roomID))
|
actionsSubject.send(.openDirectChat(roomID: roomID))
|
||||||
case .failure:
|
case .failure:
|
||||||
state.bindings.alertInfo = .init(id: .failedOpeningDirectChat)
|
state.bindings.alertInfo = .init(id: .failedOpeningDirectChat)
|
||||||
|
|||||||
@@ -341,23 +341,6 @@ class ClientProxy: ClientProxyProtocol {
|
|||||||
try? await client.accountUrl(action: action).flatMap(URL.init(string:))
|
try? await client.accountUrl(action: action).flatMap(URL.init(string:))
|
||||||
}
|
}
|
||||||
|
|
||||||
func createDirectRoomIfNeeded(with userID: String, expectedRoomName: String?) async -> Result<(roomID: String, isNewRoom: Bool), ClientProxyError> {
|
|
||||||
let currentDirectRoom = await directRoomForUserID(userID)
|
|
||||||
switch currentDirectRoom {
|
|
||||||
case .success(.some(let roomID)):
|
|
||||||
return .success((roomID: roomID, isNewRoom: false))
|
|
||||||
case .success(.none):
|
|
||||||
switch await createDirectRoom(with: userID, expectedRoomName: expectedRoomName) {
|
|
||||||
case .success(let roomID):
|
|
||||||
return .success((roomID: roomID, isNewRoom: true))
|
|
||||||
case .failure(let error):
|
|
||||||
return .failure(.sdkError(error))
|
|
||||||
}
|
|
||||||
case .failure(let error):
|
|
||||||
return .failure(.sdkError(error))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func directRoomForUserID(_ userID: String) async -> Result<String?, ClientProxyError> {
|
func directRoomForUserID(_ userID: String) async -> Result<String?, ClientProxyError> {
|
||||||
await Task.dispatch(on: clientQueue) {
|
await Task.dispatch(on: clientQueue) {
|
||||||
do {
|
do {
|
||||||
|
|||||||
@@ -113,8 +113,6 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
|
|||||||
|
|
||||||
func accountURL(action: AccountManagementAction) async -> URL?
|
func accountURL(action: AccountManagementAction) async -> URL?
|
||||||
|
|
||||||
func createDirectRoomIfNeeded(with userID: String, expectedRoomName: String?) async -> Result<(roomID: String, isNewRoom: Bool), ClientProxyError>
|
|
||||||
|
|
||||||
func directRoomForUserID(_ userID: String) async -> Result<String?, ClientProxyError>
|
func directRoomForUserID(_ userID: String) async -> Result<String?, ClientProxyError>
|
||||||
|
|
||||||
func createDirectRoom(with userID: String, expectedRoomName: String?) async -> Result<String, ClientProxyError>
|
func createDirectRoom(with userID: String, expectedRoomName: String?) async -> Result<String, ClientProxyError>
|
||||||
|
|||||||
Reference in New Issue
Block a user