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.
99 lines
2.4 KiB
Matlab
99 lines
2.4 KiB
Matlab
8 years ago
|
//
|
||
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
10 years ago
|
|
||
|
#import "SignalRecipient.h"
|
||
8 years ago
|
#import "OWSIdentityManager.h"
|
||
9 years ago
|
#import "TSStorageHeaders.h"
|
||
10 years ago
|
|
||
9 years ago
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
10 years ago
|
@implementation SignalRecipient
|
||
|
|
||
|
+ (NSString *)collection {
|
||
|
return @"SignalRecipient";
|
||
|
}
|
||
|
|
||
|
- (instancetype)initWithTextSecureIdentifier:(NSString *)textSecureIdentifier
|
||
9 years ago
|
relay:(nullable NSString *)relay
|
||
|
{
|
||
10 years ago
|
self = [super initWithUniqueId:textSecureIdentifier];
|
||
9 years ago
|
if (!self) {
|
||
|
return self;
|
||
10 years ago
|
}
|
||
|
|
||
9 years ago
|
_devices = [NSMutableOrderedSet orderedSetWithObject:[NSNumber numberWithInt:1]];
|
||
|
_relay = [relay isEqualToString:@""] ? nil : relay;
|
||
|
|
||
10 years ago
|
return self;
|
||
|
}
|
||
|
|
||
9 years ago
|
+ (nullable instancetype)recipientWithTextSecureIdentifier:(NSString *)textSecureIdentifier
|
||
|
withTransaction:(YapDatabaseReadTransaction *)transaction
|
||
|
{
|
||
10 years ago
|
return [self fetchObjectWithUniqueID:textSecureIdentifier transaction:transaction];
|
||
|
}
|
||
|
|
||
9 years ago
|
+ (nullable instancetype)recipientWithTextSecureIdentifier:(NSString *)textSecureIdentifier
|
||
9 years ago
|
{
|
||
|
__block SignalRecipient *recipient;
|
||
8 years ago
|
[self.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
|
||
9 years ago
|
recipient = [self recipientWithTextSecureIdentifier:textSecureIdentifier withTransaction:transaction];
|
||
|
}];
|
||
|
return recipient;
|
||
|
}
|
||
|
|
||
9 years ago
|
+ (instancetype)selfRecipient
|
||
|
{
|
||
|
SignalRecipient *myself = [self recipientWithTextSecureIdentifier:[TSStorageManager localNumber]];
|
||
|
if (!myself) {
|
||
8 years ago
|
myself = [[self alloc] initWithTextSecureIdentifier:[TSStorageManager localNumber]
|
||
8 years ago
|
relay:nil];
|
||
9 years ago
|
}
|
||
|
return myself;
|
||
|
}
|
||
|
|
||
10 years ago
|
- (NSMutableOrderedSet *)devices {
|
||
|
return [_devices copy];
|
||
|
}
|
||
|
|
||
|
- (void)addDevices:(NSSet *)set {
|
||
|
[self checkDevices];
|
||
|
[_devices unionSet:set];
|
||
|
}
|
||
|
|
||
|
- (void)removeDevices:(NSSet *)set {
|
||
|
[self checkDevices];
|
||
|
[_devices minusSet:set];
|
||
|
}
|
||
|
|
||
|
- (void)checkDevices {
|
||
|
if (_devices == nil || ![_devices isKindOfClass:[NSMutableOrderedSet class]]) {
|
||
|
_devices = [NSMutableOrderedSet orderedSetWithObject:[NSNumber numberWithInt:1]];
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
- (BOOL)supportsVoice
|
||
|
{
|
||
|
return YES;
|
||
|
}
|
||
|
|
||
|
- (BOOL)supportsWebRTC
|
||
|
{
|
||
|
return YES;
|
||
|
}
|
||
|
|
||
8 years ago
|
- (NSString *)recipientId
|
||
|
{
|
||
|
return self.uniqueId;
|
||
|
}
|
||
|
|
||
|
- (NSComparisonResult)compare:(SignalRecipient *)other
|
||
|
{
|
||
|
return [self.recipientId compare:other.recipientId];
|
||
|
}
|
||
|
|
||
10 years ago
|
@end
|
||
9 years ago
|
|
||
|
NS_ASSUME_NONNULL_END
|