mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
sync verification state with contacts
// FREEBIE
This commit is contained in:
parent
48b3f498a9
commit
f653bc36a8
|
@ -7,10 +7,12 @@
|
|||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SignalAccount;
|
||||
@class OWSRecipientIdentity;
|
||||
|
||||
@interface OWSContactsOutputStream : OWSChunkedOutputStream
|
||||
|
||||
- (void)writeSignalAccount:(SignalAccount *)signalAccount;
|
||||
- (void)writeSignalAccount:(SignalAccount *)signalAccount
|
||||
recipientIdentity:(OWSRecipientIdentity *)recipientIdentity;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#import "MIMETypeUtil.h"
|
||||
#import "OWSSignalServiceProtos.pb.h"
|
||||
#import "SignalAccount.h"
|
||||
#import "OWSRecipientIdentity.h"
|
||||
#import <ProtocolBuffers/CodedOutputStream.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
@ -14,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@implementation OWSContactsOutputStream
|
||||
|
||||
- (void)writeSignalAccount:(SignalAccount *)signalAccount
|
||||
recipientIdentity:(OWSRecipientIdentity *)recipientIdentity
|
||||
{
|
||||
OWSAssert(signalAccount);
|
||||
OWSAssert(signalAccount.contact);
|
||||
|
@ -21,7 +23,17 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
OWSSignalServiceProtosContactDetailsBuilder *contactBuilder = [OWSSignalServiceProtosContactDetailsBuilder new];
|
||||
[contactBuilder setName:signalAccount.contact.fullName];
|
||||
[contactBuilder setNumber:signalAccount.recipientId];
|
||||
|
||||
|
||||
// Don't sync default or no-longer-verified state in contact sync.
|
||||
if (recipientIdentity.verificationState == OWSVerificationStateVerified) {
|
||||
OWSSignalServiceProtosVerifiedBuilder *verifiedBuilder = [OWSSignalServiceProtosVerifiedBuilder new];
|
||||
verifiedBuilder.state = OWSSignalServiceProtosVerifiedStateVerified;
|
||||
verifiedBuilder.destination = recipientIdentity.recipientId;
|
||||
verifiedBuilder.identityKey = recipientIdentity.identityKey;
|
||||
// TODO do we need to set null message here?
|
||||
contactBuilder.verified = [verifiedBuilder build];
|
||||
}
|
||||
|
||||
NSData *avatarPng;
|
||||
if (signalAccount.contact.image) {
|
||||
OWSSignalServiceProtosContactDetailsAvatarBuilder *avatarBuilder =
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
// Copyright © 2016 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSOutgoingSyncMessage.h"
|
||||
|
||||
|
@ -6,10 +8,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@class YapDatabaseReadWriteTransaction;
|
||||
@protocol ContactsManagerProtocol;
|
||||
@class OWSIdentityManager;
|
||||
|
||||
@interface OWSSyncContactsMessage : OWSOutgoingSyncMessage
|
||||
|
||||
- (instancetype)initWithContactsManager:(id<ContactsManagerProtocol>)contactsManager;
|
||||
- (instancetype)initWithContactsManager:(id<ContactsManagerProtocol>)contactsManager
|
||||
identityManager:(OWSIdentityManager *)identityManager;
|
||||
|
||||
- (NSData *)buildPlainTextAttachmentData;
|
||||
|
||||
@end
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#import "NSDate+millisecondTimeStamp.h"
|
||||
#import "OWSContactsOutputStream.h"
|
||||
#import "OWSSignalServiceProtos.pb.h"
|
||||
#import "OWSIdentityManager.h"
|
||||
#import "SignalAccount.h"
|
||||
#import "TSAttachment.h"
|
||||
#import "TSAttachmentStream.h"
|
||||
|
@ -17,12 +18,14 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@interface OWSSyncContactsMessage ()
|
||||
|
||||
@property (nonatomic, readonly) id<ContactsManagerProtocol> contactsManager;
|
||||
@property (nonatomic, readonly) OWSIdentityManager *identityManager;
|
||||
|
||||
@end
|
||||
|
||||
@implementation OWSSyncContactsMessage
|
||||
|
||||
- (instancetype)initWithContactsManager:(id<ContactsManagerProtocol>)contactsManager
|
||||
identityManager:(OWSIdentityManager *)identityManager
|
||||
{
|
||||
self = [super initWithTimestamp:[NSDate ows_millisecondTimeStamp]];
|
||||
if (!self) {
|
||||
|
@ -30,6 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
|
||||
_contactsManager = contactsManager;
|
||||
_identityManager = identityManager;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -66,7 +70,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
OWSContactsOutputStream *contactsOutputStream = [OWSContactsOutputStream streamWithOutputStream:dataOutputStream];
|
||||
|
||||
for (SignalAccount *signalAccount in self.contactsManager.signalAccounts) {
|
||||
[contactsOutputStream writeSignalAccount:signalAccount];
|
||||
OWSRecipientIdentity *recipientIdentity = [self.identityManager recipientIdentityForRecipientId:signalAccount.recipientId];
|
||||
|
||||
[contactsOutputStream writeSignalAccount:signalAccount recipientIdentity:recipientIdentity];
|
||||
}
|
||||
|
||||
[contactsOutputStream flush];
|
||||
|
|
|
@ -500,49 +500,49 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|||
});
|
||||
}
|
||||
|
||||
- (void)syncAllVerificationStates
|
||||
{
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
@synchronized(self)
|
||||
{
|
||||
|
||||
NSMutableArray<OWSVerificationStateSyncMessage *> *messages = [NSMutableArray new];
|
||||
[OWSRecipientIdentity enumerateCollectionObjectsUsingBlock:^(OWSRecipientIdentity *recipientIdentity, BOOL *stop) {
|
||||
OWSAssert(recipientIdentity);
|
||||
OWSAssert(recipientIdentity.recipientId.length > 0);
|
||||
OWSAssert(recipientIdentity.identityKey.length == kStoredIdentityKeyLength);
|
||||
|
||||
if (recipientIdentity.recipientId.length < 1) {
|
||||
OWSFail(@"Invalid recipient identity for recipientId: %@", recipientIdentity.recipientId);
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepend key type for transit.
|
||||
// TODO we should just be storing the key type so we don't have to juggle re-adding it.
|
||||
NSData *identityKey = [recipientIdentity.identityKey prependKeyType];
|
||||
if (identityKey.length != kIdentityKeyLength) {
|
||||
OWSFail(@"Invalid recipient identitykey for recipientId: %@ key: %@",
|
||||
recipientIdentity.recipientId,
|
||||
identityKey);
|
||||
return;
|
||||
}
|
||||
|
||||
OWSVerificationStateSyncMessage *message = [[OWSVerificationStateSyncMessage alloc]
|
||||
initWithVerificationState:recipientIdentity.verificationState
|
||||
identityKey:identityKey
|
||||
verificationForRecipientId:recipientIdentity.recipientId];
|
||||
[messages addObject:message];
|
||||
}];
|
||||
if (messages.count > 0) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
for (OWSVerificationStateSyncMessage *message in messages) {
|
||||
[self sendSyncVerificationStateMessage:message];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
//- (void)syncAllVerificationStates
|
||||
//{
|
||||
// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
// @synchronized(self)
|
||||
// {
|
||||
//
|
||||
// NSMutableArray<OWSVerificationStateSyncMessage *> *messages = [NSMutableArray new];
|
||||
// [OWSRecipientIdentity enumerateCollectionObjectsUsingBlock:^(OWSRecipientIdentity *recipientIdentity, BOOL *stop) {
|
||||
// OWSAssert(recipientIdentity);
|
||||
// OWSAssert(recipientIdentity.recipientId.length > 0);
|
||||
// OWSAssert(recipientIdentity.identityKey.length == kStoredIdentityKeyLength);
|
||||
//
|
||||
// if (recipientIdentity.recipientId.length < 1) {
|
||||
// OWSFail(@"Invalid recipient identity for recipientId: %@", recipientIdentity.recipientId);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // Prepend key type for transit.
|
||||
// // TODO we should just be storing the key type so we don't have to juggle re-adding it.
|
||||
// NSData *identityKey = [recipientIdentity.identityKey prependKeyType];
|
||||
// if (identityKey.length != kIdentityKeyLength) {
|
||||
// OWSFail(@"Invalid recipient identitykey for recipientId: %@ key: %@",
|
||||
// recipientIdentity.recipientId,
|
||||
// identityKey);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// OWSVerificationStateSyncMessage *message = [[OWSVerificationStateSyncMessage alloc]
|
||||
// initWithVerificationState:recipientIdentity.verificationState
|
||||
// identityKey:identityKey
|
||||
// verificationForRecipientId:recipientIdentity.recipientId];
|
||||
// [messages addObject:message];
|
||||
// }];
|
||||
// if (messages.count > 0) {
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// for (OWSVerificationStateSyncMessage *message in messages) {
|
||||
// [self sendSyncVerificationStateMessage:message];
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//}
|
||||
|
||||
- (void)sendSyncVerificationStateMessage:(OWSVerificationStateSyncMessage *)message
|
||||
{
|
||||
|
|
|
@ -50,6 +50,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
||||
@property (nonatomic, readonly) OWSIncomingMessageFinder *incomingMessageFinder;
|
||||
@property (nonatomic, readonly) OWSBlockingManager *blockingManager;
|
||||
@property (nonatomic, readonly) OWSIdentityManager *identityManager;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -73,13 +74,16 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
id<ContactsManagerProtocol> contactsManager = [TextSecureKitEnv sharedEnv].contactsManager;
|
||||
id<OWSCallMessageHandler> callMessageHandler = [TextSecureKitEnv sharedEnv].callMessageHandler;
|
||||
ContactsUpdater *contactsUpdater = [ContactsUpdater sharedUpdater];
|
||||
OWSIdentityManager *identityManager = [OWSIdentityManager sharedManager];
|
||||
OWSMessageSender *messageSender = [TextSecureKitEnv sharedEnv].messageSender;
|
||||
|
||||
|
||||
return [self initWithNetworkManager:networkManager
|
||||
storageManager:storageManager
|
||||
callMessageHandler:callMessageHandler
|
||||
contactsManager:contactsManager
|
||||
contactsUpdater:contactsUpdater
|
||||
identityManager:identityManager
|
||||
messageSender:messageSender];
|
||||
}
|
||||
|
||||
|
@ -88,6 +92,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
callMessageHandler:(id<OWSCallMessageHandler>)callMessageHandler
|
||||
contactsManager:(id<ContactsManagerProtocol>)contactsManager
|
||||
contactsUpdater:(ContactsUpdater *)contactsUpdater
|
||||
identityManager:(OWSIdentityManager *)identityManager
|
||||
messageSender:(OWSMessageSender *)messageSender
|
||||
{
|
||||
self = [super init];
|
||||
|
@ -101,6 +106,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
_callMessageHandler = callMessageHandler;
|
||||
_contactsManager = contactsManager;
|
||||
_contactsUpdater = contactsUpdater;
|
||||
_identityManager = identityManager;
|
||||
_messageSender = messageSender;
|
||||
|
||||
_dbConnection = storageManager.newDatabaseConnection;
|
||||
|
@ -364,7 +370,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
SessionCipher *cipher = [[SessionCipher alloc] initWithSessionStore:storageManager
|
||||
preKeyStore:storageManager
|
||||
signedPreKeyStore:storageManager
|
||||
identityKeyStore:[OWSIdentityManager sharedManager]
|
||||
identityKeyStore:self.identityManager
|
||||
recipientId:recipientId
|
||||
deviceId:deviceId];
|
||||
|
||||
|
@ -416,7 +422,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
SessionCipher *cipher = [[SessionCipher alloc] initWithSessionStore:storageManager
|
||||
preKeyStore:storageManager
|
||||
signedPreKeyStore:storageManager
|
||||
identityKeyStore:[OWSIdentityManager sharedManager]
|
||||
identityKeyStore:self.identityManager
|
||||
recipientId:recipientId
|
||||
deviceId:deviceId];
|
||||
|
||||
|
@ -450,7 +456,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
sourceId:envelope.source
|
||||
sourceDeviceId:envelope.sourceDevice];
|
||||
if (duplicateEnvelope) {
|
||||
DDLogInfo(@"%@ Ignoring previously received envelope with timestamp: %llu", self.tag, envelope.timestamp);
|
||||
DDLogInfo(@"%@ Ignoring previously received envelope from %@.%d with timestamp: %llu", self.tag, envelope.source, (unsigned int)envelope.sourceDevice, envelope.timestamp);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -649,7 +655,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
} else if (syncMessage.hasRequest) {
|
||||
if (syncMessage.request.type == OWSSignalServiceProtosSyncMessageRequestTypeContacts) {
|
||||
OWSSyncContactsMessage *syncContactsMessage =
|
||||
[[OWSSyncContactsMessage alloc] initWithContactsManager:self.contactsManager];
|
||||
[[OWSSyncContactsMessage alloc] initWithContactsManager:self.contactsManager
|
||||
identityManager:self.identityManager];
|
||||
|
||||
[self.messageSender sendTemporaryAttachmentData:[syncContactsMessage buildPlainTextAttachmentData]
|
||||
contentType:OWSMimeTypeApplicationOctetStream
|
||||
|
@ -661,8 +668,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
DDLogError(@"%@ Failed to send Contacts response syncMessage with error: %@", self.tag, error);
|
||||
}];
|
||||
|
||||
// Also sync all verification state after syncing contacts.
|
||||
[[OWSIdentityManager sharedManager] syncAllVerificationStates];
|
||||
// // Also sync all verification state after syncing contacts.
|
||||
// [[OWSIdentityManager sharedManager] syncAllVerificationStates];
|
||||
} else if (syncMessage.request.type == OWSSignalServiceProtosSyncMessageRequestTypeGroups) {
|
||||
OWSSyncGroupsMessage *syncGroupsMessage = [[OWSSyncGroupsMessage alloc] init];
|
||||
|
||||
|
@ -690,7 +697,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[readReceiptsProcessor process];
|
||||
} else if (syncMessage.hasVerified) {
|
||||
DDLogInfo(@"%@ Received verification state for %@", self.tag, syncMessage.verified.destination);
|
||||
[[OWSIdentityManager sharedManager] processIncomingSyncMessage:syncMessage.verified];
|
||||
[self.identityManager processIncomingSyncMessage:syncMessage.verified];
|
||||
} else {
|
||||
DDLogWarn(@"%@ Ignoring unsupported sync message.", self.tag);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue