Skip to content

Commit 2ca449c

Browse files
authored
feat: add AppInfo Core Data entity - WPB-20362 (#4446)
1 parent 8daa4e2 commit 2ca449c

File tree

45 files changed

+1099
-37
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1099
-37
lines changed

WireData/Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PackageDescription
44

55
let package = Package(
66
name: "WireData",
7+
platforms: [.iOS(.v17)],
78
products: [
89
.library(
910
name: "WireData",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// Wire
3+
// Copyright (C) 2026 Wire Swiss GmbH
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program. If not, see http://www.gnu.org/licenses/.
17+
//
18+
19+
import CoreData
20+
21+
/// Additional information about an app.
22+
23+
public final class AppInfo: NSManagedObject {
24+
25+
/// The name of the associated Core Data entity.
26+
27+
public static let entityName = "AppInfo"
28+
29+
/// The category name of the app (e.g., `"other"`).
30+
31+
@NSManaged public var category: String
32+
33+
/// A short description of the app (max 300 characters).
34+
///
35+
/// - Note: This corresponds to the `description` field in the API
36+
/// but is renamed to avoid shadowing `NSObject.description`.
37+
38+
@NSManaged public var appDescription: String
39+
40+
}

WireData/Sources/WireData/Schema/zmessaging.xcdatamodeld/.xccurrentversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<plist version="1.0">
44
<dict>
55
<key>_XCCurrentVersionName</key>
6-
<string>zmessaging2.133.0.xcdatamodel</string>
6+
<string>zmessaging2.134.0.xcdatamodel</string>
77
</dict>
88
</plist>

WireData/Sources/WireData/Schema/zmessaging.xcdatamodeld/zmessaging2.134.0.xcdatamodel/contents

Lines changed: 455 additions & 0 deletions
Large diffs are not rendered by default.

WireData/Tests/TestPlans/AllTests.xctestplan

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,19 @@
99
}
1010
],
1111
"defaultOptions" : {
12-
"codeCoverage" : false
12+
"commandLineArgumentEntries" : [
13+
{
14+
"argument" : "-com.apple.CoreData.ConcurrencyDebug 1"
15+
}
16+
],
17+
"environmentVariableEntries" : [
18+
{
19+
"key" : "CI",
20+
"value" : "${CI}"
21+
}
22+
],
23+
"language" : "en",
24+
"region" : "DE"
1325
},
1426
"testTargets" : [
1527
{
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// Wire
3+
// Copyright (C) 2026 Wire Swiss GmbH
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program. If not, see http://www.gnu.org/licenses/.
17+
//
18+
19+
import CoreData
20+
import Testing
21+
22+
@testable import WireData
23+
24+
@MainActor
25+
struct AppInfoTests {
26+
27+
private let container: NSPersistentContainer
28+
29+
init() throws {
30+
self.container = try NSPersistentContainer.inMemoryContainer()
31+
}
32+
33+
@Test
34+
func initialization() async throws {
35+
let context = container.newBackgroundContext()
36+
let (appDescription, category) = try await context.perform {
37+
38+
// given
39+
let appInfo = AppInfo(context: context)
40+
appInfo.appDescription = "desc"
41+
appInfo.category = "cat"
42+
43+
// when
44+
try context.save()
45+
let request = try #require(AppInfo.fetchRequest() as? NSFetchRequest<AppInfo>)
46+
let persisted = try #require(context.fetch(request).first)
47+
return (persisted.appDescription, persisted.category)
48+
}
49+
50+
// then
51+
#expect(appDescription == "desc")
52+
#expect(category == "cat")
53+
}
54+
55+
}

WireData/Tests/WireDataTests/Models/WireCellsLocalAssetTests.swift

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct WireCellsLocalAssetTests {
3131
}
3232

3333
@Test
34-
func initialization() async throws {
34+
func initialization() throws {
3535
// given
3636
let context = container.viewContext
3737
let nodeID = UUID()
@@ -60,26 +60,3 @@ struct WireCellsLocalAssetTests {
6060
}
6161

6262
}
63-
64-
// MARK: - Helpers
65-
66-
private extension NSPersistentContainer {
67-
68-
static func inMemoryContainer() throws -> NSPersistentContainer {
69-
let model = NSManagedObjectModel.mergedModel(from: [WireDataBundle.bundle])
70-
71-
let description = NSPersistentStoreDescription()
72-
description.type = NSInMemoryStoreType
73-
let container = NSPersistentContainer(name: "zmessaging", managedObjectModel: model!)
74-
container.persistentStoreDescriptions = [description]
75-
var loadError: Error?
76-
container.loadPersistentStores { _, error in
77-
loadError = error
78-
}
79-
if let loadError {
80-
throw loadError
81-
}
82-
return container
83-
}
84-
85-
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// Wire
3+
// Copyright (C) 2026 Wire Swiss GmbH
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with this program. If not, see http://www.gnu.org/licenses/.
17+
//
18+
19+
import CoreData
20+
import WireData
21+
22+
extension NSPersistentContainer {
23+
24+
static func inMemoryContainer() throws -> NSPersistentContainer {
25+
let model = NSManagedObjectModel.mergedModel(from: [WireDataBundle.bundle])
26+
27+
let description = NSPersistentStoreDescription()
28+
description.type = NSInMemoryStoreType
29+
let container = NSPersistentContainer(name: "zmessaging", managedObjectModel: model!)
30+
container.persistentStoreDescriptions = [description]
31+
var loadError: Error?
32+
container.loadPersistentStores { _, error in
33+
loadError = error
34+
}
35+
if let loadError {
36+
throw loadError
37+
}
38+
return container
39+
}
40+
41+
}

WireDomain/Sources/WireDomain/Repositories/User/Models/NewUserInfo.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// along with this program. If not, see http://www.gnu.org/licenses/.
1717
//
1818

19+
import WireData
1920
import WireDataModel
2021

2122
public struct NewUserInfo: Equatable, Sendable {
@@ -30,6 +31,8 @@ public struct NewUserInfo: Equatable, Sendable {
3031
let isDeleted: Bool
3132
let email: String?
3233
let expiresAt: Date?
34+
let appDescription: String?
35+
let appCategory: String?
3336
let serviceID: UUID?
3437
let serviceProvider: UUID?
3538
let supportedProtocols: Set<WireDataModel.MessageProtocol>?

WireDomain/Sources/WireDomain/Repositories/User/UserLocalStore.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// along with this program. If not, see http://www.gnu.org/licenses/.
1717
//
1818

19+
import WireData
1920
import WireDataModel
2021
import WireLogging
2122
import WireNetwork
@@ -322,7 +323,7 @@ public final class UserLocalStore: UserLocalStoreProtocol {
322323
domain: userInfo.userID.domain
323324
)
324325

325-
await context.perform {
326+
await context.perform { [context] in
326327
guard !userInfo.isDeleted else {
327328
return persistedUser.markAccountAsDeleted(at: Date())
328329
}
@@ -335,6 +336,12 @@ public final class UserLocalStore: UserLocalStoreProtocol {
335336
persistedUser.previewProfileAssetIdentifier = userInfo.completeAssetKey
336337
persistedUser.emailAddress = userInfo.email
337338
persistedUser.expiresAt = userInfo.expiresAt
339+
if let appDescription = userInfo.appDescription, let appCategory = userInfo.appCategory {
340+
let appInfo = persistedUser.appInfo ?? WireData.AppInfo(context: context)
341+
appInfo.appDescription = appDescription
342+
appInfo.category = appCategory
343+
persistedUser.appInfo = appInfo
344+
}
338345
persistedUser.serviceIdentifier = userInfo.serviceID?.transportString()
339346
persistedUser.providerIdentifier = userInfo.serviceProvider?.transportString()
340347
persistedUser.supportedProtocols = userInfo.supportedProtocols ?? [.proteus]

0 commit comments

Comments
 (0)