mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			81 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Objective-C
		
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Objective-C
		
	
| //
 | |
| //  Copyright (c) 2018 Open Whisper Systems. All rights reserved.
 | |
| //
 | |
| 
 | |
| #import "OWSContactsOutputStream.h"
 | |
| #import "MIMETypeUtil.h"
 | |
| #import "NSData+keyVersionByte.h"
 | |
| #import "OWSBlockingManager.h"
 | |
| #import "OWSDisappearingMessagesConfiguration.h"
 | |
| #import "OWSRecipientIdentity.h"
 | |
| #import "SignalAccount.h"
 | |
| #import "TSContactThread.h"
 | |
| #import <SignalCoreKit/Cryptography.h>
 | |
| #import <SignalCoreKit/NSData+OWS.h>
 | |
| #import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>
 | |
| 
 | |
| NS_ASSUME_NONNULL_BEGIN
 | |
| 
 | |
| @implementation OWSContactsOutputStream
 | |
| 
 | |
| - (void)writeSignalAccount:(SignalAccount *)signalAccount
 | |
|          recipientIdentity:(nullable OWSRecipientIdentity *)recipientIdentity
 | |
|             profileKeyData:(nullable NSData *)profileKeyData
 | |
|            contactsManager:(id<ContactsManagerProtocol>)contactsManager
 | |
|      conversationColorName:(NSString *)conversationColorName
 | |
| disappearingMessagesConfiguration:(nullable OWSDisappearingMessagesConfiguration *)disappearingMessagesConfiguration
 | |
| {
 | |
|     OWSAssertDebug(signalAccount);
 | |
|     OWSAssertDebug(contactsManager);
 | |
| 
 | |
|     SNProtoContactDetailsBuilder *contactBuilder =
 | |
|         [SNProtoContactDetails builderWithNumber:signalAccount.recipientId];
 | |
|     [contactBuilder setName:[LKUserDisplayNameUtilities getPrivateChatDisplayNameFor:signalAccount.recipientId] ?: signalAccount.recipientId];
 | |
|     [contactBuilder setColor:conversationColorName];
 | |
| 
 | |
|     if (recipientIdentity != nil) {
 | |
|         SNProtoVerified *_Nullable verified = BuildVerifiedProtoWithRecipientId(recipientIdentity.recipientId,
 | |
|             [recipientIdentity.identityKey prependKeyType],
 | |
|             recipientIdentity.verificationState,
 | |
|             0);
 | |
|         if (!verified) {
 | |
|             OWSLogError(@"could not build protobuf.");
 | |
|             return;
 | |
|         }
 | |
|         contactBuilder.verified = verified;
 | |
|     }
 | |
| 
 | |
|     if (profileKeyData) {
 | |
|         OWSAssertDebug(profileKeyData.length == kAES256_KeyByteLength);
 | |
|         [contactBuilder setProfileKey:profileKeyData];
 | |
|     }
 | |
| 
 | |
|     // Always ensure the "expire timer" property is set so that desktop
 | |
|     // can easily distinguish between a modern client declaring "off" vs a
 | |
|     // legacy client "not specifying".
 | |
|     [contactBuilder setExpireTimer:0];
 | |
| 
 | |
|     if (disappearingMessagesConfiguration && disappearingMessagesConfiguration.isEnabled) {
 | |
|         [contactBuilder setExpireTimer:disappearingMessagesConfiguration.durationSeconds];
 | |
|     }
 | |
| 
 | |
|     if ([OWSBlockingManager.sharedManager isRecipientIdBlocked:signalAccount.recipientId]) {
 | |
|         [contactBuilder setBlocked:YES];
 | |
|     }
 | |
| 
 | |
|     NSError *error;
 | |
|     NSData *_Nullable contactData = [contactBuilder buildSerializedDataAndReturnError:&error];
 | |
|     if (error || !contactData) {
 | |
|         OWSFailDebug(@"could not serialize protobuf: %@", error);
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     uint32_t contactDataLength = (uint32_t)contactData.length;
 | |
|     [self writeUInt32:contactDataLength];
 | |
|     [self writeData:contactData];
 | |
| }
 | |
| 
 | |
| @end
 | |
| 
 | |
| NS_ASSUME_NONNULL_END
 |