Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
var viewContext: NSManagedObjectContext { get }
func newBackgroundContext() -> NSManagedObjectContext
var syncContext: NSManagedObjectContext { get }
var searchContext: NSManagedObjectContext { get }
var eventContext: NSManagedObjectContext { get }

}
Expand Down Expand Up @@ -138,8 +137,6 @@
return context
}()

public lazy var searchContext: NSManagedObjectContext = messagesContainer.newBackgroundContext()

public lazy var eventContext: NSManagedObjectContext = eventsContainer.newBackgroundContext()

public let accountContainer: URL
Expand Down Expand Up @@ -253,7 +250,6 @@

viewContext.tearDown()
syncContext.tearDown()
searchContext.tearDown()
eventContext.tearDown()
closeStores()
}
Expand Down Expand Up @@ -311,7 +307,6 @@
await configureContextReferences()
await configureViewContext(viewContext)
await configureSyncContext(syncContext)
await configureSearchContext(searchContext)

} catch {
WireLogger.localStorage.critical(
Expand Down Expand Up @@ -374,7 +369,7 @@

func configureViewContext(_ context: NSManagedObjectContext) async {
context.markAsUIContext()
await context.perform {

Check warning on line 372 in wire-ios-data-model/Source/ManagedObjectContext/CoreDataStack.swift

View workflow job for this annotation

GitHub Actions / Test Results

Capture of 'self' with non-Sendable type 'CoreDataStack' in a '@Sendable' closure

Capture of 'self' with non-Sendable type 'CoreDataStack' in a '@sendable' closure
context.localDomain = self.localDomain
context.isFederationEnabled = self.isFederationEnabled
context.createDispatchGroups()
Expand All @@ -386,17 +381,17 @@
}

func configureContextReferences() async {
await viewContext.perform {

Check warning on line 384 in wire-ios-data-model/Source/ManagedObjectContext/CoreDataStack.swift

View workflow job for this annotation

GitHub Actions / Test Results

Capture of 'self' with non-Sendable type 'CoreDataStack' in a '@Sendable' closure

Capture of 'self' with non-Sendable type 'CoreDataStack' in a '@sendable' closure
self.viewContext.zm_sync = self.syncContext
}
await syncContext.perform {

Check warning on line 387 in wire-ios-data-model/Source/ManagedObjectContext/CoreDataStack.swift

View workflow job for this annotation

GitHub Actions / Test Results

Capture of 'self' with non-Sendable type 'CoreDataStack' in a '@Sendable' closure

Capture of 'self' with non-Sendable type 'CoreDataStack' in a '@sendable' closure
self.syncContext.zm_userInterface = self.viewContext
}
}

func configureSyncContext(_ context: NSManagedObjectContext) async {
// Note: markAsSyncContext() is now called in the lazy initializer
await context.perform {

Check warning on line 394 in wire-ios-data-model/Source/ManagedObjectContext/CoreDataStack.swift

View workflow job for this annotation

GitHub Actions / Test Results

Capture of 'self' with non-Sendable type 'CoreDataStack' in a '@Sendable' closure

Capture of 'self' with non-Sendable type 'CoreDataStack' in a '@sendable' closure
context.localDomain = self.localDomain
context.isFederationEnabled = self.isFederationEnabled
context.createDispatchGroups()
Expand All @@ -413,22 +408,9 @@
}
}

func configureSearchContext(_ context: NSManagedObjectContext) async {
context.markAsSearch()
await context.perform {
context.localDomain = self.localDomain
context.isFederationEnabled = self.isFederationEnabled
context.createDispatchGroups()
self.dispatchGroup.map(context.addGroup(_:))
context.setupLocalCachedSessionAndSelfUser()
context.undoManager = nil
context.mergePolicy = NSMergePolicy(merge: .rollbackMergePolicyType)
}
}

func configureEventContext(_ context: NSManagedObjectContext) async {
await context.perform {
context.createDispatchGroups()

Check warning on line 413 in wire-ios-data-model/Source/ManagedObjectContext/CoreDataStack.swift

View workflow job for this annotation

GitHub Actions / Test Results

Capture of 'self' with non-Sendable type 'CoreDataStack' in a '@Sendable' closure

Capture of 'self' with non-Sendable type 'CoreDataStack' in a '@sendable' closure
self.dispatchGroup.map(context.addGroup(_:))
}
}
Expand Down Expand Up @@ -557,7 +539,7 @@
}

// MARK: -

Check warning on line 542 in wire-ios-data-model/Source/ManagedObjectContext/CoreDataStack.swift

View workflow job for this annotation

GitHub Actions / Test Results

Class 'PersistentContainer' must restate inherited '@unchecked Sendable' conformance

Class 'PersistentContainer' must restate inherited '@unchecked Sendable' conformance
public class PersistentContainer: NSPersistentContainer {

var storeURL: URL? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
@interface NSManagedObjectContext (zmessagingTests)

- (void)markAsSyncContext;
- (void)markAsSearchContext;
- (void)markAsUIContext;
- (void)disableObjectRefresh;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

extern NSString * _Nonnull const IsUserInterfaceContextKey;
extern NSString * _Nonnull const IsSyncContextKey;
extern NSString * _Nonnull const IsSearchContextKey;
extern NSString * _Nonnull const IsEventContextKey;

@interface NSManagedObjectContext (zmessaging)
Expand All @@ -37,9 +36,6 @@ extern NSString * _Nonnull const IsEventContextKey;
/// Inverse of @c zm_isSyncContext
@property (readonly) BOOL zm_isUserInterfaceContext;

/// Returns @c YES if the receiver is a context that is used for searching.
@property (readonly) BOOL zm_isSearchContext;

/// Returns @c YES if the context should refresh objects following the policy for the sync context
@property (readonly) BOOL zm_shouldRefreshObjectsWithSyncContextPolicy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#import <WireDataModel/WireDataModel-Swift.h>

NSString * const IsSyncContextKey = @"ZMIsSyncContext";
NSString * const IsSearchContextKey = @"ZMIsSearchContext";
NSString * const IsUserInterfaceContextKey = @"ZMIsUserInterfaceContext";
NSString * const IsEventContextKey = @"ZMIsEventDecoderContext";

Expand Down Expand Up @@ -88,7 +87,7 @@ @implementation NSManagedObjectContext (zmessaging)

- (BOOL)zm_isValidContext
{
return self.zm_isSyncContext || self.zm_isUserInterfaceContext || self.zm_isSearchContext;
return self.zm_isSyncContext || self.zm_isUserInterfaceContext;
}

- (id)validUserInfoValueOfClass:(Class)class forKey:(NSString *)key
Expand Down Expand Up @@ -128,11 +127,6 @@ - (BOOL)zm_isUserInterfaceContext
return [[self validUserInfoValueOfClass:[NSNumber class] forKey:IsUserInterfaceContextKey] boolValue];
}

- (BOOL)zm_isSearchContext
{
return [self.userInfo[IsSearchContextKey] boolValue];
}

- (NSManagedObjectContext*)zm_syncContext
{
if (self.zm_isSyncContext) {
Expand Down Expand Up @@ -539,13 +533,6 @@ - (void)markAsSyncContext;
}];
}

- (void)markAsSearchContext;
{
[self performBlockAndWait:^{
self.userInfo[IsSearchContextKey] = @YES;
}];
}

- (void)markAsUIContext
{
[self performBlockAndWait:^{
Expand All @@ -558,7 +545,6 @@ - (void)resetContextType
[self performBlockAndWait:^{
self.userInfo[IsSyncContextKey] = @NO;
self.userInfo[IsUserInterfaceContextKey] = @NO;
self.userInfo[IsSearchContextKey] = @NO;
}];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
// along with this program. If not, see http://www.gnu.org/licenses/.
//

import Foundation

extension UserType {

func isFederating(with otherUser: UserType) -> Bool {
Expand Down
36 changes: 16 additions & 20 deletions wire-ios-data-model/Source/Model/User/ZMSearchUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class ZMSearchUser: NSObject, UserType {
user?.objectId ?? remoteIdentifier!
}

fileprivate weak var contextProvider: ContextProvider?
fileprivate weak var viewContext: NSManagedObjectContext?
private let searchUsersCache: SearchUsersCache?

fileprivate var internalDomain: String?
Expand Down Expand Up @@ -162,16 +162,12 @@ public class ZMSearchUser: NSObject, UserType {
}

public var isFederated: Bool {
guard let contextProvider else {
return false
}

return ZMUser.selfUser(inUserSession: contextProvider).isFederating(with: self)
guard let viewContext else { return false }
return ZMUser.selfUser(in: viewContext).isFederating(with: self)
}

public var isSelfUser: Bool {
guard let user else { return false }

return user.isSelfUser
}

Expand Down Expand Up @@ -265,8 +261,8 @@ public class ZMSearchUser: NSObject, UserType {
}

public var oneToOneConversation: ZMConversation? {
if isTeamMember, let uiContext = contextProvider?.viewContext {
materialize(in: uiContext)?.oneToOneConversation
if isTeamMember, let viewContext {
materialize(in: viewContext)?.oneToOneConversation
} else {
user?.oneToOneConversation
}
Expand Down Expand Up @@ -482,7 +478,7 @@ public class ZMSearchUser: NSObject, UserType {

@objc
public required init(
contextProvider: ContextProvider,
viewContext: NSManagedObjectContext,
name: String,
handle: String?,
accentColor: ZMAccentColor?,
Expand All @@ -503,10 +499,10 @@ public class ZMSearchUser: NSObject, UserType {
self.internalDomain = domain
self.remoteIdentifier = existingUser?.remoteIdentifier ?? remoteIdentifier
self.teamIdentifier = existingUser?.teamIdentifier ?? teamIdentifier
self.contextProvider = contextProvider
self.viewContext = viewContext
self.searchUsersCache = searchUsersCache

let selfUser = ZMUser.selfUser(inUserSession: contextProvider)
let selfUser = ZMUser.selfUser(in: viewContext)
self.internalIsTeamMember = teamIdentifier != nil && selfUser.teamIdentifier == teamIdentifier
self.internalIsConnected = internalIsTeamMember

Expand All @@ -524,7 +520,7 @@ public class ZMSearchUser: NSObject, UserType {
searchUsersCache: SearchUsersCache?
) {
self.init(
contextProvider: contextProvider,
viewContext: contextProvider.viewContext,
name: user.name ?? "",
handle: user.handle,
accentColor: user.zmAccentColor,
Expand Down Expand Up @@ -556,7 +552,7 @@ public class ZMSearchUser: NSObject, UserType {
let accentColorRawValue = (payload["accent_id"] as? NSNumber)?.int16Value ?? 0

self.init(
contextProvider: contextProvider,
viewContext: contextProvider.viewContext,
name: name,
handle: handle,
accentColor: .from(rawValue: accentColorRawValue) ?? .default,
Expand Down Expand Up @@ -611,7 +607,7 @@ public class ZMSearchUser: NSObject, UserType {
}

public func connect(completion: @escaping (Error?) -> Void) {
let selfUser = ZMUser.selfUser(inUserSession: contextProvider!)
let selfUser = ZMUser.selfUser(in: viewContext!)
selfUser.sendConnectionRequest(to: self) { [weak self] result in
switch result {
case .success:
Expand All @@ -628,7 +624,7 @@ public class ZMSearchUser: NSObject, UserType {
private func updateLocalUser() {
guard
let userID = remoteIdentifier,
let viewContext = contextProvider?.viewContext
let viewContext
else {
return
}
Expand All @@ -637,7 +633,7 @@ public class ZMSearchUser: NSObject, UserType {
}

private func notifySearchUserChanged() {
contextProvider?.viewContext.searchUserObserverCenter.notifyUpdatedSearchUser(self)
viewContext?.searchUserObserverCenter.notifyUpdatedSearchUser(self)
}

public func accept(completion: @escaping (Error?) -> Void) {
Expand Down Expand Up @@ -671,7 +667,7 @@ public class ZMSearchUser: NSObject, UserType {

if let user {
user.requestPreviewProfileImage()
} else if let notificationContext = contextProvider?.viewContext.notificationContext {
} else if let notificationContext = viewContext?.notificationContext {
NotificationInContext(
name: .searchUserDidRequestPreviewAsset,
context: notificationContext,
Expand All @@ -686,7 +682,7 @@ public class ZMSearchUser: NSObject, UserType {

if let user {
user.requestCompleteProfileImage()
} else if let notificationContext = contextProvider?.viewContext.notificationContext {
} else if let notificationContext = viewContext?.notificationContext {
NotificationInContext(
name: .searchUserDidRequestCompleteAsset,
context: notificationContext,
Expand Down Expand Up @@ -731,7 +727,7 @@ public class ZMSearchUser: NSObject, UserType {
internalCompleteImageData = imageData
}

contextProvider?.viewContext.searchUserObserverCenter.notifyUpdatedSearchUser(self)
viewContext?.searchUserObserverCenter.notifyUpdatedSearchUser(self)
}

public func update(from payload: [String: Any]) {
Expand Down
11 changes: 0 additions & 11 deletions wire-ios-data-model/Source/Model/User/ZMUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
@end



Check warning on line 157 in wire-ios-data-model/Source/Model/User/ZMUser.m

View workflow job for this annotation

GitHub Actions / Test Results

Property 'connectionRequestMessage' requires method 'connectionRequestMessage' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation

Property 'connectionRequestMessage' requires method 'connectionRequestMessage' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation

Check warning on line 157 in wire-ios-data-model/Source/Model/User/ZMUser.m

View workflow job for this annotation

GitHub Actions / Test Results

Property 'isPendingMetadataRefresh' requires method 'isPendingMetadataRefresh' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation

Property 'isPendingMetadataRefresh' requires method 'isPendingMetadataRefresh' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation

Check warning on line 157 in wire-ios-data-model/Source/Model/User/ZMUser.m

View workflow job for this annotation

GitHub Actions / Test Results

Property 'isPendingMetadataRefresh' requires method 'setIsPendingMetadataRefresh:' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation

Property 'isPendingMetadataRefresh' requires method 'setIsPendingMetadataRefresh:' to be defined - use @synthesize, @dynamic or provide a method implementation in this class implementation
@implementation ZMUser

+ (NSSet<NSString *> *)keyPathsForValuesAffectingIsApp
Expand Down Expand Up @@ -717,17 +717,6 @@
@end


@implementation ZMUser (Utilities)

+ (ZMUser<ZMEditableUserType> *)selfUserInUserSession:(id<ZMContextProvider>)session
{
VerifyReturnNil(session != nil);
return [self selfUserInContext:session.viewContext];
}

@end




@implementation ZMUser (Editable)
Expand Down
9 changes: 0 additions & 9 deletions wire-ios-data-model/Source/Public/ZMUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ typedef NS_ENUM(int16_t, ZMBlockState) {
@end


@protocol ZMEditableUserType;

@interface ZMUser (Utilities)

+ (ZMUser<ZMEditableUserType> *_Nonnull)selfUserInUserSession:(id<ZMContextProvider> _Nonnull)session;

@end




@interface ZMUser (Connections)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ final class SearchUserObserverCenterTests: ModelObjectsTests {
user: ZMUser? = nil
) -> ZMSearchUser {
ZMSearchUser(
contextProvider: coreDataStack,
viewContext: coreDataStack.viewContext,
name: name,
handle: handle,
accentColor: accentColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ final class SearchUserObserverTests: NotificationDispatcherTestBase {
user: ZMUser? = nil
) -> ZMSearchUser {
ZMSearchUser(
contextProvider: coreDataStack,
viewContext: coreDataStack.viewContext,
name: name,
handle: name.lowercased(),
accentColor: .amber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ final class SearchUserSnapshotTests: ZMBaseManagedObjectTest {
user: ZMUser? = nil
) -> ZMSearchUser {
ZMSearchUser(
contextProvider: coreDataStack,
viewContext: coreDataStack.viewContext,
name: name,
handle: handle,
accentColor: accentColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class ZMSearchUserTests_Connections: ModelObjectsTests {
func testThatConnectSendsAConnectToUserNotification() {
// given
let searchUser = ZMSearchUser(
contextProvider: coreDataStack,
viewContext: coreDataStack.viewContext,
name: "John Doe",
handle: "johndoe",
accentColor: .turquoise,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ final class ZMSearchUserTests_ProfileImages: ZMBaseManagedObjectTest {
user: ZMUser? = nil
) -> ZMSearchUser {
ZMSearchUser(
contextProvider: coreDataStack,
viewContext: coreDataStack.viewContext,
name: name,
handle: name.lowercased(),
accentColor: .amber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ final class ZMSearchUserTests_TeamUser: ModelObjectsTests {

private func makeSearchUser(teamIdentifier: UUID?) -> ZMSearchUser {
ZMSearchUser(
contextProvider: coreDataStack,
viewContext: coreDataStack.viewContext,
name: "Foo",
handle: "foo",
accentColor: .amber,
Expand Down
Loading
Loading