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.
session-ios/SignalServiceKit/src/Contacts/SignalRecipient.m

99 lines
2.4 KiB
Matlab

//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
10 years ago
#import "SignalRecipient.h"
#import "OWSIdentityManager.h"
#import "TSAccountManager.h"
#import <YapDatabase/YapDatabaseConnection.h>
10 years ago
NS_ASSUME_NONNULL_BEGIN
10 years ago
@implementation SignalRecipient
+ (NSString *)collection {
return @"SignalRecipient";
}
- (instancetype)initWithTextSecureIdentifier:(NSString *)textSecureIdentifier
relay:(nullable NSString *)relay
{
10 years ago
self = [super initWithUniqueId:textSecureIdentifier];
if (!self) {
return self;
10 years ago
}
_devices = [NSMutableOrderedSet orderedSetWithObject:[NSNumber numberWithInt:1]];
_relay = [relay isEqualToString:@""] ? nil : relay;
10 years ago
return self;
}
+ (nullable instancetype)recipientWithTextSecureIdentifier:(NSString *)textSecureIdentifier
withTransaction:(YapDatabaseReadTransaction *)transaction
{
10 years ago
return [self fetchObjectWithUniqueID:textSecureIdentifier transaction:transaction];
}
+ (nullable instancetype)recipientWithTextSecureIdentifier:(NSString *)textSecureIdentifier
{
__block SignalRecipient *recipient;
[self.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
recipient = [self recipientWithTextSecureIdentifier:textSecureIdentifier withTransaction:transaction];
}];
return recipient;
}
+ (instancetype)selfRecipient
{
SignalRecipient *myself = [self recipientWithTextSecureIdentifier:[TSAccountManager localNumber]];
if (!myself) {
myself = [[self alloc] initWithTextSecureIdentifier:[TSAccountManager localNumber] relay:nil];
}
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]];
}
}
- (BOOL)supportsVoice
{
return YES;
}
- (BOOL)supportsWebRTC
{
return YES;
}
- (NSString *)recipientId
{
return self.uniqueId;
}
- (NSComparisonResult)compare:(SignalRecipient *)other
{
return [self.recipientId compare:other.recipientId];
}
10 years ago
@end
NS_ASSUME_NONNULL_END