Skip to content

Commit 670a6f8

Browse files
authored
fix: change the condition to close the call - WPB-24070 (#4435)
1 parent a914853 commit 670a6f8

File tree

11 files changed

+49
-183
lines changed

11 files changed

+49
-183
lines changed

WireDomain/Sources/WireDomain/Repositories/Conversations/LocalStore/ConversationLocalStore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,11 +1330,11 @@ public final class ConversationLocalStore: ConversationLocalStoreProtocol {
13301330
}
13311331

13321332
public func execute(
1333-
identifier: MLSGroupID,
1333+
conversationID: QualifiedID,
13341334
block: @escaping @Sendable (ZMConversation?, NSManagedObjectContext) -> Void
13351335
) async {
13361336
await context.perform { [context] in
1337-
let conversation = ZMConversation.fetch(with: identifier, in: context)
1337+
let conversation = ZMConversation.fetch(with: conversationID, in: context)
13381338
block(conversation, context)
13391339
}
13401340
}

WireDomain/Sources/WireDomain/Repositories/Conversations/Protocols/ConversationLocalStoreProtocol.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,14 @@ public protocol ConversationLocalStoreProtocol {
492492

493493
func fetchServerTimeDelta() async -> TimeInterval
494494

495+
/// Fetches the conversation matching the given qualified ID and executes a block,
496+
/// providing the conversation (if found) and the context.
497+
/// - Parameters:
498+
/// - conversationID: The qualified conversation ID used to look up the conversation.
499+
/// - block: Some code that should be invoked with the fetched conversation and the managed object context.
495500
func execute(
496-
identifier: MLSGroupID,
501+
conversationID: QualifiedID,
497502
block: @escaping @Sendable (ZMConversation?, NSManagedObjectContext) -> Void
498503
) async
504+
499505
}

WireDomain/Sources/WireDomain/Repositories/Conversations/Protocols/ConversationRepositoryProtocol.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ public protocol ConversationRepositoryProtocol: Sendable {
193193
) async throws -> String?
194194

195195
/// Checks if selfUser is still in a given conversation
196-
/// - Parameter groupID: mlsGroupID of the conversation
196+
/// - Parameter conversationID: QualifiedID of the conversation
197197
/// - Returns: true if selfUser belongs to the conversation, false otherwise
198198
func isSelfAnActiveMember(
199-
in groupID: WireDataModel.MLSGroupID
199+
in conversationID: WireDataModel.QualifiedID
200200
) async -> Bool
201201

202202
/// Reset the pendingProposalDate for the conversation
203-
/// - Parameter groupID: mlsGroupID of the conversation
204-
func clearPendingProposals(in groupID: WireDataModel.MLSGroupID) async
203+
/// - Parameter groupID: QualifiedID of the conversation
204+
func clearPendingProposals(in conversationID: WireDataModel.QualifiedID) async
205205

206206
}

WireDomain/Sources/WireDomain/Repositories/Conversations/Repository/ConversationRepository.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,17 +381,17 @@ public final class ConversationRepository: ConversationRepositoryProtocol {
381381
}
382382

383383
public func isSelfAnActiveMember(
384-
in groupID: MLSGroupID
384+
in conversationID: WireDataModel.QualifiedID
385385
) async -> Bool {
386386
nonisolated(unsafe) var isSelfAnActiveMember = false
387-
await conversationsLocalStore.execute(identifier: groupID) { conversation, _ in
387+
await conversationsLocalStore.execute(conversationID: conversationID) { conversation, _ in
388388
isSelfAnActiveMember = conversation?.isSelfAnActiveMember ?? false
389389
}
390390
return isSelfAnActiveMember
391391
}
392392

393-
public func clearPendingProposals(in groupID: WireDataModel.MLSGroupID) async {
394-
await conversationsLocalStore.execute(identifier: groupID) { conversation, context in
393+
public func clearPendingProposals(in conversationID: WireDataModel.QualifiedID) async {
394+
await conversationsLocalStore.execute(conversationID: conversationID) { conversation, context in
395395
conversation?.commitPendingProposalDate = nil
396396
context.saveOrRollback()
397397
}

WireDomain/Sources/WireDomain/Synchronization/CommitPendingProsalsGenerator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public final class CommitPendingProposalsGenerator: NSObject, LiveGeneratorProto
117117
}
118118

119119
// Re-check membership right before enqueuing the actual work item
120-
let stillMember = await repository.isSelfAnActiveMember(in: mlsGroupID)
120+
let stillMember = await repository.isSelfAnActiveMember(in: conversationID)
121121
guard stillMember else { return }
122122

123123
// Enqueue parent group item
@@ -126,6 +126,7 @@ public final class CommitPendingProposalsGenerator: NSObject, LiveGeneratorProto
126126
repository: repository,
127127
conversationID: conversationID,
128128
groupID: mlsGroupID,
129+
isSubconversation: false,
129130
mlsService: mlsService
130131
)
131132
)
@@ -137,6 +138,7 @@ public final class CommitPendingProposalsGenerator: NSObject, LiveGeneratorProto
137138
repository: repository,
138139
conversationID: conversationID,
139140
groupID: subgroupID,
141+
isSubconversation: true,
140142
mlsService: mlsService
141143
)
142144
)

WireDomain/Sources/WireDomain/WorkAgent/WorkItem/CommitPendingProposalItem.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,30 @@ struct CommitPendingProposalItem: WorkItem, CustomStringConvertible {
4141

4242
let conversationID: WireDataModel.QualifiedID
4343
let groupID: WireDataModel.MLSGroupID
44+
let isSubconversation: Bool
4445
let logger = WireLogger.mls
4546

4647
public init(
4748
repository: ConversationRepositoryProtocol,
4849
conversationID: WireDataModel.QualifiedID,
4950
groupID: WireDataModel.MLSGroupID,
51+
isSubconversation: Bool,
5052
mlsService: MLSServiceInterface
5153
) {
5254
self.repository = repository
5355
self.conversationID = conversationID
5456
self.groupID = groupID
57+
self.isSubconversation = isSubconversation
5558
self.mlsService = mlsService
5659
}
5760

5861
func start() async throws {
59-
let logAttributes: LogAttributes = [.mlsGroupID: groupID.safeForLoggingDescription] + LogAttributes.safePublic
62+
let logAttributes: LogAttributes = [
63+
.mlsGroupID: groupID.safeForLoggingDescription,
64+
.isSubconversation: isSubconversation
65+
] + LogAttributes.safePublic
6066

61-
let isSelfAnActiveMember = await repository.isSelfAnActiveMember(in: groupID)
67+
let isSelfAnActiveMember = await repository.isSelfAnActiveMember(in: conversationID)
6268

6369
guard isSelfAnActiveMember else {
6470
logger.info("cancelling commit as the user is no longer a member", attributes: logAttributes)
@@ -67,7 +73,7 @@ struct CommitPendingProposalItem: WorkItem, CustomStringConvertible {
6773

6874
guard try await mlsService.conversationExists(groupID: groupID) else {
6975
logger.warn("mls group does not exist, clearing pending proposal", attributes: logAttributes)
70-
await repository.clearPendingProposals(in: groupID)
76+
await repository.clearPendingProposals(in: conversationID)
7177
return
7278
}
7379

WireDomain/Sources/WireDomainSupport/Sourcery/generated/AutoMockable.generated.swift

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WireDomain/Tests/WireDomainTests/WorkAgent/WorkItem/CommitPendingProposalItemTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class CommitPendingProposalItemTests {
4848
repository: repository,
4949
conversationID: conversationID,
5050
groupID: mlsGroupID,
51+
isSubconversation: false,
5152
mlsService: mlsService
5253
)
5354
}

WireLogging/Sources/WireLogging/LogAttributes.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public enum LogAttributesKey: String, Comparable, Sendable {
4949
case syncVersion = "sync_version"
5050
case workItemID = "work_item_id"
5151
case isNewClient = "is_new_client"
52+
case isSubconversation = "is_subconversation"
5253
case timeInterval = "time_interval"
5354

5455
public static func < (lhs: LogAttributesKey, rhs: LogAttributesKey) -> Bool {

wire-ios-sync-engine/Source/Calling/WireCallCenterV3.swift

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -500,44 +500,7 @@ extension WireCallCenterV3 {
500500
return false
501501
}
502502

503-
switch conversation.messageProtocol {
504-
case .mls:
505-
return shouldEndCallForMLS(
506-
previousParticipants: previousParticipants,
507-
newParticipants: newParticipants
508-
)
509-
case .mixed, .proteus:
510-
return shouldEndCallForProteus(
511-
previousParticipants: previousParticipants,
512-
newParticipants: newParticipants
513-
)
514-
}
515-
}
516-
517-
private func shouldEndCallForMLS(
518-
previousParticipants: [AVSCallMember],
519-
newParticipants: [AVSCallMember]
520-
) -> Bool {
521-
/// We assume that the 2nd participant is the other user.
522-
/// If the other user's audio state changes from `established` to `connecting`,
523-
/// it means the call connection was dropped and the call should be ended.
524-
/// https://wearezeta.atlassian.net/wiki/spaces/PAD/pages/1314750477/2024-07-29+1+1+calls+over+SFT
525-
guard
526-
previousParticipants.count == 2,
527-
newParticipants.count == 2,
528-
previousParticipants[1].audioState == .established,
529-
newParticipants[1].audioState == .connecting
530-
else {
531-
return false
532-
}
533-
return true
534-
}
535-
536-
private func shouldEndCallForProteus(
537-
previousParticipants: [AVSCallMember],
538-
newParticipants: [AVSCallMember]
539-
) -> Bool {
540-
previousParticipants.count == 2 && newParticipants.count == 1
503+
return previousParticipants.count == 2 && newParticipants.count == 1
541504
}
542505

543506
}

0 commit comments

Comments
 (0)