-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: generate notification for new messages - WPB-11647 #2340
Open
jullianm
wants to merge
17
commits into
refactor/nse-pull-pending-events
Choose a base branch
from
refactor/generate-notification-new-messages
base: refactor/nse-pull-pending-events
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,080
−26
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7d0507c
Merge branch 'develop' into refactor/generate-notification-new-messages
jullianm 1d6a20f
add builders
jullianm 9dca21b
add NotificationBuilder protocol, add Notification components (sound,…
jullianm a4c4bec
add notification actions
jullianm 77178e2
add title and body composer
jullianm 9f4d6d2
add Notification components
jullianm 5e63872
generate notification: image, ephemeral, text
jullianm 552a317
add methods to local stores, use repo and stores from notification bu…
jullianm b570d49
add new message builder UT, fix notification session UT
jullianm 2c3410a
add TODO and code doc, clean up
jullianm 8635b5d
Merge branch 'refactor/nse-pull-pending-events' into refactor/generat…
jullianm 2ff7e8a
Merge branch 'develop' into refactor/generate-notification-new-messages
jullianm 87885f6
Merge branch 'refactor/nse-pull-pending-events' into refactor/generat…
jullianm 0bc1b75
lint and format
jullianm e26e471
Merge branch 'develop' into refactor/generate-notification-new-messages
jullianm 6ff2424
lint and format
jullianm 8823f80
Merge branch 'refactor/nse-pull-pending-events' into refactor/generat…
jullianm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
WireDomain/Sources/WireDomain/Helpers/ConversationEvent+Notifications.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 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 | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import Foundation | ||
import WireAPI | ||
|
||
extension ConversationEvent { | ||
var senderID: UserID { | ||
switch self { | ||
case let .accessUpdate(conversationAccessUpdateEvent): | ||
conversationAccessUpdateEvent.senderID | ||
case let .codeUpdate(conversationCodeUpdateEvent): | ||
conversationCodeUpdateEvent.senderID | ||
case let .create(conversationCreateEvent): | ||
conversationCreateEvent.senderID | ||
case let .delete(conversationDeleteEvent): | ||
conversationDeleteEvent.senderID | ||
case let .memberJoin(conversationMemberJoinEvent): | ||
conversationMemberJoinEvent.senderID | ||
case let .memberLeave(conversationMemberLeaveEvent): | ||
conversationMemberLeaveEvent.senderID | ||
case let .memberUpdate(conversationMemberUpdateEvent): | ||
conversationMemberUpdateEvent.senderID | ||
case let .messageTimerUpdate(conversationMessageTimerUpdateEvent): | ||
conversationMessageTimerUpdateEvent.senderID | ||
case let .mlsMessageAdd(conversationMLSMessageAddEvent): | ||
conversationMLSMessageAddEvent.senderID | ||
case let .mlsWelcome(conversationMLSWelcomeEvent): | ||
conversationMLSWelcomeEvent.senderID | ||
case let .proteusMessageAdd(conversationProteusMessageAddEvent): | ||
conversationProteusMessageAddEvent.senderID | ||
case let .protocolUpdate(conversationProtocolUpdateEvent): | ||
conversationProtocolUpdateEvent.senderID | ||
case let .receiptModeUpdate(conversationReceiptModeUpdateEvent): | ||
conversationReceiptModeUpdateEvent.senderID | ||
case let .rename(conversationRenameEvent): | ||
conversationRenameEvent.senderID | ||
case let .typing(conversationTypingEvent): | ||
conversationTypingEvent.senderID | ||
} | ||
} | ||
|
||
var conversationID: WireAPI.QualifiedID { | ||
switch self { | ||
case let .accessUpdate(conversationAccessUpdateEvent): | ||
conversationAccessUpdateEvent.conversationID | ||
case let .codeUpdate(conversationCodeUpdateEvent): | ||
conversationCodeUpdateEvent.conversationID | ||
case let .create(conversationCreateEvent): | ||
conversationCreateEvent.conversationID | ||
case let .delete(conversationDeleteEvent): | ||
conversationDeleteEvent.conversationID | ||
case let .memberJoin(conversationMemberJoinEvent): | ||
conversationMemberJoinEvent.conversationID | ||
case let .memberLeave(conversationMemberLeaveEvent): | ||
conversationMemberLeaveEvent.conversationID | ||
case let .memberUpdate(conversationMemberUpdateEvent): | ||
conversationMemberUpdateEvent.conversationID | ||
case let .messageTimerUpdate(conversationMessageTimerUpdateEvent): | ||
conversationMessageTimerUpdateEvent.conversationID | ||
case let .mlsMessageAdd(conversationMLSMessageAddEvent): | ||
conversationMLSMessageAddEvent.conversationID | ||
case let .mlsWelcome(conversationMLSWelcomeEvent): | ||
conversationMLSWelcomeEvent.conversationID | ||
case let .proteusMessageAdd(conversationProteusMessageAddEvent): | ||
conversationProteusMessageAddEvent.conversationID | ||
case let .protocolUpdate(conversationProtocolUpdateEvent): | ||
conversationProtocolUpdateEvent.conversationID | ||
case let .receiptModeUpdate(conversationReceiptModeUpdateEvent): | ||
conversationReceiptModeUpdateEvent.conversationID | ||
case let .rename(conversationRenameEvent): | ||
conversationRenameEvent.conversationID | ||
case let .typing(conversationTypingEvent): | ||
conversationTypingEvent.conversationID | ||
} | ||
} | ||
|
||
var timestamp: Date? { | ||
switch self { | ||
case let .create(conversationCreateEvent): | ||
conversationCreateEvent.timestamp | ||
case let .delete(conversationDeleteEvent): | ||
conversationDeleteEvent.timestamp | ||
case let .memberJoin(conversationMemberJoinEvent): | ||
conversationMemberJoinEvent.timestamp | ||
case let .memberLeave(conversationMemberLeaveEvent): | ||
conversationMemberLeaveEvent.timestamp | ||
case let .memberUpdate(conversationMemberUpdateEvent): | ||
conversationMemberUpdateEvent.timestamp | ||
case let .messageTimerUpdate(conversationMessageTimerUpdateEvent): | ||
conversationMessageTimerUpdateEvent.timestamp | ||
case let .mlsMessageAdd(conversationMLSMessageAddEvent): | ||
conversationMLSMessageAddEvent.timestamp | ||
case let .proteusMessageAdd(conversationProteusMessageAddEvent): | ||
conversationProteusMessageAddEvent.timestamp | ||
case let .rename(conversationRenameEvent): | ||
conversationRenameEvent.timestamp | ||
default: | ||
nil | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
WireDomain/Sources/WireDomain/Helpers/ProtobufMessageHelper.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 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 | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import WireProtos | ||
|
||
struct ProtobufMessageHelper { | ||
|
||
private init() {} | ||
|
||
static func getProtobufMessage( | ||
from base64Message: String, | ||
externalData: String? = nil | ||
) -> (GenericMessage, GenericMessage.OneOf_Content)? { | ||
var genericMessage = GenericMessage(withBase64String: base64Message) | ||
|
||
/// If the encrypted payload is bigger than a certain size, an External Message is sent instead of a regular | ||
/// message. | ||
/// See `External` section from https://github.com/wireapp/generic-message-proto | ||
/// See `External messages` section from | ||
/// https://wearezeta.atlassian.net/wiki/spaces/ENGINEERIN/pages/20545866/Messages | ||
/// | ||
if let externalData, | ||
case let .some(.external(external)) = genericMessage?.content { | ||
|
||
/// Content message is external, we decrypt the external payload | ||
/// and turns it back into a generic non-external content message. | ||
if let decryptedGenericMessage = decryptExternalMessage( | ||
externalData: externalData, | ||
external: external | ||
) { | ||
genericMessage = decryptedGenericMessage | ||
} else { | ||
return nil | ||
} | ||
} | ||
|
||
guard let genericMessage, let content = genericMessage.content else { | ||
return nil | ||
} | ||
|
||
return (genericMessage, content) | ||
} | ||
|
||
private static func decryptExternalMessage( | ||
externalData: String, | ||
external: External | ||
) -> GenericMessage? { | ||
let externalData = Data(base64Encoded: externalData) | ||
let externalSha256 = externalData?.zmSHA256Digest() | ||
|
||
guard externalSha256 == external.sha256 else { | ||
return nil | ||
} | ||
|
||
let decryptedData = externalData?.zmDecryptPrefixedPlainTextIV( | ||
key: external.otrKey | ||
) | ||
|
||
guard let message = GenericMessage( | ||
withBase64String: decryptedData?.base64String() | ||
) else { | ||
return nil | ||
} | ||
|
||
return message | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
WireDomain/Sources/WireDomain/Notifications/Actions/AcceptConnectionNotificationAction.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 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 | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import Foundation | ||
|
||
struct AcceptConnectionNotificationAction: NotificationAction { | ||
var identifier: String { | ||
"acceptConnectAction" | ||
} | ||
|
||
var title: String { | ||
"connection.accept" | ||
} | ||
|
||
var isDestructive: Bool { | ||
false | ||
} | ||
|
||
var opensApplication: Bool { | ||
false | ||
} | ||
|
||
var requiresAuthentication: Bool { | ||
false | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
WireDomain/Sources/WireDomain/Notifications/Actions/CallbackNotificationAction.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 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 | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import Foundation | ||
|
||
struct CallbackNotificationAction: NotificationAction { | ||
var identifier: String { | ||
"callbackCallAction" | ||
} | ||
|
||
var title: String { | ||
"call.callback" | ||
} | ||
|
||
var isDestructive: Bool { | ||
false | ||
} | ||
|
||
var opensApplication: Bool { | ||
true | ||
} | ||
|
||
var requiresAuthentication: Bool { | ||
false | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
WireDomain/Sources/WireDomain/Notifications/Actions/IgnoreCallNotificationAction.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 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 | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
struct IgnoreCallNotificationAction: NotificationAction { | ||
var identifier: String { | ||
"ignoreCallAction" | ||
} | ||
|
||
var title: String { | ||
"call.ignore" | ||
} | ||
|
||
var isDestructive: Bool { | ||
true | ||
} | ||
|
||
var opensApplication: Bool { | ||
false | ||
} | ||
|
||
var requiresAuthentication: Bool { | ||
false | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this remove from Assembly?