Skip to content

Commit

Permalink
refactor: process conversation rename event - WPB-10177 (#2175)
Browse files Browse the repository at this point in the history
  • Loading branch information
jullianm authored Nov 26, 2024
1 parent d6ad59d commit 163ce55
Show file tree
Hide file tree
Showing 21 changed files with 715 additions and 512 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct ConversationMemberLeaveEventDecoder {
senderID: senderID,
timestamp: timestamp.date,
removedUserIDs: payload.userIDs,
reason: payload.reason ?? .left
reason: payload.reason ?? .userLeft
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public enum ConversationMemberLeaveReason: String, Codable, Sendable {

/// The user left the conversation by themselves.

case left
case userLeft

/// The user was removed from the conversation by an admin.

case removed
case userRemoved

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
C9C8FDD22C9DBE0E00702B91 /* UserClientAddEventProcessorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9C8FDC92C9DBE0E00702B91 /* UserClientAddEventProcessorTests.swift */; };
C9C8FDD32C9DBE0E00702B91 /* UserLegalHoldDisableEventProcessorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9C8FDCA2C9DBE0E00702B91 /* UserLegalHoldDisableEventProcessorTests.swift */; };
C9C8FDD42C9DBE0E00702B91 /* UserLegalholdRequestEventProcessorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9C8FDCB2C9DBE0E00702B91 /* UserLegalholdRequestEventProcessorTests.swift */; };
C9D574582CEB9FB400012A0E /* ConversationRenameEventProcessorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D574572CEB9FB400012A0E /* ConversationRenameEventProcessorTests.swift */; };
C9E0C9BB2C91B76F00CE6607 /* WireTestingPackage in Frameworks */ = {isa = PBXBuildFile; productRef = C9E0C9BA2C91B76F00CE6607 /* WireTestingPackage */; };
C9E8A3AE2C73878B0093DD5C /* ConnectionsRepositoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9E8A3AD2C73878B0093DD5C /* ConnectionsRepositoryTests.swift */; };
C9E8A3B72C749F2A0093DD5C /* ConversationLabelsRepositoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9E8A3B62C749F2A0093DD5C /* ConversationLabelsRepositoryTests.swift */; };
Expand Down Expand Up @@ -237,6 +238,7 @@
C9C8FDC92C9DBE0E00702B91 /* UserClientAddEventProcessorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserClientAddEventProcessorTests.swift; sourceTree = "<group>"; };
C9C8FDCA2C9DBE0E00702B91 /* UserLegalHoldDisableEventProcessorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserLegalHoldDisableEventProcessorTests.swift; sourceTree = "<group>"; };
C9C8FDCB2C9DBE0E00702B91 /* UserLegalholdRequestEventProcessorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserLegalholdRequestEventProcessorTests.swift; sourceTree = "<group>"; };
C9D574572CEB9FB400012A0E /* ConversationRenameEventProcessorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationRenameEventProcessorTests.swift; sourceTree = "<group>"; };
C9E8A3AD2C73878B0093DD5C /* ConnectionsRepositoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionsRepositoryTests.swift; sourceTree = "<group>"; };
C9E8A3B62C749F2A0093DD5C /* ConversationLabelsRepositoryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConversationLabelsRepositoryTests.swift; sourceTree = "<group>"; };
C9E8A3BF2C761EDD0093DD5C /* FeatureConfigRepositoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureConfigRepositoryTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -481,6 +483,7 @@
C96B75252CDB7688003A85EB /* ConversationMemberUpdateEventProcessorTests.swift */,
C96B75262CDB7688003A85EB /* ConversationProtocolUpdateEventProcessorTests.swift */,
C96B75272CDB7688003A85EB /* ConversationReceiptModeUpdateEventProcessorTests.swift */,
C9D574572CEB9FB400012A0E /* ConversationRenameEventProcessorTests.swift */,
);
path = ConversationEventProcessor;
sourceTree = "<group>";
Expand Down Expand Up @@ -1128,6 +1131,8 @@
C97C01BB2CBE5E65000683C5 /* UserUpdateEventProcessorTests.swift in Sources */,
C9C1024E2CE7984300EA273F /* OneOnOneResolverTests.swift in Sources */,
C97C013D2CAD7D69000683C5 /* UserPropertiesDeleteEventProcessorTests.swift in Sources */,
C9D574582CEB9FB400012A0E /* ConversationRenameEventProcessorTests.swift in Sources */,
C97C01502CB01BDF000683C5 /* OneOnOneResolverTests.swift in Sources */,
C9C8FDD22C9DBE0E00702B91 /* UserClientAddEventProcessorTests.swift in Sources */,
C9C8FDD12C9DBE0E00702B91 /* TeamMemberUpdateEventProcessorTests.swift in Sources */,
C9C1024C2CE7935600EA273F /* UserConnectionEventProcessorTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct ConversationReceiptModeUpdateEventProcessor: ConversationReceiptModeUpdat
let userRepository: any UserRepositoryProtocol
let conversationRepository: any ConversationRepositoryProtocol
let conversationLocalStore: any ConversationLocalStoreProtocol
let messageRepository: any MessageRepositoryProtocol

func processEvent(_ event: ConversationReceiptModeUpdateEvent) async throws {
let senderID = event.senderID
Expand Down Expand Up @@ -69,20 +70,17 @@ struct ConversationReceiptModeUpdateEventProcessor: ConversationReceiptModeUpdat
timestamp: .now
)

await conversationRepository.addSystemMessage(
systemMessage,
to: conversation
let systemMessageType: MessageType = .readReceiptsStatus(
isEnabled: isEnabled,
sender: (senderID.uuid, senderID.domain),
date: .now
)

let isConversationArchived = await conversationLocalStore.isConversationArchived(conversation)
let mutedMessageTypes = await conversationLocalStore.conversationMutedMessageTypes(conversation)

if isConversationArchived, mutedMessageTypes == .none {
await conversationLocalStore.storeConversation(
isArchived: false,
for: conversation
)
}
await messageRepository.addMessageToConversation(
messageType: systemMessageType,
conversationID: conversationID.uuid,
conversationDomain: conversationID.domain
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,22 @@ protocol ConversationRenameEventProcessorProtocol {

struct ConversationRenameEventProcessor: ConversationRenameEventProcessorProtocol {

func processEvent(_: ConversationRenameEvent) async throws {
// TODO: [WPB-10177]
assertionFailure("not implemented yet")
let repository: any ConversationRepositoryProtocol

func processEvent(_ event: ConversationRenameEvent) async throws {
let newName = event.newName
let conversationID = event.conversationID
let senderID = event.senderID
let timestamp = event.timestamp

await repository.updateConversationName(
newName: newName,
conversationID: conversationID.uuid,
conversationDomain: conversationID.domain,
senderID: senderID.uuid,
senderDomain: senderID.domain,
date: timestamp
)
}

}
Loading

0 comments on commit 163ce55

Please sign in to comment.