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
|
|
|
|
2016-12-05 04:51:31 +01:00
|
|
|
@class UIFont;
|
2017-05-01 18:51:59 +02:00
|
|
|
@class SignalAccount;
|
2017-08-25 00:47:11 +02:00
|
|
|
@class ImageCache;
|
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-05-01 18:51:59 +02:00
|
|
|
// signalAccountMap and signalAccounts hold the same data.
|
|
|
|
// signalAccountMap is for lookup. signalAccounts contains the accounts
|
|
|
|
// ordered by display order.
|
|
|
|
@property (atomic, readonly) NSDictionary<NSString *, SignalAccount *> *signalAccountMap;
|
|
|
|
@property (atomic, readonly) NSArray<SignalAccount *> *signalAccounts;
|
2015-10-31 13:27:07 +01:00
|
|
|
|
2017-05-02 18:30:53 +02:00
|
|
|
- (nullable SignalAccount *)signalAccountForRecipientId:(NSString *)recipientId;
|
2017-05-01 18:51:59 +02:00
|
|
|
|
2016-11-12 18:22:29 +01:00
|
|
|
- (Contact *)getOrBuildContactForPhoneIdentifier:(NSString *)identifier;
|
2014-05-06 19:41:08 +02:00
|
|
|
|
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-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-05-01 20:28:37 +02:00
|
|
|
- (void)fetchSystemContactsIfAlreadyAuthorized;
|
2017-09-11 16:53:28 +02:00
|
|
|
- (void)fetchSystemContactsIfAlreadyAuthorizedAndIgnoreDebounce;
|
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
|
|
|
|
|
|
|
// 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-08-16 21:14:52 +02:00
|
|
|
- (NSAttributedString *)attributedStringForMessageFooterWithPhoneIdentifier:(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
|