2017-02-08 20:25:31 +01:00
|
|
|
//
|
|
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2014-05-06 19:41:08 +02:00
|
|
|
#import "Contact.h"
|
2017-05-01 20:28:37 +02:00
|
|
|
#import <SignalServiceKit/ContactsManagerProtocol.h>
|
2014-05-06 19:41:08 +02:00
|
|
|
|
2016-12-05 04:51:31 +01:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
2014-05-06 19:41:08 +02:00
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
extern NSString *const OWSContactsManagerSignalAccountsDidChangeNotification;
|
2017-02-08 17:59:02 +01:00
|
|
|
|
2017-08-25 00:47:11 +02:00
|
|
|
@class ImageCache;
|
2017-09-19 16:36:23 +02:00
|
|
|
@class SignalAccount;
|
|
|
|
@class UIFont;
|
2015-11-29 01:14:49 +01:00
|
|
|
|
2016-12-05 04:51:31 +01:00
|
|
|
/**
|
|
|
|
* Get latest Signal contacts, and be notified when they change.
|
|
|
|
*/
|
2016-06-27 23:32:35 +02:00
|
|
|
@interface OWSContactsManager : NSObject <ContactsManagerProtocol>
|
2014-05-06 19:41:08 +02:00
|
|
|
|
2017-08-24 23:08:02 +02:00
|
|
|
#pragma mark - Setup
|
|
|
|
|
|
|
|
- (void)startObserving;
|
|
|
|
|
|
|
|
#pragma mark - Accessors
|
|
|
|
|
2017-08-25 00:47:11 +02:00
|
|
|
@property (nonnull, readonly) ImageCache *avatarCache;
|
2017-05-01 18:51:59 +02:00
|
|
|
|
2017-07-04 22:40:28 +02:00
|
|
|
@property (atomic, readonly) NSArray<Contact *> *allContacts;
|
|
|
|
|
2017-05-05 17:37:17 +02:00
|
|
|
@property (atomic, readonly) NSDictionary<NSString *, Contact *> *allContactsMap;
|
|
|
|
|
2017-12-13 22:59:57 +01:00
|
|
|
// order of the signalAccounts array respects the systems contact sorting preference
|
2017-05-01 18:51:59 +02:00
|
|
|
@property (atomic, readonly) NSArray<SignalAccount *> *signalAccounts;
|
2017-05-02 18:30:53 +02:00
|
|
|
- (nullable SignalAccount *)signalAccountForRecipientId:(NSString *)recipientId;
|
2017-12-14 16:51:46 +01:00
|
|
|
- (BOOL)hasSignalAccountForRecipientId:(NSString *)recipientId;
|
2017-05-01 18:51:59 +02:00
|
|
|
|
2017-12-14 01:08:47 +01:00
|
|
|
- (void)loadSignalAccountsFromCache;
|
2017-05-01 20:28:37 +02:00
|
|
|
#pragma mark - System Contact Fetching
|
|
|
|
|
2017-05-03 23:03:26 +02:00
|
|
|
// Must call `requestSystemContactsOnce` before accessing this method
|
|
|
|
@property (nonatomic, readonly) BOOL isSystemContactsAuthorized;
|
2017-11-17 16:20:00 +01:00
|
|
|
@property (nonatomic, readonly) BOOL systemContactsHaveBeenRequestedAtLeastOnce;
|
2017-05-03 23:03:26 +02:00
|
|
|
|
2017-05-18 14:41:28 +02:00
|
|
|
@property (nonatomic, readonly) BOOL supportsContactEditing;
|
|
|
|
|
2017-05-03 23:03:26 +02:00
|
|
|
// Request systems contacts and start syncing changes. The user will see an alert
|
|
|
|
// if they haven't previously.
|
2017-05-01 20:28:37 +02:00
|
|
|
- (void)requestSystemContactsOnce;
|
2017-05-08 22:28:01 +02:00
|
|
|
- (void)requestSystemContactsOnceWithCompletion:(void (^_Nullable)(NSError *_Nullable error))completion;
|
2017-05-03 23:03:26 +02:00
|
|
|
|
|
|
|
// Ensure's the app has the latest contacts, but won't prompt the user for contact
|
|
|
|
// access if they haven't granted it.
|
2017-10-25 15:18:27 +02:00
|
|
|
- (void)fetchSystemContactsOnceIfAlreadyAuthorized;
|
|
|
|
// This variant will fetch system contacts if contact access has already been granted,
|
|
|
|
// but not prompt for contact access. Also, it will always fire a notification.
|
2017-10-24 16:53:15 +02:00
|
|
|
- (void)fetchSystemContactsIfAlreadyAuthorizedAndAlwaysNotify;
|
2015-08-24 01:47:25 +02:00
|
|
|
|
2017-05-03 23:48:25 +02:00
|
|
|
#pragma mark - Util
|
|
|
|
|
2017-08-16 21:14:52 +02:00
|
|
|
- (BOOL)hasNameInSystemContactsForRecipientId:(NSString *)recipientId;
|
2016-12-05 04:51:31 +01:00
|
|
|
- (NSString *)displayNameForPhoneIdentifier:(nullable NSString *)identifier;
|
2017-05-02 18:30:53 +02:00
|
|
|
- (NSString *)displayNameForSignalAccount:(SignalAccount *)signalAccount;
|
2017-08-24 23:08:02 +02:00
|
|
|
|
2017-10-14 19:20:46 +02:00
|
|
|
/**
|
|
|
|
* Used for sorting, respects system contacts name sort order preference.
|
|
|
|
*/
|
|
|
|
- (NSString *)comparableNameForSignalAccount:(SignalAccount *)signalAccount;
|
|
|
|
|
2017-08-24 23:08:02 +02:00
|
|
|
// Generally we prefer the formattedProfileName over the raw profileName so as to
|
|
|
|
// distinguish a profile name apart from a name pulled from the system's contacts.
|
|
|
|
// This helps clarify when the remote person chooses a potentially confusing profile name.
|
2017-08-16 21:14:52 +02:00
|
|
|
- (nullable NSString *)formattedProfileNameForRecipientId:(NSString *)recipientId;
|
2017-08-24 23:08:02 +02:00
|
|
|
- (nullable NSString *)profileNameForRecipientId:(NSString *)recipientId;
|
|
|
|
- (nullable NSString *)nameFromSystemContactsForRecipientId:(NSString *)recipientId;
|
2017-09-07 22:25:57 +02:00
|
|
|
- (NSString *)stringForConversationTitleWithPhoneIdentifier:(NSString *)recipientId;
|
2017-08-24 23:08:02 +02:00
|
|
|
|
2016-12-05 04:51:31 +01:00
|
|
|
- (nullable UIImage *)imageForPhoneIdentifier:(nullable NSString *)identifier;
|
2017-05-02 18:30:53 +02:00
|
|
|
- (NSAttributedString *)formattedDisplayNameForSignalAccount:(SignalAccount *)signalAccount font:(UIFont *_Nonnull)font;
|
2017-04-18 22:08:01 +02:00
|
|
|
- (NSAttributedString *)formattedFullNameForRecipientId:(NSString *)recipientId font:(UIFont *)font;
|
2017-09-19 16:36:23 +02:00
|
|
|
- (NSString *)contactOrProfileNameForPhoneIdentifier:(NSString *)recipientId;
|
|
|
|
- (NSAttributedString *)attributedContactOrProfileNameForPhoneIdentifier:(NSString *)recipientId;
|
2017-08-23 18:03:36 +02:00
|
|
|
- (NSAttributedString *)attributedStringForConversationTitleWithPhoneIdentifier:(NSString *)recipientId
|
|
|
|
primaryFont:(UIFont *)primaryFont
|
|
|
|
secondaryFont:(UIFont *)secondaryFont;
|
2014-05-06 19:41:08 +02:00
|
|
|
@end
|
2016-12-05 04:51:31 +01:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|