Skip to content

Commit

Permalink
Fix a bug where the room state wouldn't indicate when a call was in p…
Browse files Browse the repository at this point in the history
…rogress. (#3442)

* Fix breaking changes on decryption errors and sending failures.

* Update SDK and analytics events.

* Add extra UTD strings.

---------

Co-authored-by: Stefan Ceriu <[email protected]>
  • Loading branch information
pixlwave and stefanceriu authored Oct 24, 2024
1 parent 665bdd1 commit cb4d68a
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 81 deletions.
4 changes: 2 additions & 2 deletions ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7822,7 +7822,7 @@
repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift";
requirement = {
kind = exactVersion;
version = 1.0.60;
version = 1.0.61;
};
};
701C7BEF8F70F7A83E852DCC /* XCRemoteSwiftPackageReference "GZIP" */ = {
Expand Down Expand Up @@ -7862,7 +7862,7 @@
repositoryURL = "https://github.com/matrix-org/matrix-analytics-events";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 0.25.0;
minimumVersion = 0.27.0;
};
};
C13F55E4518415CB4C278E73 /* XCRemoteSwiftPackageReference "DTCoreText" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/element-hq/compound-design-tokens",
"state" : {
"revision" : "2af7bb571eb30cbfbd67cdda6617500507ef46aa",
"version" : "1.8.0"
"revision" : "976db67b849775799b4153e7894d61e90fc96888",
"version" : "1.9.0"
}
},
{
Expand Down Expand Up @@ -131,8 +131,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-analytics-events",
"state" : {
"revision" : "c9b40120a5f7b8ce1bab3f09f8417fdc9407f006",
"version" : "0.25.0"
"revision" : "9bd3c57e84f87d56b69862369f3b9da714d1d151",
"version" : "0.27.0"
}
},
{
Expand All @@ -149,8 +149,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/element-hq/matrix-rust-components-swift",
"state" : {
"revision" : "dc3a2199b0e87824ccf06d1207487d2e49c5e584",
"version" : "1.0.60"
"revision" : "2e6378514e79a648d436e8faeb8cd8106910cf0b",
"version" : "1.0.61"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions ElementX/Resources/Localizations/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@
"common.pinned" = "Pinned";
"common.send_to" = "Send to";
"common.you" = "You";
"common_unable_to_decrypt_insecure_device" = "Sent from an insecure device";
"common_unable_to_decrypt_verification_violation" = "Sender's verified identity has changed";
"confirm_recovery_key_banner_message" = "Your chat backup is currently out of sync. You need to enter your recovery key to maintain access to your chat backup.";
"confirm_recovery_key_banner_title" = "Enter your recovery key";
"crash_detection_dialog_content" = "%1$@ crashed the last time it was used. Would you like to share a crash report with us?";
Expand Down
13 changes: 10 additions & 3 deletions ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
/// For testing purposes.
var statePublisher: AnyPublisher<UserSessionFlowCoordinatorStateMachine.State, Never> { stateMachine.statePublisher }

// swiftlint:disable:next function_body_length
init(userSession: UserSessionProtocol,
navigationRootCoordinator: NavigationRootCoordinator,
appLockService: AppLockServiceProtocol,
Expand Down Expand Up @@ -158,9 +159,15 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {

switch info.cause {
case .unknown:
analytics.trackError(context: nil, domain: .E2EE, name: .OlmKeysNotSentError, timeToDecryptMillis: timeToDecryptMs)
case .membership:
analytics.trackError(context: nil, domain: .E2EE, name: .HistoricalMessage, timeToDecryptMillis: timeToDecryptMs)
analytics.trackError(context: nil, domain: .E2EE, name: .UnknownError, timeToDecryptMillis: timeToDecryptMs)
case .unknownDevice:
analytics.trackError(context: nil, domain: .E2EE, name: .ExpectedSentByInsecureDevice, timeToDecryptMillis: timeToDecryptMs)
case .unsignedDevice:
analytics.trackError(context: nil, domain: .E2EE, name: .ExpectedSentByInsecureDevice, timeToDecryptMillis: timeToDecryptMs)
case .verificationViolation:
analytics.trackError(context: nil, domain: .E2EE, name: .ExpectedVerificationViolation, timeToDecryptMillis: timeToDecryptMs)
case .sentBeforeWeJoined:
analytics.trackError(context: nil, domain: .E2EE, name: .ExpectedDueToMembership, timeToDecryptMillis: timeToDecryptMs)
}
}
.store(in: &cancellables)
Expand Down
4 changes: 4 additions & 0 deletions ElementX/Sources/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,12 @@ internal enum L10n {
internal static var commonTouchIdIos: String { return L10n.tr("Localizable", "common_touch_id_ios") }
/// Unable to decrypt
internal static var commonUnableToDecrypt: String { return L10n.tr("Localizable", "common_unable_to_decrypt") }
/// Sent from an insecure device
internal static var commonUnableToDecryptInsecureDevice: String { return L10n.tr("Localizable", "common_unable_to_decrypt_insecure_device") }
/// You don't have access to this message
internal static var commonUnableToDecryptNoAccess: String { return L10n.tr("Localizable", "common_unable_to_decrypt_no_access") }
/// Sender's verified identity has changed
internal static var commonUnableToDecryptVerificationViolation: String { return L10n.tr("Localizable", "common_unable_to_decrypt_verification_violation") }
/// Invites couldn't be sent to one or more users.
internal static var commonUnableToInviteMessage: String { return L10n.tr("Localizable", "common_unable_to_invite_message") }
/// Unable to send invite(s)
Expand Down
48 changes: 24 additions & 24 deletions ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2837,72 +2837,72 @@ class ClientProxyMock: ClientProxyProtocol {
}
//MARK: - knockRoom

var knockRoomMessageUnderlyingCallsCount = 0
var knockRoomMessageCallsCount: Int {
var knockRoomViaMessageUnderlyingCallsCount = 0
var knockRoomViaMessageCallsCount: Int {
get {
if Thread.isMainThread {
return knockRoomMessageUnderlyingCallsCount
return knockRoomViaMessageUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = knockRoomMessageUnderlyingCallsCount
returnValue = knockRoomViaMessageUnderlyingCallsCount
}

return returnValue!
}
}
set {
if Thread.isMainThread {
knockRoomMessageUnderlyingCallsCount = newValue
knockRoomViaMessageUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
knockRoomMessageUnderlyingCallsCount = newValue
knockRoomViaMessageUnderlyingCallsCount = newValue
}
}
}
}
var knockRoomMessageCalled: Bool {
return knockRoomMessageCallsCount > 0
var knockRoomViaMessageCalled: Bool {
return knockRoomViaMessageCallsCount > 0
}
var knockRoomMessageReceivedArguments: (roomID: String, message: String?)?
var knockRoomMessageReceivedInvocations: [(roomID: String, message: String?)] = []
var knockRoomViaMessageReceivedArguments: (roomID: String, via: [String], message: String?)?
var knockRoomViaMessageReceivedInvocations: [(roomID: String, via: [String], message: String?)] = []

var knockRoomMessageUnderlyingReturnValue: Result<Void, ClientProxyError>!
var knockRoomMessageReturnValue: Result<Void, ClientProxyError>! {
var knockRoomViaMessageUnderlyingReturnValue: Result<Void, ClientProxyError>!
var knockRoomViaMessageReturnValue: Result<Void, ClientProxyError>! {
get {
if Thread.isMainThread {
return knockRoomMessageUnderlyingReturnValue
return knockRoomViaMessageUnderlyingReturnValue
} else {
var returnValue: Result<Void, ClientProxyError>? = nil
DispatchQueue.main.sync {
returnValue = knockRoomMessageUnderlyingReturnValue
returnValue = knockRoomViaMessageUnderlyingReturnValue
}

return returnValue!
}
}
set {
if Thread.isMainThread {
knockRoomMessageUnderlyingReturnValue = newValue
knockRoomViaMessageUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
knockRoomMessageUnderlyingReturnValue = newValue
knockRoomViaMessageUnderlyingReturnValue = newValue
}
}
}
}
var knockRoomMessageClosure: ((String, String?) async -> Result<Void, ClientProxyError>)?
var knockRoomViaMessageClosure: ((String, [String], String?) async -> Result<Void, ClientProxyError>)?

func knockRoom(_ roomID: String, message: String?) async -> Result<Void, ClientProxyError> {
knockRoomMessageCallsCount += 1
knockRoomMessageReceivedArguments = (roomID: roomID, message: message)
func knockRoom(_ roomID: String, via: [String], message: String?) async -> Result<Void, ClientProxyError> {
knockRoomViaMessageCallsCount += 1
knockRoomViaMessageReceivedArguments = (roomID: roomID, via: via, message: message)
DispatchQueue.main.async {
self.knockRoomMessageReceivedInvocations.append((roomID: roomID, message: message))
self.knockRoomViaMessageReceivedInvocations.append((roomID: roomID, via: via, message: message))
}
if let knockRoomMessageClosure = knockRoomMessageClosure {
return await knockRoomMessageClosure(roomID, message)
if let knockRoomViaMessageClosure = knockRoomViaMessageClosure {
return await knockRoomViaMessageClosure(roomID, via, message)
} else {
return knockRoomMessageReturnValue
return knockRoomViaMessageReturnValue
}
}
//MARK: - knockRoomAlias
Expand Down
52 changes: 26 additions & 26 deletions ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2208,76 +2208,76 @@ open class ClientSDKMock: MatrixRustSDK.Client {

//MARK: - knock

open var knockRoomIdOrAliasThrowableError: Error?
var knockRoomIdOrAliasUnderlyingCallsCount = 0
open var knockRoomIdOrAliasCallsCount: Int {
open var knockRoomIdOrAliasReasonServerNamesThrowableError: Error?
var knockRoomIdOrAliasReasonServerNamesUnderlyingCallsCount = 0
open var knockRoomIdOrAliasReasonServerNamesCallsCount: Int {
get {
if Thread.isMainThread {
return knockRoomIdOrAliasUnderlyingCallsCount
return knockRoomIdOrAliasReasonServerNamesUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = knockRoomIdOrAliasUnderlyingCallsCount
returnValue = knockRoomIdOrAliasReasonServerNamesUnderlyingCallsCount
}

return returnValue!
}
}
set {
if Thread.isMainThread {
knockRoomIdOrAliasUnderlyingCallsCount = newValue
knockRoomIdOrAliasReasonServerNamesUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
knockRoomIdOrAliasUnderlyingCallsCount = newValue
knockRoomIdOrAliasReasonServerNamesUnderlyingCallsCount = newValue
}
}
}
}
open var knockRoomIdOrAliasCalled: Bool {
return knockRoomIdOrAliasCallsCount > 0
open var knockRoomIdOrAliasReasonServerNamesCalled: Bool {
return knockRoomIdOrAliasReasonServerNamesCallsCount > 0
}
open var knockRoomIdOrAliasReceivedRoomIdOrAlias: String?
open var knockRoomIdOrAliasReceivedInvocations: [String] = []
open var knockRoomIdOrAliasReasonServerNamesReceivedArguments: (roomIdOrAlias: String, reason: String?, serverNames: [String])?
open var knockRoomIdOrAliasReasonServerNamesReceivedInvocations: [(roomIdOrAlias: String, reason: String?, serverNames: [String])] = []

var knockRoomIdOrAliasUnderlyingReturnValue: Room!
open var knockRoomIdOrAliasReturnValue: Room! {
var knockRoomIdOrAliasReasonServerNamesUnderlyingReturnValue: Room!
open var knockRoomIdOrAliasReasonServerNamesReturnValue: Room! {
get {
if Thread.isMainThread {
return knockRoomIdOrAliasUnderlyingReturnValue
return knockRoomIdOrAliasReasonServerNamesUnderlyingReturnValue
} else {
var returnValue: Room? = nil
DispatchQueue.main.sync {
returnValue = knockRoomIdOrAliasUnderlyingReturnValue
returnValue = knockRoomIdOrAliasReasonServerNamesUnderlyingReturnValue
}

return returnValue!
}
}
set {
if Thread.isMainThread {
knockRoomIdOrAliasUnderlyingReturnValue = newValue
knockRoomIdOrAliasReasonServerNamesUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
knockRoomIdOrAliasUnderlyingReturnValue = newValue
knockRoomIdOrAliasReasonServerNamesUnderlyingReturnValue = newValue
}
}
}
}
open var knockRoomIdOrAliasClosure: ((String) async throws -> Room)?
open var knockRoomIdOrAliasReasonServerNamesClosure: ((String, String?, [String]) async throws -> Room)?

open override func knock(roomIdOrAlias: String) async throws -> Room {
if let error = knockRoomIdOrAliasThrowableError {
open override func knock(roomIdOrAlias: String, reason: String?, serverNames: [String]) async throws -> Room {
if let error = knockRoomIdOrAliasReasonServerNamesThrowableError {
throw error
}
knockRoomIdOrAliasCallsCount += 1
knockRoomIdOrAliasReceivedRoomIdOrAlias = roomIdOrAlias
knockRoomIdOrAliasReasonServerNamesCallsCount += 1
knockRoomIdOrAliasReasonServerNamesReceivedArguments = (roomIdOrAlias: roomIdOrAlias, reason: reason, serverNames: serverNames)
DispatchQueue.main.async {
self.knockRoomIdOrAliasReceivedInvocations.append(roomIdOrAlias)
self.knockRoomIdOrAliasReasonServerNamesReceivedInvocations.append((roomIdOrAlias: roomIdOrAlias, reason: reason, serverNames: serverNames))
}
if let knockRoomIdOrAliasClosure = knockRoomIdOrAliasClosure {
return try await knockRoomIdOrAliasClosure(roomIdOrAlias)
if let knockRoomIdOrAliasReasonServerNamesClosure = knockRoomIdOrAliasReasonServerNamesClosure {
return try await knockRoomIdOrAliasReasonServerNamesClosure(roomIdOrAlias, reason, serverNames)
} else {
return knockRoomIdOrAliasReturnValue
return knockRoomIdOrAliasReasonServerNamesReturnValue
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
}
} else {
switch await clientProxy.knockRoom(roomID,
via: via,
message: state.bindings.knockMessage.isBlank ? nil : state.bindings.knockMessage) {
case .success:
state.mode = .knocked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ struct EncryptedRoomTimelineView: View {
switch cause {
case .unknown:
return \.time
case .membership:
case .sentBeforeWeJoined,
.verificationViolation,
.insecureDevice:
return \.block
}
default:
Expand Down Expand Up @@ -90,7 +92,7 @@ struct EncryptedRoomTimelineView_Previews: PreviewProvider, TestablePreview {
private static func expectedItemWith(timestamp: String, isOutgoing: Bool, senderId: String) -> EncryptedRoomTimelineItem {
EncryptedRoomTimelineItem(id: .randomEvent,
body: L10n.commonUnableToDecryptNoAccess,
encryptionType: .megolmV1AesSha2(sessionID: "foo", cause: .membership),
encryptionType: .megolmV1AesSha2(sessionID: "foo", cause: .sentBeforeWeJoined),
timestamp: timestamp,
isOutgoing: isOutgoing,
isEditable: false,
Expand Down
6 changes: 3 additions & 3 deletions ElementX/Sources/Services/Client/ClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ class ClientProxy: ClientProxyProtocol {
}
}

func knockRoom(_ roomID: String, message: String?) async -> Result<Void, ClientProxyError> {
func knockRoom(_ roomID: String, via: [String], message: String?) async -> Result<Void, ClientProxyError> {
do {
let _ = try await client.knock(roomIdOrAlias: roomID)
let _ = try await client.knock(roomIdOrAlias: roomID, reason: nil, serverNames: via)
await waitForRoomToSync(roomID: roomID, timeout: .seconds(30))
return .success(())
} catch {
Expand All @@ -428,7 +428,7 @@ class ClientProxy: ClientProxyProtocol {

func knockRoomAlias(_ roomAlias: String, message: String?) async -> Result<Void, ClientProxyError> {
do {
let room = try await client.knock(roomIdOrAlias: roomAlias)
let room = try await client.knock(roomIdOrAlias: roomAlias, reason: nil, serverNames: [])
await waitForRoomToSync(roomID: room.id(), timeout: .seconds(30))
return .success(())
} catch {
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Services/Client/ClientProxyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {

func joinRoomAlias(_ roomAlias: String) async -> Result<Void, ClientProxyError>

func knockRoom(_ roomID: String, message: String?) async -> Result<Void, ClientProxyError>
func knockRoom(_ roomID: String, via: [String], message: String?) async -> Result<Void, ClientProxyError>

func knockRoomAlias(_ roomAlias: String, message: String?) async -> Result<Void, ClientProxyError>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ struct RoomEventStringBuilder {
switch eventItemProxy.content {
case .unableToDecrypt(let encryptedMessage):
let errorMessage = switch encryptedMessage {
case .megolmV1AesSha2(_, .membership): L10n.commonUnableToDecryptNoAccess
case .megolmV1AesSha2(_, .sentBeforeWeJoined): L10n.commonUnableToDecryptNoAccess
case .megolmV1AesSha2(_, .verificationViolation): L10n.commonUnableToDecryptVerificationViolation
case .megolmV1AesSha2(_, .unknownDevice), .megolmV1AesSha2(_, .unsignedDevice): L10n.commonUnableToDecryptInsecureDevice
default: L10n.commonWaitingForDecryptionKey
}
return prefix(errorMessage, with: displayName)
Expand Down
17 changes: 9 additions & 8 deletions ElementX/Sources/Services/Timeline/TimelineItemProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,19 @@ class EventTimelineItemProxy {
}

switch localSendState {
case .sendingFailed(_, let isRecoverable):
return isRecoverable ? .sending : .sendingFailed(.unknown)
case .sendingFailed(let error, let isRecoverable):
switch error {
case .identityViolations(let users):
return .sendingFailed(.verifiedUser(.changedIdentity(users: users)))
case .insecureDevices(let userDeviceMap):
return .sendingFailed(.verifiedUser(.hasUnsignedDevice(devices: userDeviceMap)))
default:
return .sendingFailed(.unknown)
}
case .notSentYet:
return .sending
case .sent:
return .sent
case .verifiedUserHasUnsignedDevice(devices: let devices):
return .sendingFailed(.verifiedUser(.hasUnsignedDevice(devices: devices)))
case .verifiedUserChangedIdentity(users: let users):
return .sendingFailed(.verifiedUser(.changedIdentity(users: users)))
case .crossSigningNotSetup, .sendingFromUnverifiedDevice:
return .sendingFailed(.unknown)
}
}()

Expand Down
Loading

0 comments on commit cb4d68a

Please sign in to comment.