Skip to content

Commit 2099de3

Browse files
authored
Merge pull request #3385 from anyproto/ios-4691-make-separate-notificationscore-package
iOS-4691 Make separate NotificationsCore package
2 parents 4a0a760 + 143deb9 commit 2099de3

File tree

16 files changed

+86
-50
lines changed

16 files changed

+86
-50
lines changed

Anytype.xcodeproj/project.pbxproj

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@
4949
2AB511AE29093CB4005D0A91 /* InlineMarkdownListenerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AB511AD29093CB4005D0A91 /* InlineMarkdownListenerTests.swift */; };
5050
2ADB57862CB6B6FE00BFC386 /* Cache in Frameworks */ = {isa = PBXBuildFile; productRef = 2ADB57852CB6B6FE00BFC386 /* Cache */; };
5151
2ADD66782CB57036009ED95E /* MessageAttachmentsGridLayoutBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ADD66772CB57036009ED95E /* MessageAttachmentsGridLayoutBuilderTests.swift */; };
52+
2E074C4C2DE620E800260ABD /* NotificationsCore in Frameworks */ = {isa = PBXBuildFile; productRef = 2E074C4B2DE620E800260ABD /* NotificationsCore */; };
53+
2E074C4E2DE623DB00260ABD /* NotificationsCore in Frameworks */ = {isa = PBXBuildFile; productRef = 2E074C4D2DE623DB00260ABD /* NotificationsCore */; };
5254
2E3058142D81DF7F00BF4F25 /* AnytypeNotificationServiceExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 2E30580D2D81DF7E00BF4F25 /* AnytypeNotificationServiceExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
53-
2E428A262DA836B900B849EF /* Factory in Frameworks */ = {isa = PBXBuildFile; productRef = 2E428A252DA836B900B849EF /* Factory */; };
5455
2E63D9B72D56520C008A733A /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = 2E63D9B62D56520C008A733A /* FirebaseMessaging */; };
5556
2ED425D22DDE3CF5008C7AD3 /* Loc in Frameworks */ = {isa = PBXBuildFile; productRef = 2ED425D12DDE3CF5008C7AD3 /* Loc */; };
5657
2ED5E1542DAFE2A700B59485 /* AnytypeCore in Frameworks */ = {isa = PBXBuildFile; productRef = 2ED5E1532DAFE2A700B59485 /* AnytypeCore */; };
57-
2EDD08442DA833720050397F /* Services in Frameworks */ = {isa = PBXBuildFile; productRef = 2EDD08432DA833720050397F /* Services */; };
5858
2EEE411E2C1080AD000AB88B /* CachedAsyncImage in Frameworks */ = {isa = PBXBuildFile; productRef = 2EEE411D2C1080AD000AB88B /* CachedAsyncImage */; };
5959
3D24B09C2C1A2DAF00795BAA /* ConfettiSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 3D24B09B2C1A2DAF00795BAA /* ConfettiSwiftUI */; };
6060
3D30407727D66E7E00FFE0EB /* InfoContainerMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D30407627D66E7E00FFE0EB /* InfoContainerMock.swift */; };
@@ -329,6 +329,7 @@
329329
538ABD4E284F9F88000D3CCC /* Collections in Frameworks */,
330330
7411879B2D9ADD200006EA41 /* Loc in Frameworks */,
331331
2A94B5D329B88E95009AE2A7 /* Sentry in Frameworks */,
332+
2E074C4C2DE620E800260ABD /* NotificationsCore in Frameworks */,
332333
1259300E26F3A6AE00B115CD /* Kingfisher in Frameworks */,
333334
2ADB57862CB6B6FE00BFC386 /* Cache in Frameworks */,
334335
538ABD50284F9F88000D3CCC /* DequeModule in Frameworks */,
@@ -373,9 +374,8 @@
373374
isa = PBXFrameworksBuildPhase;
374375
buildActionMask = 2147483647;
375376
files = (
376-
2EDD08442DA833720050397F /* Services in Frameworks */,
377+
2E074C4E2DE623DB00260ABD /* NotificationsCore in Frameworks */,
377378
2ED425D22DDE3CF5008C7AD3 /* Loc in Frameworks */,
378-
2E428A262DA836B900B849EF /* Factory in Frameworks */,
379379
2ED5E1542DAFE2A700B59485 /* AnytypeCore in Frameworks */,
380380
);
381381
runOnlyForDeploymentPostprocessing = 0;
@@ -695,6 +695,7 @@
695695
74EB806B2D79D3EA003F8D84 /* Assets */,
696696
7411879A2D9ADD200006EA41 /* Loc */,
697697
746F06002DB8E712005795F7 /* DesignKit */,
698+
2E074C4B2DE620E800260ABD /* NotificationsCore */,
698699
);
699700
productName = Anytype;
700701
productReference = 0303ECFB22D8EDAA005C552B /* Anytype.app */;
@@ -3125,10 +3126,13 @@
31253126
package = 2ADB57842CB6B6FE00BFC386 /* XCRemoteSwiftPackageReference "Cache" */;
31263127
productName = Cache;
31273128
};
3128-
2E428A252DA836B900B849EF /* Factory */ = {
3129+
2E074C4B2DE620E800260ABD /* NotificationsCore */ = {
31293130
isa = XCSwiftPackageProductDependency;
3130-
package = 2AC1262B2B90F65F003A4A8D /* XCRemoteSwiftPackageReference "Factory" */;
3131-
productName = Factory;
3131+
productName = NotificationsCore;
3132+
};
3133+
2E074C4D2DE623DB00260ABD /* NotificationsCore */ = {
3134+
isa = XCSwiftPackageProductDependency;
3135+
productName = NotificationsCore;
31323136
};
31333137
2E63D9B62D56520C008A733A /* FirebaseMessaging */ = {
31343138
isa = XCSwiftPackageProductDependency;
@@ -3143,10 +3147,6 @@
31433147
isa = XCSwiftPackageProductDependency;
31443148
productName = AnytypeCore;
31453149
};
3146-
2EDD08432DA833720050397F /* Services */ = {
3147-
isa = XCSwiftPackageProductDependency;
3148-
productName = Services;
3149-
};
31503150
2EEE411D2C1080AD000AB88B /* CachedAsyncImage */ = {
31513151
isa = XCSwiftPackageProductDependency;
31523152
package = 2EEE411C2C1080AD000AB88B /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */;

Anytype/Sources/ApplicationLayer/AppDelegate.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import UIKit
22
import AnytypeCore
33
import FirebaseMessaging
44
import Services
5+
import NotificationsCore
56

67
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
78

Anytype/Sources/ServiceLayer/EncryptionKeyEventHandler/EncryptionKeyEventHandler.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Services
22
import AnytypeCore
3+
import NotificationsCore
34

45
protocol EncryptionKeyEventHandlerProtocol: AnyObject, Sendable {
56
func startSubscription() async

AnytypeNotificationServiceExtension/NotificationService.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
import UserNotifications
2-
import Services
32
import AnytypeCore
43
import Loc
4+
import NotificationsCore
55

66
class NotificationService: UNNotificationServiceExtension {
77

8-
private let decryptionPushContentService: any DecryptionPushContentServiceProtocol = Container.shared.decryptionPushContentService()
9-
private let basicUserInfoStorage: any BasicUserInfoStorageProtocol = Container.shared.basicUserInfoStorage()
8+
private let decryptionPushContentService: any DecryptionPushContentServiceProtocol = DecryptionPushContentService()
109

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

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

16-
if FeatureFlags.checkLoginInNotificationService, basicUserInfoStorage.usersId.isEmpty {
17-
return
18-
}
19-
2015
self.contentHandler = contentHandler
2116
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
2217

Modules/AnytypeCore/AnytypeCore/Generated/FeatureFlags+Flags.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@ public extension FeatureFlags {
130130
value(for: .chatWidget)
131131
}
132132

133-
static var checkLoginInNotificationService: Bool {
134-
value(for: .checkLoginInNotificationService)
135-
}
136-
137133
static var rainbowViews: Bool {
138134
value(for: .rainbowViews)
139135
}
@@ -231,7 +227,6 @@ public extension FeatureFlags {
231227
.binScreenEmptyAction,
232228
.openFullscreenObjectsFromSetWidget,
233229
.chatWidget,
234-
.checkLoginInNotificationService,
235230
.rainbowViews,
236231
.showAlertOnAssert,
237232
.analytics,

Modules/AnytypeCore/AnytypeCore/Utils/FeatureFlags/FeatureDescription+Flags.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,6 @@ public extension FeatureDescription {
223223
defaultValue: false
224224
)
225225

226-
static let checkLoginInNotificationService = FeatureDescription(
227-
title: "Check login in NotificationService",
228-
type: .feature(author: "[email protected]", releaseVersion: "11"),
229-
defaultValue: true
230-
)
231-
232226
// MARK: - Debug
233227

234228
static let rainbowViews = FeatureDescription(

Modules/NotificationsCore/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// swift-tools-version: 6.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "NotificationsCore",
8+
platforms: [
9+
.iOS(.v16),
10+
],
11+
products: [
12+
.library(
13+
name: "NotificationsCore",
14+
type: .dynamic,
15+
targets: ["NotificationsCore"]),
16+
],
17+
dependencies: [
18+
.package(path: "../AnytypeCore"),
19+
.package(path: "../SecureService"),
20+
],
21+
targets: [
22+
.target(
23+
name: "NotificationsCore",
24+
dependencies: [
25+
"AnytypeCore",
26+
"SecureService"
27+
],
28+
swiftSettings: [
29+
.swiftLanguageMode(.v6)
30+
]
31+
),
32+
.testTarget(
33+
name: "NotificationsCoreTests",
34+
dependencies: ["NotificationsCore"]
35+
),
36+
]
37+
)

Modules/Services/Sources/Services/CryptoService/CryptoService.swift renamed to Modules/NotificationsCore/Sources/NotificationsCore/CryptoService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22
import CryptoKit
33

4-
public protocol CryptoServiceProtocol: AnyObject, Sendable {
4+
protocol CryptoServiceProtocol: AnyObject, Sendable {
55
func decryptAESGCM(data: Data, keyData: Data) throws -> Data
66
}
77

@@ -22,6 +22,6 @@ final class CryptoService: CryptoServiceProtocol {
2222
}
2323
}
2424

25-
public enum CryptoError: Error {
25+
enum CryptoError: Error {
2626
case decryptionFailed
2727
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ public protocol DecryptionPushContentServiceProtocol: AnyObject, Sendable {
55
func decrypt(_ encryptedData: Data, keyId: String) -> DecryptedPushContent?
66
}
77

8-
final class DecryptionPushContentService: DecryptionPushContentServiceProtocol {
8+
public final class DecryptionPushContentService: DecryptionPushContentServiceProtocol {
99

10-
private let cryptoService: any CryptoServiceProtocol = Container.shared.cryptoService()
11-
private let encryptionKeyService: any EncryptionKeyServiceProtocol = Container.shared.encryptionKeyService()
10+
private let cryptoService: any CryptoServiceProtocol = CryptoService()
11+
private let encryptionKeyService: any EncryptionKeyServiceProtocol = EncryptionKeyService()
1212
private let decoder = JSONDecoder()
1313

14-
func decrypt(_ encryptedData: Data, keyId: String) -> DecryptedPushContent? {
14+
public init() {}
15+
16+
public func decrypt(_ encryptedData: Data, keyId: String) -> DecryptedPushContent? {
1517
do {
1618
let keyString = try encryptionKeyService.obtainKeyById(keyId)
1719

@@ -30,6 +32,6 @@ final class DecryptionPushContentService: DecryptionPushContentServiceProtocol {
3032
}
3133

3234

33-
public enum DecryptionPushContentError: Error {
35+
enum DecryptionPushContentError: Error {
3436
case keyEncodeFailed
3537
}

Modules/Services/Sources/Services/EncryptionKeyService/EncryptionKeyService.swift renamed to Modules/NotificationsCore/Sources/NotificationsCore/EncryptionKeyService.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ public protocol EncryptionKeyServiceProtocol: AnyObject, Sendable {
77
func saveKey(_ key: String, keyId: String) throws
88
}
99

10-
final class EncryptionKeyService: EncryptionKeyServiceProtocol {
10+
public final class EncryptionKeyService: EncryptionKeyServiceProtocol {
1111

12-
private let keychainStore: any KeychainStoreProtocol = Container.shared.keychainStore()
12+
private let keychainStore: any KeychainStoreProtocol = KeychainStore()
1313

14-
func obtainKeyById(_ keyId: String) throws -> String {
14+
public init() {}
15+
16+
public func obtainKeyById(_ keyId: String) throws -> String {
1517
try keychainStore.retreiveItem(queryable: query(with: keyId))
1618
}
1719

18-
func saveKey(_ key: String, keyId: String) throws {
20+
public func saveKey(_ key: String, keyId: String) throws {
1921
try keychainStore.storeItem(item: key, queryable: query(with: keyId))
2022
}
2123

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Testing
2+
@testable import NotificationsCore
3+
4+
@Test func example() async throws {
5+
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
6+
}

Modules/Services/Package.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ let package = Package(
1717
.package(url: "https://github.com/hmlongco/Factory", revision: "2.3.1"),
1818
.package(path: "../ProtobufMessages"),
1919
.package(path: "../AnytypeCore"),
20-
.package(path: "../SecureService")
20+
.package(path: "../SecureService"),
21+
.package(path: "../NotificationsCore")
2122
],
2223
targets: [
2324
.target(
@@ -27,7 +28,8 @@ let package = Package(
2728
"Factory",
2829
"ProtobufMessages",
2930
"AnytypeCore",
30-
"SecureService"
31+
"SecureService",
32+
"NotificationsCore"
3133
],
3234
path: "Sources",
3335
swiftSettings: [

Modules/Services/Sources/ServicesDI.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
import SecureService
3+
import NotificationsCore
34
// Automatically export Factory when import Servies
45
@_exported import Factory
56

@@ -165,14 +166,6 @@ public extension Container {
165166
self { EncryptionKeyService() }.shared
166167
}
167168

168-
var cryptoService: Factory<CryptoServiceProtocol> {
169-
self { CryptoService() }.shared
170-
}
171-
172-
var decryptionPushContentService: Factory<DecryptionPushContentServiceProtocol> {
173-
self { DecryptionPushContentService() }.shared
174-
}
175-
176169
var basicUserInfoStorage: Factory<BasicUserInfoStorageProtocol> {
177170
self { BasicUserInfoStorage() }.singleton
178171
}

0 commit comments

Comments
 (0)