Send "disappearing messages" state for contacts.

pull/1/head
Matthew Chen 7 years ago
parent 2dc37d598c
commit 742d4cabc2

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSThread.h"
@ -19,6 +19,9 @@ NS_ASSUME_NONNULL_BEGIN
transaction:(YapDatabaseReadWriteTransaction *)transaction
relay:(nullable NSString *)relay;
// Unlike getOrCreateThreadWithContactId, this will _NOT_ create a thread if one does not already exist.
+ (nullable instancetype)getThreadWithContactId:(NSString *)contactId;
- (NSString *)contactIdentifier;
+ (NSString *)contactIdFromThreadId:(NSString *)threadId;

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "TSContactThread.h"
@ -83,6 +83,19 @@ NS_ASSUME_NONNULL_BEGIN
return thread;
}
+ (nullable instancetype)getThreadWithContactId:(NSString *)contactId
{
OWSAssert(contactId.length > 0);
__block TSContactThread *_Nullable thread;
[[self dbReadWriteConnection] readWithBlock:^(YapDatabaseReadTransaction *transaction) {
thread =
[TSContactThread fetchObjectWithUniqueID:[self threadIdFromContactId:contactId] transaction:transaction];
}];
return thread;
}
- (NSString *)contactIdentifier {
return [[self class] contactIdFromThreadId:self.uniqueId];
}

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSContactsOutputStream.h"
@ -7,9 +7,11 @@
#import "Cryptography.h"
#import "MIMETypeUtil.h"
#import "NSData+keyVersionByte.h"
#import "OWSDisappearingMessagesConfiguration.h"
#import "OWSRecipientIdentity.h"
#import "OWSSignalServiceProtos.pb.h"
#import "SignalAccount.h"
#import "TSContactThread.h"
#import <ProtocolBuffers/CodedOutputStream.h>
NS_ASSUME_NONNULL_BEGIN
@ -51,6 +53,16 @@ NS_ASSUME_NONNULL_BEGIN
[contactBuilder setProfileKey:profileKeyData];
}
TSContactThread *_Nullable contactThread = [TSContactThread getThreadWithContactId:signalAccount.recipientId];
if (contactThread) {
OWSDisappearingMessagesConfiguration *_Nullable disappearingMessagesConfiguration =
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:contactThread.uniqueId];
if (disappearingMessagesConfiguration && disappearingMessagesConfiguration.isEnabled) {
[contactBuilder setExpireTimer:disappearingMessagesConfiguration.durationSeconds];
}
}
NSData *contactData = [[contactBuilder build] data];
uint32_t contactDataLength = (uint32_t)contactData.length;

Loading…
Cancel
Save