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.
86 lines
2.4 KiB
Matlab
86 lines
2.4 KiB
Matlab
5 years ago
|
//
|
||
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "TSContactThread.h"
|
||
4 years ago
|
#import <YapDatabase/YapDatabase.h>
|
||
|
#import <SessionMessagingKit/OWSIdentityManager.h>
|
||
|
#import <SessionMessagingKit/SessionMessagingKit-Swift.h>
|
||
5 years ago
|
|
||
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
||
|
NSString *const TSContactThreadPrefix = @"c";
|
||
|
|
||
|
@implementation TSContactThread
|
||
|
|
||
|
- (instancetype)initWithContactId:(NSString *)contactId {
|
||
|
NSString *uniqueIdentifier = [[self class] threadIdFromContactId:contactId];
|
||
|
|
||
|
self = [super initWithUniqueId:uniqueIdentifier];
|
||
|
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
+ (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId
|
||
|
transaction:(YapDatabaseReadWriteTransaction *)transaction {
|
||
|
TSContactThread *thread =
|
||
|
[self fetchObjectWithUniqueID:[self threadIdFromContactId:contactId] transaction:transaction];
|
||
|
|
||
|
if (!thread) {
|
||
|
thread = [[TSContactThread alloc] initWithContactId:contactId];
|
||
|
[thread saveWithTransaction:transaction];
|
||
|
}
|
||
|
|
||
|
return thread;
|
||
|
}
|
||
|
|
||
|
+ (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId
|
||
|
{
|
||
|
__block TSContactThread *thread;
|
||
|
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||
|
thread = [self getOrCreateThreadWithContactId:contactId transaction:transaction];
|
||
|
}];
|
||
|
|
||
|
return thread;
|
||
|
}
|
||
|
|
||
|
+ (nullable instancetype)getThreadWithContactId:(NSString *)contactId transaction:(YapDatabaseReadTransaction *)transaction;
|
||
|
{
|
||
|
return [TSContactThread fetchObjectWithUniqueID:[self threadIdFromContactId:contactId] transaction:transaction];
|
||
|
}
|
||
|
|
||
|
- (NSString *)contactIdentifier {
|
||
|
return [[self class] contactIdFromThreadId:self.uniqueId];
|
||
|
}
|
||
|
|
||
|
- (NSArray<NSString *> *)recipientIdentifiers
|
||
|
{
|
||
|
return @[ self.contactIdentifier ];
|
||
|
}
|
||
|
|
||
|
- (BOOL)isGroupThread {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
- (BOOL)hasSafetyNumbers
|
||
|
{
|
||
|
return !![[OWSIdentityManager sharedManager] identityKeyForRecipientId:self.contactIdentifier];
|
||
|
}
|
||
|
|
||
5 years ago
|
- (NSString *)name
|
||
|
{
|
||
4 years ago
|
return [SSKEnvironment.shared.profileManager profileNameForRecipientWithID:self.contactIdentifier avoidingWriteTransaction:YES] ?: self.contactIdentifier;
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
+ (NSString *)threadIdFromContactId:(NSString *)contactId {
|
||
|
return [TSContactThreadPrefix stringByAppendingString:contactId];
|
||
|
}
|
||
|
|
||
|
+ (NSString *)contactIdFromThreadId:(NSString *)threadId {
|
||
|
return [threadId substringWithRange:NSMakeRange(1, threadId.length - 1)];
|
||
|
}
|
||
|
|
||
|
@end
|
||
|
|
||
|
NS_ASSUME_NONNULL_END
|