Update SignalRecipient with “is WebRTC enabled” property from service.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 6791875ebc
commit 08ba42c563

@ -147,25 +147,18 @@ NS_ASSUME_NONNULL_BEGIN
SignalRecipient *recipient = SignalRecipient *recipient =
[SignalRecipient recipientWithTextSecureIdentifier:identifier withTransaction:transaction]; [SignalRecipient recipientWithTextSecureIdentifier:identifier withTransaction:transaction];
if (!recipient) { if (!recipient) {
recipient = recipient = [[SignalRecipient alloc] initWithTextSecureIdentifier:identifier
[[SignalRecipient alloc] initWithTextSecureIdentifier:identifier relay:nil supportsVoice:NO]; relay:nil
supportsVoice:NO
supportsWebRTC:NO];
} }
NSDictionary *attributes = [attributesForIdentifier objectForKey:identifier]; NSDictionary *attributes = [attributesForIdentifier objectForKey:identifier];
NSString *relay = [attributes objectForKey:@"relay"]; recipient.relay = attributes[@"relay"];
if (relay) { recipient.supportsVoice = [attributes[@"voice"] boolValue];
recipient.relay = relay; // The key for the "supports WebRTC audio/video" property is "video".
} else { recipient.supportsWebRTC = [attributes[@"video"] boolValue];
recipient.relay = nil;
}
BOOL supportsVoice = [[attributes objectForKey:@"voice"] boolValue];
if (supportsVoice) {
recipient.supportsVoice = YES;
} else {
recipient.supportsVoice = NO;
}
[recipient saveWithTransaction:transaction]; [recipient saveWithTransaction:transaction];
} }

@ -9,7 +9,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithTextSecureIdentifier:(NSString *)textSecureIdentifier - (instancetype)initWithTextSecureIdentifier:(NSString *)textSecureIdentifier
relay:(nullable NSString *)relay relay:(nullable NSString *)relay
supportsVoice:(BOOL)voiceCapable; supportsVoice:(BOOL)voiceCapable
supportsWebRTC:(BOOL)supportsWebRTC;
+ (instancetype)selfRecipient; + (instancetype)selfRecipient;
+ (nullable instancetype)recipientWithTextSecureIdentifier:(NSString *)textSecureIdentifier; + (nullable instancetype)recipientWithTextSecureIdentifier:(NSString *)textSecureIdentifier;
@ -23,6 +24,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, nullable) NSString *relay; @property (nonatomic, nullable) NSString *relay;
@property (nonatomic, retain) NSMutableOrderedSet *devices; @property (nonatomic, retain) NSMutableOrderedSet *devices;
@property BOOL supportsVoice; @property BOOL supportsVoice;
// This property indicates support for both WebRTC audio and video calls.
@property BOOL supportsWebRTC;
@end @end

@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithTextSecureIdentifier:(NSString *)textSecureIdentifier - (instancetype)initWithTextSecureIdentifier:(NSString *)textSecureIdentifier
relay:(nullable NSString *)relay relay:(nullable NSString *)relay
supportsVoice:(BOOL)voiceCapable supportsVoice:(BOOL)voiceCapable
supportsWebRTC:(BOOL)supportsWebRTC
{ {
self = [super initWithUniqueId:textSecureIdentifier]; self = [super initWithUniqueId:textSecureIdentifier];
if (!self) { if (!self) {
@ -25,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
_devices = [NSMutableOrderedSet orderedSetWithObject:[NSNumber numberWithInt:1]]; _devices = [NSMutableOrderedSet orderedSetWithObject:[NSNumber numberWithInt:1]];
_relay = [relay isEqualToString:@""] ? nil : relay; _relay = [relay isEqualToString:@""] ? nil : relay;
_supportsVoice = voiceCapable; _supportsVoice = voiceCapable;
_supportsWebRTC = supportsWebRTC;
return self; return self;
} }
@ -48,7 +50,12 @@ NS_ASSUME_NONNULL_BEGIN
{ {
SignalRecipient *myself = [self recipientWithTextSecureIdentifier:[TSStorageManager localNumber]]; SignalRecipient *myself = [self recipientWithTextSecureIdentifier:[TSStorageManager localNumber]];
if (!myself) { if (!myself) {
myself = [[self alloc] initWithTextSecureIdentifier:[TSStorageManager localNumber] relay:nil supportsVoice:YES]; myself = [[self alloc] initWithTextSecureIdentifier:[TSStorageManager localNumber]
relay:nil
supportsVoice:YES
// This property may be inaccurate, but it's fine since this will only be
// sent to the current user's other devices, which will ignore this value.
supportsWebRTC:YES];
} }
return myself; return myself;
} }

@ -32,7 +32,12 @@ NS_ASSUME_NONNULL_BEGIN
[SignalRecipient recipientWithTextSecureIdentifier:contactId withTransaction:transaction]; [SignalRecipient recipientWithTextSecureIdentifier:contactId withTransaction:transaction];
if (!recipient) { if (!recipient) {
recipient = [[SignalRecipient alloc] initWithTextSecureIdentifier:contactId relay:relay supportsVoice:YES]; recipient =
[[SignalRecipient alloc] initWithTextSecureIdentifier:contactId
relay:relay
supportsVoice:YES
// Default to NO; ContactsUpdater will try to update this property.
supportsWebRTC:NO];
[[ContactsUpdater sharedUpdater] lookupIdentifier:contactId [[ContactsUpdater sharedUpdater] lookupIdentifier:contactId
success:^(NSSet<NSString *> *matchedIds) { success:^(NSSet<NSString *> *matchedIds) {

Loading…
Cancel
Save