Skip to content

Commit

Permalink
fix: cannot start conversation - WPB-11572 (#2037)
Browse files Browse the repository at this point in the history
  • Loading branch information
netbe authored Oct 18, 2024
1 parent d5d5782 commit 309e5a3
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,26 @@ final class OneOnOneProtocolSelectorTests: ZMBaseManagedObjectTest {
XCTAssertEqual(result, .proteus)
}

func test_GetProtocolForUser_IfNoProtocolForSelfReturnsNil() async throws {
// Given
let userID = QualifiedID.random()

await uiMOC.perform { [self] in
let user = createUser(id: userID, in: uiMOC)
user.supportedProtocols = [.proteus]

let selfUser = ZMUser.selfUser(in: uiMOC)
selfUser.supportedProtocols = []
}

// When
let result = try await sut.getProtocolForUser(
with: userID,
in: uiMOC
)

// Then
XCTAssertEqual(result, .none)
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
////
//
// Wire
// Copyright (C) 2023 Wire Swiss GmbH
// Copyright (C) 2024 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -31,7 +31,7 @@ public final class SupportedProtocolsService: SupportedProtocolsServiceInterface

private let featureRepository: FeatureRepositoryInterface
private let userRepository: UserRepositoryInterface
private let logger = WireLogger(tag: "supported-protocols")
private let logger = WireLogger.supportedProtocols

// MARK: - Life cycle

Expand Down
1 change: 0 additions & 1 deletion wire-ios-sync-engine/Source/Use cases/UseCaseFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ struct UseCaseFactory: UseCaseFactoryProtocol {
resolver: oneOnOneResolver
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ extension ZMUserSession: ZMSyncStateDelegate {

WaitingGroupTask(context: syncContext) { [self] in
await fetchAndStoreFeatureConfig()
await calculateSelfSupportedProtocolsIfNeeded()
await resolveOneOnOneConversationsIfNeeded()
}

Expand All @@ -962,6 +963,23 @@ extension ZMUserSession: ZMSyncStateDelegate {
performPostQuickSyncE2EIActions()
}

/// Calculate supported protocols for self user in case they are empty
/// - note: Supported protocols are calculated only during slow sync
/// or while resolving 1-1 conversations (MLS enabled).
/// It fixes users that updates to latest version without having a supported-protocol.
/// This could be removed once MLS is enabled.
private func calculateSelfSupportedProtocolsIfNeeded() async {
await syncContext.perform { [syncContext] in
let service = SupportedProtocolsService(context: syncContext)
let selfUser = ZMUser.selfUser(in: syncContext)
if selfUser.supportedProtocols.isEmpty {
WireLogger.supportedProtocols.warn("no supported protocols found")
selfUser.supportedProtocols = service.calculateSupportedProtocols()
syncContext.saveOrRollback()
}
}
}

private func resolveOneOnOneConversationsIfNeeded() async {
guard DeveloperFlag.enableMLSSupport.isOn else { return }
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ final class CreateTeamOneOnOneConversationUseCaseTests: XCTestCase {
do {
// When
_ = try await sut.invoke(with: otherUser, syncContext: syncContext)
XCTFail("should fail")
} catch CreateTeamOneOnOneConversationError.userIsNotOnSameTeam {
// Then
} catch {
Expand All @@ -113,6 +114,7 @@ final class CreateTeamOneOnOneConversationUseCaseTests: XCTestCase {
do {
// When
_ = try await sut.invoke(with: otherUser, syncContext: syncContext)
XCTFail("should fail")
} catch CreateTeamOneOnOneConversationError.noCommonProtocols {
// Then
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ final class ZMUserSessionTests: ZMUserSessionTestsBase {

func test_itPerformsPeriodicMLSUpdates_AfterQuickSync() {
// GIVEN
DeveloperFlag.enableMLSSupport.enable(true, storage: .temporary())
mockMLSService.performPendingJoins_MockMethod = {}
mockMLSService.commitPendingProposalsIfNeeded_MockMethod = {}
mockMLSService.uploadKeyPackagesIfNeeded_MockMethod = {}
Expand Down Expand Up @@ -596,5 +597,12 @@ final class ZMUserSessionTests: ZMUserSessionTestsBase {
XCTAssertFalse(mockMLSService.updateKeyMaterialForAllStaleGroupsIfNeeded_Invocations.isEmpty)
XCTAssertFalse(mockMLSService.commitPendingProposalsIfNeeded_Invocations.isEmpty)
}

XCTAssertTrue(waitForAllGroupsToBeEmpty(withTimeout: 0.5))

// THEN
let supportedProtocols = syncMOC.performAndWait { ZMUser.selfUser(in: self.syncMOC).supportedProtocols }

XCTAssertTrue(supportedProtocols.contains(.proteus))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class ZMUserSessionTestsBase: MessagingTest {
var thirdPartyServices: ThirdPartyServices!
var mockSyncStateDelegate: MockSyncStateDelegate!
var mockUseCaseFactory: MockUseCaseFactoryProtocol!
var mockResolveOneOnOneConversationUseCase: MockResolveOneOnOneConversationsUseCaseProtocol!
var mockGetFeatureConfigsActionHandler: MockActionHandler<GetFeatureConfigsAction>!

var sut: ZMUserSession!
Expand Down Expand Up @@ -85,11 +84,11 @@ class ZMUserSessionTestsBase: MessagingTest {
}

mockUseCaseFactory = MockUseCaseFactoryProtocol()
mockResolveOneOnOneConversationUseCase = MockResolveOneOnOneConversationsUseCaseProtocol()
mockResolveOneOnOneConversationUseCase.invoke_MockMethod = { }

mockUseCaseFactory.createResolveOneOnOneUseCase_MockMethod = {
return self.mockResolveOneOnOneConversationUseCase
let mockResolveOneOnOneConversationUseCase = MockResolveOneOnOneConversationsUseCaseProtocol()
mockResolveOneOnOneConversationUseCase.invoke_MockMethod = { }
return mockResolveOneOnOneConversationUseCase
}

sut = createSut()
Expand Down Expand Up @@ -117,7 +116,6 @@ class ZMUserSessionTestsBase: MessagingTest {
self.mediaManager = nil
self.flowManagerMock = nil
self.mockUseCaseFactory = nil
self.mockResolveOneOnOneConversationUseCase = nil
self.mockEARService.delegate = nil
self.mockEARService = nil
let sut = self.sut
Expand Down
1 change: 1 addition & 0 deletions wire-ios-system/Source/Logging/WireLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ public extension WireLogger {
static let eventProcessing = WireLogger(tag: "event-processing")
static let safeFileContext = WireLogger(tag: "safe-file-context")
static let messageProcessing = WireLogger(tag: "message-processing")
static let supportedProtocols = WireLogger(tag: "supported-protocols")
}

/// Class to proxy WireLogger methods to Objective-C
Expand Down

0 comments on commit 309e5a3

Please sign in to comment.