diff --git a/src/Contacts/TSThread.h b/src/Contacts/TSThread.h index 4cf517658..1a433684c 100644 --- a/src/Contacts/TSThread.h +++ b/src/Contacts/TSThread.h @@ -36,6 +36,11 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable NSString *)contactIdentifier; +/** + * @returns recipientId for each recipient in the thread + */ +@property (nonatomic, readonly) NSArray *recipientIdentifiers; + #if TARGET_OS_IOS /** diff --git a/src/Contacts/TSThread.m b/src/Contacts/TSThread.m index ccdfc564c..97d21d2c4 100644 --- a/src/Contacts/TSThread.m +++ b/src/Contacts/TSThread.m @@ -84,6 +84,12 @@ NS_ASSUME_NONNULL_BEGIN return nil; } +- (NSArray *)recipientIdentifiers +{ + NSAssert(FALSE, @"Should be implemented in subclasses"); + return @[]; +} + - (nullable UIImage *)image { return nil; diff --git a/src/Contacts/Threads/TSContactThread.m b/src/Contacts/Threads/TSContactThread.m index 78c51e82c..47875cb81 100644 --- a/src/Contacts/Threads/TSContactThread.m +++ b/src/Contacts/Threads/TSContactThread.m @@ -80,6 +80,11 @@ NS_ASSUME_NONNULL_BEGIN return [[self class] contactIdFromThreadId:self.uniqueId]; } +- (NSArray *)recipientIdentifiers +{ + return @[self.contactIdentifier]; +} + - (BOOL)isGroupThread { return false; } diff --git a/src/Contacts/Threads/TSGroupThread.m b/src/Contacts/Threads/TSGroupThread.m index 2dadd57b0..4bcef274b 100644 --- a/src/Contacts/Threads/TSGroupThread.m +++ b/src/Contacts/Threads/TSGroupThread.m @@ -6,6 +6,7 @@ #import "NSData+Base64.h" #import "SignalRecipient.h" #import "TSAttachmentStream.h" +#import #import #import @@ -86,6 +87,18 @@ NS_ASSUME_NONNULL_BEGIN return [NSData dataFromBase64String:[threadId substringWithRange:NSMakeRange(1, threadId.length - 1)]]; } +- (NSArray *)recipientIdentifiers +{ + NSMutableArray *groupMemberIds = [self.groupModel.groupMemberIds mutableCopy]; + if (groupMemberIds == nil) { + return @[]; + } + + [groupMemberIds removeObject:[TSAccountManager localNumber]]; + + return [groupMemberIds copy]; +} + // Group and Contact threads share a collection, this is a convenient way to enumerate *just* the group threads + (void)enumerateGroupThreadsUsingBlock:(void (^)(TSGroupThread *groupThread, BOOL *stop))block { diff --git a/src/Network/API/Requests/OWSGetProfileRequest.h b/src/Network/API/Requests/OWSGetProfileRequest.h new file mode 100644 index 000000000..d23442d3c --- /dev/null +++ b/src/Network/API/Requests/OWSGetProfileRequest.h @@ -0,0 +1,15 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "TSRequest.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface OWSGetProfileRequest : TSRequest + +- (instancetype)initWithRecipientId:(NSString *)recipientId; + +@end + +NS_ASSUME_NONNULL_END diff --git a/src/Network/API/Requests/OWSGetProfileRequest.m b/src/Network/API/Requests/OWSGetProfileRequest.m new file mode 100644 index 000000000..8def49234 --- /dev/null +++ b/src/Network/API/Requests/OWSGetProfileRequest.m @@ -0,0 +1,31 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "OWSGetProfileRequest.h" + +NS_ASSUME_NONNULL_BEGIN + +NSString *const OWSProfileRequestPathFormat = @"v1/profile/%@"; + +@implementation OWSGetProfileRequest + +- (instancetype)initWithRecipientId:(NSString *)recipientId +{ + OWSAssert(recipientId.length > 0); + + NSString *path =[NSString stringWithFormat:OWSProfileRequestPathFormat, recipientId]; + self = [super initWithURL:[NSURL URLWithString:path]]; + if (!self) { + return self; + } + + self.HTTPMethod = @"GET"; + self.parameters = nil; + + return self; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/src/Storage/TSStorageManager+keyingMaterial.m b/src/Storage/TSStorageManager+keyingMaterial.m index e0be87119..b12728ad9 100644 --- a/src/Storage/TSStorageManager+keyingMaterial.m +++ b/src/Storage/TSStorageManager+keyingMaterial.m @@ -1,9 +1,5 @@ // -// TSStorageManager+keyingMaterial.m -// TextSecureKit -// -// Created by Frederic Jacobs on 06/11/14. -// Copyright (c) 2014 Open Whisper Systems. All rights reserved. +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // #import "TSStorageManager+keyingMaterial.h" @@ -17,6 +13,7 @@ - (NSString *)localNumber { + // TODO cache this? It only changes once, ever, and otherwise causes "surprising" transactions to occur. return [self stringForKey:TSStorageRegisteredNumberKey inCollection:TSStorageUserAccountCollection]; }