From 8ac66ab943226388fcec9b49bf0a5bab3a985be7 Mon Sep 17 00:00:00 2001 From: Jullian Mercier <31648126+jullianm@users.noreply.github.com> Date: Mon, 13 Jan 2025 11:50:35 +0100 Subject: [PATCH] generate notification for deleted conversation, add UT --- .../NewSystemMessageNotificationBuilder.swift | 23 +++++++++++++++++-- ...ystemMessageNotificationBodyComposer.swift | 3 +-- ...ystemMessageNotificationBuilderTests.swift | 8 ++++--- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/WireDomain/Sources/WireDomain/Notifications/Builders/NewSystemMessageNotificationBuilder.swift b/WireDomain/Sources/WireDomain/Notifications/Builders/NewSystemMessageNotificationBuilder.swift index bcd4177b78..b9dc7f5ecc 100644 --- a/WireDomain/Sources/WireDomain/Notifications/Builders/NewSystemMessageNotificationBuilder.swift +++ b/WireDomain/Sources/WireDomain/Notifications/Builders/NewSystemMessageNotificationBuilder.swift @@ -108,8 +108,7 @@ struct NewSystemMessageNotificationBuilder: NotificationBuilder { // TODO: [WPB-11661] break case .conversationDeleted: - // TODO: [WPB-11658] - break + return buildDeletedConversationNotification() case .messageTimerUpdate: // TODO: [WPB-11663] break @@ -140,6 +139,26 @@ struct NewSystemMessageNotificationBuilder: NotificationBuilder { return content } + private func buildDeletedConversationNotification() -> UNMutableNotificationContent { + let content = UNMutableNotificationContent() + + if let title = makeTitle() { + content.title = title + } + + let body = NotificationBody.newSystemMessage( + .deletedGroup(senderName: context.senderName) + ) + + content.body = body.make() + content.categoryIdentifier = makeCategory() + content.sound = makeSound() + content.userInfo = makeUserInfo() + content.threadIdentifier = context.conversationID.uuid.transportString() + + return content + } + // MARK: - Helpers private func makeTitle() -> String? { diff --git a/WireDomain/Sources/WireDomain/Notifications/Composers/NewSystemMessageNotificationBodyComposer.swift b/WireDomain/Sources/WireDomain/Notifications/Composers/NewSystemMessageNotificationBodyComposer.swift index 40bf5e5572..d8284617bf 100644 --- a/WireDomain/Sources/WireDomain/Notifications/Composers/NewSystemMessageNotificationBodyComposer.swift +++ b/WireDomain/Sources/WireDomain/Notifications/Composers/NewSystemMessageNotificationBodyComposer.swift @@ -39,8 +39,7 @@ struct NewSystemMessageNotificationBodyComposer { // TODO: [WPB-11663] "" case let .deletedGroup(senderName): - // TODO: [WPB-11658] - "" + senderName != nil ? "\(senderName!) deleted the group" : "Someone deleted the group" } } } diff --git a/WireDomain/Tests/WireDomainTests/Notifications/NewSystemMessageNotificationBuilderTests.swift b/WireDomain/Tests/WireDomainTests/Notifications/NewSystemMessageNotificationBuilderTests.swift index 6521b1eb8e..ccda82b991 100644 --- a/WireDomain/Tests/WireDomainTests/Notifications/NewSystemMessageNotificationBuilderTests.swift +++ b/WireDomain/Tests/WireDomainTests/Notifications/NewSystemMessageNotificationBuilderTests.swift @@ -119,7 +119,8 @@ final class NewSystemMessageNotificationBuilderTests: XCTestCase { await setupMock(isGroup: isGroup, isTeam: isTeam, selfUserID: .mockID4) let systemMessages: [NewSystemMessageNotificationBuilder.SystemMessage] = [ - .memberLeave(removedUserIDs: [.mockID4]) // concerns self user + .memberLeave(removedUserIDs: [.mockID4]), // concerns self user + .conversationDeleted ] for systemMessage in systemMessages { @@ -154,7 +155,8 @@ final class NewSystemMessageNotificationBuilderTests: XCTestCase { await setupMock(isGroup: isGroup, isTeam: isTeam, selfUserID: .mockID4) let systemMessages: [NewSystemMessageNotificationBuilder.SystemMessage] = [ - .memberLeave(removedUserIDs: [.mockID4]) // concerns self user + .memberLeave(removedUserIDs: [.mockID4]), // concerns self user + .conversationDeleted ] for systemMessage in systemMessages { @@ -236,7 +238,7 @@ final class NewSystemMessageNotificationBuilderTests: XCTestCase { case .memberJoin: break case .conversationDeleted: - break + XCTAssertEqual(notificationContent.body, "\(Scaffolding.senderName) deleted the group") case .messageTimerUpdate: break }