|
|
@ -4,8 +4,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
#import "TSOutgoingMessage.h"
|
|
|
|
#import "TSOutgoingMessage.h"
|
|
|
|
#import "NSDate+millisecondTimeStamp.h"
|
|
|
|
#import "NSDate+millisecondTimeStamp.h"
|
|
|
|
|
|
|
|
#import "OWSOutgoingSyncMessage.h"
|
|
|
|
#import "OWSProfilesManager.h"
|
|
|
|
#import "OWSProfilesManager.h"
|
|
|
|
#import "OWSSignalServiceProtos.pb.h"
|
|
|
|
#import "OWSSignalServiceProtos.pb.h"
|
|
|
|
|
|
|
|
#import "SignalRecipient.h"
|
|
|
|
#import "TSAttachmentStream.h"
|
|
|
|
#import "TSAttachmentStream.h"
|
|
|
|
#import "TSContactThread.h"
|
|
|
|
#import "TSContactThread.h"
|
|
|
|
#import "TSGroupThread.h"
|
|
|
|
#import "TSGroupThread.h"
|
|
|
@ -456,24 +458,54 @@ NSString *const kTSOutgoingMessageSentRecipientAll = @"kTSOutgoingMessageSentRec
|
|
|
|
return [[self dataMessageBuilder] build];
|
|
|
|
return [[self dataMessageBuilder] build];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSData *)buildPlainTextData
|
|
|
|
- (void)addLocalProfileKeyIfNecessary:(OWSSignalServiceProtosContentBuilder *)contentBuilder
|
|
|
|
|
|
|
|
recipient:(SignalRecipient *)recipient
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OWSSignalServiceProtosContentBuilder *contentBuilder = [OWSSignalServiceProtosContentBuilder new];
|
|
|
|
OWSAssert(contentBuilder);
|
|
|
|
contentBuilder.dataMessage = [self buildDataMessage];
|
|
|
|
OWSAssert(recipient);
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SKIP_PROFILE_KEYS
|
|
|
|
#ifndef SKIP_PROFILE_KEYS
|
|
|
|
OWSAssert([self.thread isKindOfClass:[TSContactThread class]]);
|
|
|
|
OWSAssert(OWSProfilesManager.sharedManager.localProfileKey.length > 0);
|
|
|
|
if ([self.thread isKindOfClass:[TSContactThread class]]) {
|
|
|
|
BOOL shouldIncludeProfileKey = NO;
|
|
|
|
TSContactThread *contactThread = (TSContactThread *)self.thread;
|
|
|
|
|
|
|
|
NSString *recipientId = contactThread.contactIdentifier;
|
|
|
|
if ([self isKindOfClass:[OWSOutgoingSyncMessage class]]) {
|
|
|
|
|
|
|
|
// Always sync the profile key to linked devices.
|
|
|
|
if (OWSProfilesManager.sharedManager.localProfileKey &&
|
|
|
|
shouldIncludeProfileKey = YES;
|
|
|
|
[OWSProfilesManager.sharedManager isUserInProfileWhitelist:recipientId]) {
|
|
|
|
} else {
|
|
|
|
[contentBuilder setProfileKey:OWSProfilesManager.sharedManager.localProfileKey];
|
|
|
|
OWSAssert(self.thread);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For 1:1 threads, we want to include the profile key IFF the
|
|
|
|
|
|
|
|
// contact is in the whitelist.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// For Group threads, we want to include the profile key IFF the
|
|
|
|
|
|
|
|
// recipient OR the group is in the whitelist.
|
|
|
|
|
|
|
|
if ([OWSProfilesManager.sharedManager isUserInProfileWhitelist:recipient.recipientId]) {
|
|
|
|
|
|
|
|
shouldIncludeProfileKey = YES;
|
|
|
|
|
|
|
|
} else if (self.thread.isGroupThread) {
|
|
|
|
|
|
|
|
TSGroupThread *groupThread = (TSGroupThread *)self.thread;
|
|
|
|
|
|
|
|
NSData *groupId = groupThread.groupModel.groupId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ([OWSProfilesManager.sharedManager isGroupIdInProfileWhitelist:groupId]) {
|
|
|
|
|
|
|
|
[contentBuilder setProfileKey:OWSProfilesManager.sharedManager.localProfileKey];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
TSContactThread *contactThread = (TSContactThread *)self.thread;
|
|
|
|
|
|
|
|
NSString *recipientId = contactThread.contactIdentifier;
|
|
|
|
|
|
|
|
OWSAssert([recipientId isEqualToString:recipient.recipientId]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (shouldIncludeProfileKey) {
|
|
|
|
|
|
|
|
[contentBuilder setProfileKey:OWSProfilesManager.sharedManager.localProfileKey];
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (NSData *)buildPlainTextData:(SignalRecipient *)recipient
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
OWSSignalServiceProtosContentBuilder *contentBuilder = [OWSSignalServiceProtosContentBuilder new];
|
|
|
|
|
|
|
|
contentBuilder.dataMessage = [self buildDataMessage];
|
|
|
|
|
|
|
|
[self addLocalProfileKeyIfNecessary:contentBuilder recipient:recipient];
|
|
|
|
return [[contentBuilder build] data];
|
|
|
|
return [[contentBuilder build] data];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|