Skip to content
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
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
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
126 changes: 63 additions & 63 deletions wire-ios-data-model/Tests/Source/Model/User/ZMSearchUserTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,40 @@ - (void)testThatItComparesEqualBasedOnRemoteID;
NSUUID *remoteIDA = [NSUUID createUUID];
NSUUID *remoteIDB = [NSUUID createUUID];

ZMSearchUser *user1 = [[ZMSearchUser alloc] initWithContextProvider:self.coreDataStack
name:@"A"
handle:@"a"
accentColor:ZMAccentColor.green
remoteIdentifier:remoteIDA
domain:nil
teamIdentifier:nil
user:nil
searchUsersCache:nil];
ZMSearchUser *user1 = [[ZMSearchUser alloc] initWithViewContext:self.coreDataStack.viewContext
name:@"A"
handle:@"a"
accentColor:ZMAccentColor.green
remoteIdentifier:remoteIDA
domain:nil
teamIdentifier:nil
user:nil
searchUsersCache:nil];

// (1)
ZMSearchUser *user2 = [[ZMSearchUser alloc] initWithContextProvider:self.coreDataStack
name:@"B"
handle:@"b"
accentColor:ZMAccentColor.purple
remoteIdentifier:remoteIDA
domain:nil
teamIdentifier:nil
user:nil
searchUsersCache:nil];
ZMSearchUser *user2 = [[ZMSearchUser alloc] initWithViewContext:self.coreDataStack.viewContext
name:@"B"
handle:@"b"
accentColor:ZMAccentColor.purple
remoteIdentifier:remoteIDA
domain:nil
teamIdentifier:nil
user:nil
searchUsersCache:nil];

XCTAssertEqualObjects(user1, user2);
XCTAssertEqual(user1.hash, user2.hash);

// (2)
ZMSearchUser *user3 = [[ZMSearchUser alloc] initWithContextProvider:self.coreDataStack
name:@"A"
handle:@"b"
accentColor:ZMAccentColor.green
remoteIdentifier:remoteIDB
domain:nil
teamIdentifier:nil
user:nil
searchUsersCache:nil];
ZMSearchUser *user3 = [[ZMSearchUser alloc] initWithViewContext:self.coreDataStack.viewContext
name:@"A"
handle:@"b"
accentColor:ZMAccentColor.green
remoteIdentifier:remoteIDB
domain:nil
teamIdentifier:nil
user:nil
searchUsersCache:nil];

XCTAssertNotEqualObjects(user1, user3);
}
Expand All @@ -95,15 +95,15 @@ - (void)testThatItHasAllDataItWasInitializedWith
NSUUID *remoteID = [NSUUID createUUID];

// when
ZMSearchUser *searchUser = [[ZMSearchUser alloc] initWithContextProvider:self.coreDataStack
name:name
handle:handle
accentColor:ZMAccentColor.green
remoteIdentifier:remoteID
domain:nil
teamIdentifier:nil
user:nil
searchUsersCache:nil];
ZMSearchUser *searchUser = [[ZMSearchUser alloc] initWithViewContext:self.coreDataStack.viewContext
name:name
handle:handle
accentColor:ZMAccentColor.green
remoteIdentifier:remoteID
domain:nil
teamIdentifier:nil
user:nil
searchUsersCache:nil];


// then
Expand Down Expand Up @@ -134,15 +134,15 @@ - (void)testThatItUsesDataFromAUserIfItHasOne


// when
ZMSearchUser *searchUser = [[ZMSearchUser alloc] initWithContextProvider:self.coreDataStack
name:@"Wrong name"
handle:@"not_my_handle"
accentColor:ZMAccentColor.green
remoteIdentifier:[NSUUID createUUID]
domain:nil
teamIdentifier:nil
user:user
searchUsersCache:nil];
ZMSearchUser *searchUser = [[ZMSearchUser alloc] initWithViewContext:self.coreDataStack.viewContext
name:@"Wrong name"
handle:@"not_my_handle"
accentColor:ZMAccentColor.green
remoteIdentifier:[NSUUID createUUID]
domain:nil
teamIdentifier:nil
user:user
searchUsersCache:nil];

// then
XCTAssertEqualObjects(searchUser.name, user.name);
Expand All @@ -162,15 +162,15 @@ - (void)testThatItUsesDataFromAUserIfItHasOne
- (void)testThatItCanBeConnectedIfItIsNotAlreadyConnected
{
// given
ZMSearchUser *searchUser = [[ZMSearchUser alloc] initWithContextProvider:self.coreDataStack
name:@"Hans"
handle:@"hans"
accentColor:ZMAccentColor.green
remoteIdentifier:NSUUID.createUUID
domain:nil
teamIdentifier:nil
user:nil
searchUsersCache:nil];
ZMSearchUser *searchUser = [[ZMSearchUser alloc] initWithViewContext:self.coreDataStack.viewContext
name:@"Hans"
handle:@"hans"
accentColor:ZMAccentColor.green
remoteIdentifier:NSUUID.createUUID
domain:nil
teamIdentifier:nil
user:nil
searchUsersCache:nil];


// then
Expand All @@ -181,15 +181,15 @@ - (void)testThatItCanBeConnectedIfItIsNotAlreadyConnected
- (void)testThatItCanNotBeConnectedIfItHasNoRemoteIdentifier
{
// given
ZMSearchUser *searchUser = [[ZMSearchUser alloc] initWithContextProvider:self.coreDataStack
name:@"Hans"
handle:@"hans"
accentColor:ZMAccentColor.green
remoteIdentifier:nil
domain:nil
teamIdentifier:nil
user:nil
searchUsersCache:nil];
ZMSearchUser *searchUser = [[ZMSearchUser alloc] initWithViewContext:self.coreDataStack.viewContext
name:@"Hans"
handle:@"hans"
accentColor:ZMAccentColor.green
remoteIdentifier:nil
domain:nil
teamIdentifier:nil
user:nil
searchUsersCache:nil];

// then
XCTAssertFalse(searchUser.canBeConnected);
Expand Down
Loading
Loading