Sync colors with contacts
This commit is contained in:
parent
553a94286f
commit
4d3d5d98e1
|
@ -16,10 +16,13 @@ import SignalMessaging
|
|||
|
||||
let TAG = "[MultiDeviceProfileKeyUpdateJob]"
|
||||
|
||||
let profileKey: OWSAES256Key
|
||||
let identityManager: OWSIdentityManager
|
||||
let messageSender: MessageSender
|
||||
let profileManager: OWSProfileManager
|
||||
private let profileKey: OWSAES256Key
|
||||
private let identityManager: OWSIdentityManager
|
||||
private let messageSender: MessageSender
|
||||
private let profileManager: OWSProfileManager
|
||||
private var editingDatabaseConnection: YapDatabaseConnection {
|
||||
return OWSPrimaryStorage.shared().dbReadWriteConnection
|
||||
}
|
||||
|
||||
@objc public required init(profileKey: OWSAES256Key, identityManager: OWSIdentityManager, messageSender: MessageSender, profileManager: OWSProfileManager) {
|
||||
self.profileKey = profileKey
|
||||
|
@ -45,8 +48,17 @@ import SignalMessaging
|
|||
identityManager: self.identityManager,
|
||||
profileManager: self.profileManager)
|
||||
|
||||
let dataSource = DataSourceValue.dataSource(withSyncMessage: syncContactsMessage.buildPlainTextAttachmentData())
|
||||
self.messageSender.enqueueTemporaryAttachment(dataSource,
|
||||
var dataSource: DataSource? = nil
|
||||
self.editingDatabaseConnection.readWrite { transaction in
|
||||
dataSource = DataSourceValue.dataSource(withSyncMessageData: syncContactsMessage.buildPlainTextAttachmentData(with: transaction))
|
||||
}
|
||||
|
||||
guard let attachmentDataSource = dataSource else {
|
||||
owsFail("\(self.logTag) in \(#function) dataSource was unexpectedly nil")
|
||||
return
|
||||
}
|
||||
|
||||
self.messageSender.enqueueTemporaryAttachment(attachmentDataSource,
|
||||
contentType: OWSMimeTypeApplicationOctetStream,
|
||||
in: syncContactsMessage,
|
||||
success: {
|
||||
|
|
|
@ -99,8 +99,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[[OWSSyncContactsMessage alloc] initWithSignalAccounts:self.contactsManager.signalAccounts
|
||||
identityManager:self.identityManager
|
||||
profileManager:self.profileManager];
|
||||
DataSource *dataSource =
|
||||
[DataSourceValue dataSourceWithSyncMessage:[syncContactsMessage buildPlainTextAttachmentData]];
|
||||
__block DataSource *dataSource;
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
dataSource = [DataSourceValue
|
||||
dataSourceWithSyncMessageData:[syncContactsMessage
|
||||
buildPlainTextAttachmentDataWithTransaction:transaction]];
|
||||
}];
|
||||
|
||||
[self.messageSender enqueueTemporaryAttachment:dataSource
|
||||
contentType:OWSMimeTypeApplicationOctetStream
|
||||
inMessage:syncContactsMessage
|
||||
|
@ -118,7 +123,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
__block DataSource *dataSource;
|
||||
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
dataSource = [DataSourceValue
|
||||
dataSourceWithSyncMessage:[syncGroupsMessage buildPlainTextAttachmentDataWithTransaction:transaction]];
|
||||
dataSourceWithSyncMessageData:[syncGroupsMessage buildPlainTextAttachmentDataWithTransaction:transaction]];
|
||||
}];
|
||||
[self.messageSender enqueueTemporaryAttachment:dataSource
|
||||
contentType:OWSMimeTypeApplicationOctetStream
|
||||
|
|
|
@ -95,6 +95,11 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
|
|||
[self sendSyncContactsMessageIfPossible];
|
||||
}
|
||||
|
||||
- (YapDatabaseConnection *)editingDatabaseConnection
|
||||
{
|
||||
return OWSPrimaryStorage.sharedManager.dbReadWriteConnection;
|
||||
}
|
||||
|
||||
#pragma mark - Methods
|
||||
|
||||
- (void)sendSyncContactsMessageIfNecessary
|
||||
|
@ -119,11 +124,13 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
|
|||
identityManager:self.identityManager
|
||||
profileManager:self.profileManager];
|
||||
|
||||
NSData *messageData = [syncContactsMessage buildPlainTextAttachmentData];
|
||||
|
||||
NSData *lastMessageData =
|
||||
[OWSPrimaryStorage.dbReadConnection objectForKey:kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
|
||||
inCollection:kOWSPrimaryStorageOWSContactsSyncingCollection];
|
||||
__block NSData *messageData;
|
||||
__block NSData *lastMessageData;
|
||||
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
messageData = [syncContactsMessage buildPlainTextAttachmentDataWithTransaction:transaction];
|
||||
lastMessageData = [transaction objectForKey:kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
|
||||
inCollection:kOWSPrimaryStorageOWSContactsSyncingCollection];
|
||||
}];
|
||||
|
||||
if (lastMessageData && [lastMessageData isEqual:messageData]) {
|
||||
// Ignore redundant contacts sync message.
|
||||
|
@ -132,17 +139,16 @@ NSString *const kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
|
|||
|
||||
self.isRequestInFlight = YES;
|
||||
|
||||
DataSource *dataSource =
|
||||
[DataSourceValue dataSourceWithSyncMessage:[syncContactsMessage buildPlainTextAttachmentData]];
|
||||
DataSource *dataSource = [DataSourceValue dataSourceWithSyncMessageData:messageData];
|
||||
[self.messageSender enqueueTemporaryAttachment:dataSource
|
||||
contentType:OWSMimeTypeApplicationOctetStream
|
||||
inMessage:syncContactsMessage
|
||||
success:^{
|
||||
DDLogInfo(@"%@ Successfully sent contacts sync message.", self.logTag);
|
||||
|
||||
[OWSPrimaryStorage.dbReadWriteConnection setObject:messageData
|
||||
forKey:kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
|
||||
inCollection:kOWSPrimaryStorageOWSContactsSyncingCollection];
|
||||
[self.editingDatabaseConnection setObject:messageData
|
||||
forKey:kOWSPrimaryStorageOWSContactsSyncingLastMessageKey
|
||||
inCollection:kOWSPrimaryStorageOWSContactsSyncingCollection];
|
||||
|
||||
dispatch_async(self.serialQueue, ^{
|
||||
self.isRequestInFlight = NO;
|
||||
|
|
|
@ -16,7 +16,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
- (void)writeSignalAccount:(SignalAccount *)signalAccount
|
||||
recipientIdentity:(nullable OWSRecipientIdentity *)recipientIdentity
|
||||
profileKeyData:(nullable NSData *)profileKeyData
|
||||
contactsManager:(id<ContactsManagerProtocol>)contactsManager;
|
||||
contactsManager:(id<ContactsManagerProtocol>)contactsManager
|
||||
conversationColorName:(NSString *)conversationColorName;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
recipientIdentity:(nullable OWSRecipientIdentity *)recipientIdentity
|
||||
profileKeyData:(nullable NSData *)profileKeyData
|
||||
contactsManager:(id<ContactsManagerProtocol>)contactsManager
|
||||
conversationColorName:(NSString *)conversationColorName
|
||||
{
|
||||
OWSAssert(signalAccount);
|
||||
OWSAssert(signalAccount.contact);
|
||||
|
@ -32,6 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
OWSSignalServiceProtosContactDetailsBuilder *contactBuilder = [OWSSignalServiceProtosContactDetailsBuilder new];
|
||||
[contactBuilder setName:signalAccount.contact.fullName];
|
||||
[contactBuilder setNumber:signalAccount.recipientId];
|
||||
[contactBuilder setColor:conversationColorName];
|
||||
|
||||
if (recipientIdentity != nil) {
|
||||
OWSSignalServiceProtosVerifiedBuilder *verifiedBuilder = [OWSSignalServiceProtosVerifiedBuilder new];
|
||||
|
|
|
@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (NSData *)buildPlainTextAttachmentData;
|
||||
- (NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#import "SignalAccount.h"
|
||||
#import "TSAttachment.h"
|
||||
#import "TSAttachmentStream.h"
|
||||
#import "TSContactThread.h"
|
||||
#import "TextSecureKitEnv.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
@ -70,7 +71,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
return syncMessageBuilder;
|
||||
}
|
||||
|
||||
- (NSData *)buildPlainTextAttachmentData
|
||||
- (NSData *)buildPlainTextAttachmentDataWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
id<ContactsManagerProtocol> contactsManager = TextSecureKitEnv.sharedEnv.contactsManager;
|
||||
|
||||
|
@ -86,10 +87,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[self.identityManager recipientIdentityForRecipientId:signalAccount.recipientId];
|
||||
NSData *_Nullable profileKeyData = [self.profileManager profileKeyDataForRecipientId:signalAccount.recipientId];
|
||||
|
||||
TSContactThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:signalAccount.recipientId transaction:transaction];
|
||||
[contactsOutputStream writeSignalAccount:signalAccount
|
||||
recipientIdentity:recipientIdentity
|
||||
profileKeyData:profileKeyData
|
||||
contactsManager:contactsManager];
|
||||
contactsManager:contactsManager
|
||||
conversationColorName:contactThread.conversationColorName];
|
||||
}
|
||||
|
||||
[contactsOutputStream flush];
|
||||
|
|
|
@ -657,8 +657,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[[OWSSyncContactsMessage alloc] initWithSignalAccounts:self.contactsManager.signalAccounts
|
||||
identityManager:self.identityManager
|
||||
profileManager:self.profileManager];
|
||||
DataSource *dataSource =
|
||||
[DataSourceValue dataSourceWithSyncMessage:[syncContactsMessage buildPlainTextAttachmentData]];
|
||||
DataSource *dataSource = [DataSourceValue
|
||||
dataSourceWithSyncMessageData:[syncContactsMessage
|
||||
buildPlainTextAttachmentDataWithTransaction:transaction]];
|
||||
[self.messageSender enqueueTemporaryAttachment:dataSource
|
||||
contentType:OWSMimeTypeApplicationOctetStream
|
||||
inMessage:syncContactsMessage
|
||||
|
@ -673,7 +674,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
} else if (syncMessage.request.type == OWSSignalServiceProtosSyncMessageRequestTypeGroups) {
|
||||
OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init];
|
||||
DataSource *dataSource = [DataSourceValue
|
||||
dataSourceWithSyncMessage:[syncGroupsMessage buildPlainTextAttachmentDataWithTransaction:transaction]];
|
||||
dataSourceWithSyncMessageData:[syncGroupsMessage
|
||||
buildPlainTextAttachmentDataWithTransaction:transaction]];
|
||||
[self.messageSender enqueueTemporaryAttachment:dataSource
|
||||
contentType:OWSMimeTypeApplicationOctetStream
|
||||
inMessage:syncGroupsMessage
|
||||
|
|
|
@ -47,7 +47,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
+ (nullable DataSource *)dataSourceWithOversizeText:(NSString *_Nullable)text;
|
||||
|
||||
+ (DataSource *)dataSourceWithSyncMessage:(NSData *)data;
|
||||
+ (DataSource *)dataSourceWithSyncMessageData:(NSData *)data;
|
||||
|
||||
+ (DataSource *)emptyDataSource;
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
return [self dataSourceWithData:data fileExtension:kOversizeTextAttachmentFileExtension];
|
||||
}
|
||||
|
||||
+ (DataSource *)dataSourceWithSyncMessage:(NSData *)data
|
||||
+ (DataSource *)dataSourceWithSyncMessageData:(NSData *)data
|
||||
{
|
||||
return [self dataSourceWithData:data fileExtension:kSyncMessageFileExtension];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue