Skip to content
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
wants to merge 17 commits into
base: refactor/nse-pull-pending-events
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions WireDomain/Sources/WireDomain/Assembly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ public final class Assembly {
apiService: apiService
).makeAPI(for: apiVersion)

private lazy var updateEventDecryptor = UpdateEventDecryptor(
proteusService: proteusService,
context: context
)

// MARK: - Repositories and local stores Init

private lazy var userLocalStore = UserLocalStore(context: context)
Expand Down Expand Up @@ -98,10 +93,6 @@ extension Assembly {
self.pushChannel
}

Injector.register(UpdateEventDecryptorProtocol.self) {
Copy link
Collaborator

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?

self.updateEventDecryptor
}

Injector.register(UpdateEventsLocalStoreProtocol.self) {
self.updateEventsLocalStore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@

static func resolve<Service>() -> Service {
typealias FactoryType = () -> Any
return _genericResolve(serviceType: Service.self) { (factory: FactoryType) in

Check failure on line 104 in WireDomain/Sources/WireDomain/Dependency Injection/Injector.swift

View workflow job for this annotation

GitHub Actions / PR Tests / Run tests

generic parameter 'Arguments' could not be inferred

Check failure on line 104 in WireDomain/Sources/WireDomain/Dependency Injection/Injector.swift

View workflow job for this annotation

GitHub Actions / PR Tests / Run tests

cannot convert value of type '(() -> Any) -> Any' to expected argument type '((_) -> Any) -> Any'
factory(())

Check failure on line 105 in WireDomain/Sources/WireDomain/Dependency Injection/Injector.swift

View workflow job for this annotation

GitHub Actions / PR Tests / Run tests

argument passed to call that takes no arguments
}
}

Expand Down Expand Up @@ -165,7 +165,8 @@
invoker: @escaping ((Arguments) -> Any) -> Any
) -> Service {
var resolvedInstance: Service?
var type: Any.Type = if let optionalType = Service.self as? OptionalProtocol.Type {

let type: Any.Type = if let optionalType = Service.self as? OptionalProtocol.Type {
optionalType.wrappedType
} else {
Service.self
Expand Down
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 WireDomain/Sources/WireDomain/Helpers/ProtobufMessageHelper.swift
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
}

}
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
}

}
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
}

}
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
}

}
Loading
Loading