Skip to content

iOS-4691 Make separate NotificationsCore package #3385

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

Merged
merged 2 commits into from
May 28, 2025
Merged
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
22 changes: 11 additions & 11 deletions Anytype.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
2AB511AE29093CB4005D0A91 /* InlineMarkdownListenerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB511AD29093CB4005D0A91 /* InlineMarkdownListenerTests.swift */; };
2ADB57862CB6B6FE00BFC386 /* Cache in Frameworks */ = {isa = PBXBuildFile; productRef = 2ADB57852CB6B6FE00BFC386 /* Cache */; };
2ADD66782CB57036009ED95E /* MessageAttachmentsGridLayoutBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADD66772CB57036009ED95E /* MessageAttachmentsGridLayoutBuilderTests.swift */; };
2E074C4C2DE620E800260ABD /* NotificationsCore in Frameworks */ = {isa = PBXBuildFile; productRef = 2E074C4B2DE620E800260ABD /* NotificationsCore */; };
2E074C4E2DE623DB00260ABD /* NotificationsCore in Frameworks */ = {isa = PBXBuildFile; productRef = 2E074C4D2DE623DB00260ABD /* NotificationsCore */; };
2E3058142D81DF7F00BF4F25 /* AnytypeNotificationServiceExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 2E30580D2D81DF7E00BF4F25 /* AnytypeNotificationServiceExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
2E428A262DA836B900B849EF /* Factory in Frameworks */ = {isa = PBXBuildFile; productRef = 2E428A252DA836B900B849EF /* Factory */; };
2E63D9B72D56520C008A733A /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = 2E63D9B62D56520C008A733A /* FirebaseMessaging */; };
2ED425D22DDE3CF5008C7AD3 /* Loc in Frameworks */ = {isa = PBXBuildFile; productRef = 2ED425D12DDE3CF5008C7AD3 /* Loc */; };
2ED5E1542DAFE2A700B59485 /* AnytypeCore in Frameworks */ = {isa = PBXBuildFile; productRef = 2ED5E1532DAFE2A700B59485 /* AnytypeCore */; };
2EDD08442DA833720050397F /* Services in Frameworks */ = {isa = PBXBuildFile; productRef = 2EDD08432DA833720050397F /* Services */; };
2EEE411E2C1080AD000AB88B /* CachedAsyncImage in Frameworks */ = {isa = PBXBuildFile; productRef = 2EEE411D2C1080AD000AB88B /* CachedAsyncImage */; };
3D24B09C2C1A2DAF00795BAA /* ConfettiSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 3D24B09B2C1A2DAF00795BAA /* ConfettiSwiftUI */; };
3D30407727D66E7E00FFE0EB /* InfoContainerMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D30407627D66E7E00FFE0EB /* InfoContainerMock.swift */; };
Expand Down Expand Up @@ -329,6 +329,7 @@
538ABD4E284F9F88000D3CCC /* Collections in Frameworks */,
7411879B2D9ADD200006EA41 /* Loc in Frameworks */,
2A94B5D329B88E95009AE2A7 /* Sentry in Frameworks */,
2E074C4C2DE620E800260ABD /* NotificationsCore in Frameworks */,
1259300E26F3A6AE00B115CD /* Kingfisher in Frameworks */,
2ADB57862CB6B6FE00BFC386 /* Cache in Frameworks */,
538ABD50284F9F88000D3CCC /* DequeModule in Frameworks */,
Expand Down Expand Up @@ -373,9 +374,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
2EDD08442DA833720050397F /* Services in Frameworks */,
2E074C4E2DE623DB00260ABD /* NotificationsCore in Frameworks */,
2ED425D22DDE3CF5008C7AD3 /* Loc in Frameworks */,
2E428A262DA836B900B849EF /* Factory in Frameworks */,
2ED5E1542DAFE2A700B59485 /* AnytypeCore in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -695,6 +695,7 @@
74EB806B2D79D3EA003F8D84 /* Assets */,
7411879A2D9ADD200006EA41 /* Loc */,
746F06002DB8E712005795F7 /* DesignKit */,
2E074C4B2DE620E800260ABD /* NotificationsCore */,
);
productName = Anytype;
productReference = 0303ECFB22D8EDAA005C552B /* Anytype.app */;
Expand Down Expand Up @@ -3125,10 +3126,13 @@
package = 2ADB57842CB6B6FE00BFC386 /* XCRemoteSwiftPackageReference "Cache" */;
productName = Cache;
};
2E428A252DA836B900B849EF /* Factory */ = {
2E074C4B2DE620E800260ABD /* NotificationsCore */ = {
isa = XCSwiftPackageProductDependency;
package = 2AC1262B2B90F65F003A4A8D /* XCRemoteSwiftPackageReference "Factory" */;
productName = Factory;
productName = NotificationsCore;
};
2E074C4D2DE623DB00260ABD /* NotificationsCore */ = {
isa = XCSwiftPackageProductDependency;
productName = NotificationsCore;
};
2E63D9B62D56520C008A733A /* FirebaseMessaging */ = {
isa = XCSwiftPackageProductDependency;
Expand All @@ -3143,10 +3147,6 @@
isa = XCSwiftPackageProductDependency;
productName = AnytypeCore;
};
2EDD08432DA833720050397F /* Services */ = {
isa = XCSwiftPackageProductDependency;
productName = Services;
};
2EEE411D2C1080AD000AB88B /* CachedAsyncImage */ = {
isa = XCSwiftPackageProductDependency;
package = 2EEE411C2C1080AD000AB88B /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */;
Expand Down
1 change: 1 addition & 0 deletions Anytype/Sources/ApplicationLayer/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import UIKit
import AnytypeCore
import FirebaseMessaging
import Services
import NotificationsCore

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Services
import AnytypeCore
import NotificationsCore

protocol EncryptionKeyEventHandlerProtocol: AnyObject, Sendable {
func startSubscription() async
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import UserNotifications
import Services
import AnytypeCore
import Loc
import NotificationsCore

class NotificationService: UNNotificationServiceExtension {

private let decryptionPushContentService: any DecryptionPushContentServiceProtocol = Container.shared.decryptionPushContentService()
private let basicUserInfoStorage: any BasicUserInfoStorageProtocol = Container.shared.basicUserInfoStorage()
private let decryptionPushContentService: any DecryptionPushContentServiceProtocol = DecryptionPushContentService()

var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {

if FeatureFlags.checkLoginInNotificationService, basicUserInfoStorage.usersId.isEmpty {
return
}

self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ public extension FeatureFlags {
value(for: .chatWidget)
}

static var checkLoginInNotificationService: Bool {
value(for: .checkLoginInNotificationService)
}

static var rainbowViews: Bool {
value(for: .rainbowViews)
}
Expand Down Expand Up @@ -231,7 +227,6 @@ public extension FeatureFlags {
.binScreenEmptyAction,
.openFullscreenObjectsFromSetWidget,
.chatWidget,
.checkLoginInNotificationService,
.rainbowViews,
.showAlertOnAssert,
.analytics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,6 @@ public extension FeatureDescription {
defaultValue: false
)

static let checkLoginInNotificationService = FeatureDescription(
title: "Check login in NotificationService",
type: .feature(author: "[email protected]", releaseVersion: "11"),
defaultValue: true
)

// MARK: - Debug

static let rainbowViews = FeatureDescription(
Expand Down
8 changes: 8 additions & 0 deletions Modules/NotificationsCore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
37 changes: 37 additions & 0 deletions Modules/NotificationsCore/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "NotificationsCore",
platforms: [
.iOS(.v16),
],
products: [
.library(
name: "NotificationsCore",
type: .dynamic,
targets: ["NotificationsCore"]),
],
dependencies: [
.package(path: "../AnytypeCore"),
.package(path: "../SecureService"),
],
targets: [
.target(
name: "NotificationsCore",
dependencies: [
"AnytypeCore",
"SecureService"
],
swiftSettings: [
.swiftLanguageMode(.v6)
]
),
.testTarget(
name: "NotificationsCoreTests",
dependencies: ["NotificationsCore"]
),
]
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import CryptoKit

public protocol CryptoServiceProtocol: AnyObject, Sendable {
protocol CryptoServiceProtocol: AnyObject, Sendable {
func decryptAESGCM(data: Data, keyData: Data) throws -> Data
}

Expand All @@ -22,6 +22,6 @@ final class CryptoService: CryptoServiceProtocol {
}
}

public enum CryptoError: Error {
enum CryptoError: Error {
case decryptionFailed
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ public protocol DecryptionPushContentServiceProtocol: AnyObject, Sendable {
func decrypt(_ encryptedData: Data, keyId: String) -> DecryptedPushContent?
}

final class DecryptionPushContentService: DecryptionPushContentServiceProtocol {
public final class DecryptionPushContentService: DecryptionPushContentServiceProtocol {

private let cryptoService: any CryptoServiceProtocol = Container.shared.cryptoService()
private let encryptionKeyService: any EncryptionKeyServiceProtocol = Container.shared.encryptionKeyService()
private let cryptoService: any CryptoServiceProtocol = CryptoService()
private let encryptionKeyService: any EncryptionKeyServiceProtocol = EncryptionKeyService()
private let decoder = JSONDecoder()

func decrypt(_ encryptedData: Data, keyId: String) -> DecryptedPushContent? {
public init() {}

public func decrypt(_ encryptedData: Data, keyId: String) -> DecryptedPushContent? {
do {
let keyString = try encryptionKeyService.obtainKeyById(keyId)

Expand All @@ -30,6 +32,6 @@ final class DecryptionPushContentService: DecryptionPushContentServiceProtocol {
}


public enum DecryptionPushContentError: Error {
enum DecryptionPushContentError: Error {
case keyEncodeFailed
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ public protocol EncryptionKeyServiceProtocol: AnyObject, Sendable {
func saveKey(_ key: String, keyId: String) throws
}

final class EncryptionKeyService: EncryptionKeyServiceProtocol {
public final class EncryptionKeyService: EncryptionKeyServiceProtocol {

private let keychainStore: any KeychainStoreProtocol = Container.shared.keychainStore()
private let keychainStore: any KeychainStoreProtocol = KeychainStore()

func obtainKeyById(_ keyId: String) throws -> String {
public init() {}

public func obtainKeyById(_ keyId: String) throws -> String {
try keychainStore.retreiveItem(queryable: query(with: keyId))
}

func saveKey(_ key: String, keyId: String) throws {
public func saveKey(_ key: String, keyId: String) throws {
try keychainStore.storeItem(item: key, queryable: query(with: keyId))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Testing
@testable import NotificationsCore

@Test func example() async throws {
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
}
6 changes: 4 additions & 2 deletions Modules/Services/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ let package = Package(
.package(url: "https://github.com/hmlongco/Factory", revision: "2.3.1"),
.package(path: "../ProtobufMessages"),
.package(path: "../AnytypeCore"),
.package(path: "../SecureService")
.package(path: "../SecureService"),
.package(path: "../NotificationsCore")
],
targets: [
.target(
Expand All @@ -27,7 +28,8 @@ let package = Package(
"Factory",
"ProtobufMessages",
"AnytypeCore",
"SecureService"
"SecureService",
"NotificationsCore"
],
path: "Sources",
swiftSettings: [
Expand Down
9 changes: 1 addition & 8 deletions Modules/Services/Sources/ServicesDI.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import SecureService
import NotificationsCore
// Automatically export Factory when import Servies
@_exported import Factory

Expand Down Expand Up @@ -165,14 +166,6 @@ public extension Container {
self { EncryptionKeyService() }.shared
}

var cryptoService: Factory<CryptoServiceProtocol> {
self { CryptoService() }.shared
}

var decryptionPushContentService: Factory<DecryptionPushContentServiceProtocol> {
self { DecryptionPushContentService() }.shared
}

var basicUserInfoStorage: Factory<BasicUserInfoStorageProtocol> {
self { BasicUserInfoStorage() }.singleton
}
Expand Down
Loading