Rename contactIdentifier → contactSessionID

pull/402/head
nielsandriesse 4 years ago
parent 21acdfc835
commit 49f3b9f7db

@ -24,7 +24,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
// MARK: Blocking
@objc func unblock() {
guard let thread = thread as? TSContactThread else { return }
let publicKey = thread.contactIdentifier()
let publicKey = thread.contactSessionID()
UIView.animate(withDuration: 0.25, animations: {
self.blockedBanner.alpha = 0
}, completion: { _ in
@ -34,7 +34,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
func showBlockedModalIfNeeded() -> Bool {
guard let thread = thread as? TSContactThread else { return false }
let publicKey = thread.contactIdentifier()
let publicKey = thread.contactSessionID()
guard OWSBlockingManager.shared().isRecipientIdBlocked(publicKey) else { return false }
let blockedModal = BlockedModal(publicKey: publicKey)
blockedModal.modalPresentationStyle = .overFullScreen
@ -390,7 +390,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
case .audio:
if viewItem.interaction is TSIncomingMessage,
let thread = self.thread as? TSContactThread,
Storage.shared.getContact(with: thread.contactIdentifier())?.isTrusted != true {
Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true {
confirmDownload()
} else {
playOrPauseAudio(for: viewItem)
@ -400,7 +400,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
let cell = messagesTableView.cellForRow(at: IndexPath(row: index, section: 0)) as? VisibleMessageCell else { return }
if viewItem.interaction is TSIncomingMessage,
let thread = self.thread as? TSContactThread,
Storage.shared.getContact(with: thread.contactIdentifier())?.isTrusted != true {
Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true {
confirmDownload()
} else {
guard let albumView = cell.albumView else { return }
@ -431,7 +431,7 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
case .genericAttachment:
if viewItem.interaction is TSIncomingMessage,
let thread = self.thread as? TSContactThread,
Storage.shared.getContact(with: thread.contactIdentifier())?.isTrusted != true {
Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true {
confirmDownload()
} else {
// Open the document if possible

@ -116,7 +116,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
lazy var blockedBanner: InfoBanner = {
let name: String
if let thread = thread as? TSContactThread {
let publicKey = thread.contactIdentifier()
let publicKey = thread.contactSessionID()
let context = Contact.context(for: thread)
name = Storage.shared.getContact(with: publicKey)?.displayName(for: context) ?? publicKey
} else {
@ -416,7 +416,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
blockedBanner.removeFromSuperview()
}
guard let thread = thread as? TSContactThread else { return detach() }
if OWSBlockingManager.shared().isRecipientIdBlocked(thread.contactIdentifier()) {
if OWSBlockingManager.shared().isRecipientIdBlocked(thread.contactSessionID()) {
view.addSubview(blockedBanner)
blockedBanner.pin([ UIView.HorizontalEdge.left, UIView.VerticalEdge.top, UIView.HorizontalEdge.right ], to: view)
} else {

@ -344,7 +344,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
case .mediaMessage:
if viewItem.interaction is TSIncomingMessage,
let thread = viewItem.interaction.thread as? TSContactThread,
Storage.shared.getContact(with: thread.contactIdentifier())?.isTrusted != true {
Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true {
showMediaPlaceholder()
} else {
guard let cache = delegate?.getMediaCache() else { preconditionFailure() }
@ -370,7 +370,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
case .audio:
if viewItem.interaction is TSIncomingMessage,
let thread = viewItem.interaction.thread as? TSContactThread,
Storage.shared.getContact(with: thread.contactIdentifier())?.isTrusted != true {
Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true {
showMediaPlaceholder()
} else {
let voiceMessageView = VoiceMessageView(viewItem: viewItem)
@ -381,7 +381,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
case .genericAttachment:
if viewItem.interaction is TSIncomingMessage,
let thread = viewItem.interaction.thread as? TSContactThread,
Storage.shared.getContact(with: thread.contactIdentifier())?.isTrusted != true {
Storage.shared.getContact(with: thread.contactSessionID())?.isTrusted != true {
showMediaPlaceholder()
} else {
let documentView = DocumentView(viewItem: viewItem, textColor: bodyLabelTextColor)

@ -141,7 +141,7 @@ CGFloat kIconViewLength = 24;
NSString *threadName = self.thread.name;
if ([self.thread isKindOfClass:TSContactThread.class]) {
TSContactThread *thread = (TSContactThread *)self.thread;
return [[LKStorage.shared getContactWithSessionID:thread.contactIdentifier] displayNameFor:SNContactContextRegular] ?: @"Anonymous";
return [[LKStorage.shared getContactWithSessionID:thread.contactSessionID] displayNameFor:SNContactContextRegular] ?: @"Anonymous";
} else if (threadName.length == 0 && [self isGroupThread]) {
threadName = [MessageStrings newGroupDefaultTitle];
}
@ -369,7 +369,7 @@ CGFloat kIconViewLength = 24;
displayName = @"the group";
} else {
TSContactThread *thread = (TSContactThread *)self.thread;
displayName = [[LKStorage.shared getContactWithSessionID:thread.contactIdentifier] displayNameFor:SNContactContextRegular] ?: @"anonymous";
displayName = [[LKStorage.shared getContactWithSessionID:thread.contactSessionID] displayNameFor:SNContactContextRegular] ?: @"anonymous";
}
subtitleLabel.text = [NSString stringWithFormat:NSLocalizedString(@"When enabled, messages between you and %@ will disappear after they have been seen.", ""), displayName];
subtitleLabel.textColor = LKColors.text;
@ -740,7 +740,7 @@ CGFloat kIconViewLength = 24;
subtitleView.font = [LKFonts spaceMonoOfSize:LKValues.smallFontSize];
subtitleView.lineBreakMode = NSLineBreakByCharWrapping;
subtitleView.numberOfLines = 2;
subtitleView.text = ((TSContactThread *)self.thread).contactIdentifier;
subtitleView.text = ((TSContactThread *)self.thread).contactSessionID;
subtitleView.textAlignment = NSTextAlignmentCenter;
[stackView addArrangedSubview:subtitleView];
}
@ -1086,7 +1086,7 @@ CGFloat kIconViewLength = 24;
- (void)copySessionID
{
UIPasteboard.generalPasteboard.string = ((TSContactThread *)self.thread).contactIdentifier;
UIPasteboard.generalPasteboard.string = ((TSContactThread *)self.thread).contactSessionID;
}
- (void)showMediaGallery
@ -1137,7 +1137,7 @@ CGFloat kIconViewLength = 24;
- (void)saveName
{
if (![self.thread isKindOfClass:TSContactThread.class]) { return; }
SNContact *contact = [LKStorage.shared getContactWithSessionID:((TSContactThread *)self.thread).contactIdentifier];
SNContact *contact = [LKStorage.shared getContactWithSessionID:((TSContactThread *)self.thread).contactSessionID];
if (contact == nil) { return; }
NSString *text = [self.displayNameTextField.text stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
contact.nickname = text.length > 0 ? text : nil;
@ -1188,7 +1188,7 @@ CGFloat kIconViewLength = 24;
OWSAssertDebug(recipientId.length > 0);
if (recipientId.length > 0 && [self.thread isKindOfClass:[TSContactThread class]] &&
[((TSContactThread *)self.thread).contactIdentifier isEqualToString:recipientId]) {
[((TSContactThread *)self.thread).contactSessionID isEqualToString:recipientId]) {
[self updateTableContents];
}
}

@ -76,7 +76,7 @@ final class ConversationTitleView : UIView {
} else if thread.isNoteToSelf() {
return "Note to Self"
} else {
let sessionID = (thread as! TSContactThread).contactIdentifier()
let sessionID = (thread as! TSContactThread).contactSessionID()
var result = sessionID
Storage.read { transaction in
result = Storage.shared.getContact(with: sessionID)?.displayName(for: .regular) ?? "Anonymous"

@ -154,7 +154,7 @@ final class NewDMVC : BaseVC, UIPageViewControllerDataSource, UIPageViewControll
}
private func startNewDM(with sessionID: String) {
let thread = TSContactThread.getOrCreateThread(contactId: sessionID)
let thread = TSContactThread.getOrCreateThread(contactSessionID: sessionID)
presentingViewController?.dismiss(animated: true, completion: nil)
SignalApp.shared().presentConversation(for: thread, action: .compose, animated: false)
}

@ -338,7 +338,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
}
delete.backgroundColor = Colors.destructive
if let thread = thread as? TSContactThread {
let publicKey = thread.contactIdentifier()
let publicKey = thread.contactSessionID()
let blockingManager = SSKEnvironment.shared.blockingManager
let isBlocked = blockingManager.isRecipientIdBlocked(publicKey)
let block = UITableViewRowAction(style: .normal, title: NSLocalizedString("BLOCK_LIST_BLOCK_BUTTON", comment: "")) { _, _ in

@ -61,7 +61,7 @@ NS_ASSUME_NONNULL_BEGIN
{
__block TSThread *thread = nil;
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
thread = [TSContactThread getOrCreateThreadWithContactId:recipientId transaction:transaction];
thread = [TSContactThread getOrCreateThreadWithContactSessionID:recipientId transaction:transaction];
}];
[self presentConversationForThread:thread action:action animated:(BOOL)isAnimated];
}

@ -126,7 +126,7 @@ final class QRCodeVC : BaseVC, UIPageViewControllerDataSource, UIPageViewControl
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .default, handler: nil))
presentAlert(alert)
} else {
let thread = TSContactThread.getOrCreateThread(contactId: hexEncodedPublicKey)
let thread = TSContactThread.getOrCreateThread(contactSessionID: hexEncodedPublicKey)
presentingViewController?.dismiss(animated: true, completion: nil)
SignalApp.shared().presentConversation(for: thread, action: .compose, animated: false)
}

@ -161,7 +161,7 @@ final class ConversationCell : UITableViewCell {
MentionsManager.populateUserPublicKeyCacheIfNeeded(for: threadID) // FIXME: This is a terrible place to do this
let isBlocked: Bool
if let thread = thread as? TSContactThread {
isBlocked = SSKEnvironment.shared.blockingManager.isRecipientIdBlocked(thread.contactIdentifier())
isBlocked = SSKEnvironment.shared.blockingManager.isRecipientIdBlocked(thread.contactSessionID())
} else {
isBlocked = false
}
@ -220,7 +220,7 @@ final class ConversationCell : UITableViewCell {
if threadViewModel.threadRecord.isNoteToSelf() {
return NSLocalizedString("NOTE_TO_SELF", comment: "")
} else {
let hexEncodedPublicKey = threadViewModel.contactIdentifier!
let hexEncodedPublicKey = threadViewModel.contactSessionID!
return Storage.shared.getContact(with: hexEncodedPublicKey)?.displayName(for: .regular) ?? hexEncodedPublicKey
}
}

@ -6,7 +6,7 @@ enum ContactUtilities {
Storage.read { transaction in
TSContactThread.enumerateCollectionObjects(with: transaction) { object, _ in
guard let thread = object as? TSContactThread, thread.shouldBeVisible else { return }
result.append(thread.contactIdentifier())
result.append(thread.contactSessionID())
}
}
func getDisplayName(for publicKey: String) -> String {

@ -16,7 +16,7 @@ extension Storage {
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
threadOrNil = TSGroupThread.fetch(uniqueId: TSGroupThread.threadId(fromGroupId: groupID), transaction: transaction)
} else {
threadOrNil = TSContactThread.getOrCreateThread(withContactId: publicKey, transaction: transaction)
threadOrNil = TSContactThread.getOrCreateThread(withContactSessionID: publicKey, transaction: transaction)
}
return threadOrNil?.uniqueId
}

@ -9,7 +9,7 @@ public extension Message {
static func from(_ thread: TSThread) -> Message.Destination {
if let thread = thread as? TSContactThread {
return .contact(publicKey: thread.contactIdentifier())
return .contact(publicKey: thread.contactSessionID())
} else if let thread = thread as? TSGroupThread, thread.isClosedGroup {
let groupID = thread.groupModel.groupId
let groupPublicKey = LKGroupUtilities.getDecodedGroupID(groupID)

@ -88,7 +88,7 @@ NSUInteger TSErrorMessageSchemaVersion = 1;
{
NSString *source = envelope.source;
TSContactThread *contactThread =
[TSContactThread getOrCreateThreadWithContactId:source transaction:transaction];
[TSContactThread getOrCreateThreadWithContactSessionID:source transaction:transaction];
// Legit usage of senderTimestamp. We don't actually currently surface it in the UI, but it serves as
// a reference to the envelope which we failed to process.

@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
}
if (_authorId == nil) {
_authorId = [TSContactThread contactIdFromThreadId:self.uniqueThreadId];
_authorId = [TSContactThread contactSessionIDFromThreadID:self.uniqueThreadId];
}
return self;

@ -80,7 +80,7 @@ NSString *const kOWSBlockingManager_SyncedBlockedGroupIdsKey = @"kOWSBlockingMan
{
if ([thread isKindOfClass:[TSContactThread class]]) {
TSContactThread *contactThread = (TSContactThread *)thread;
return [self isRecipientIdBlocked:contactThread.contactIdentifier];
return [self isRecipientIdBlocked:contactThread.contactSessionID];
} else if ([thread isKindOfClass:[TSGroupThread class]]) {
TSGroupThread *groupThread = (TSGroupThread *)thread;
return [self isGroupIdBlocked:groupThread.groupModel.groupId];

@ -16,7 +16,7 @@ final class DataExtractionNotificationInfoMessage : TSInfoMessage {
override func previewText(with transaction: YapDatabaseReadTransaction) -> String {
guard let thread = thread as? TSContactThread else { return "" } // Should never occur
let sessionID = thread.contactIdentifier()
let sessionID = thread.contactSessionID()
let displayName = Storage.shared.getContact(with: sessionID)?.displayName(for: .regular) ?? sessionID
switch messageType {
case .screenshotNotification: return "\(displayName) took a screenshot."

@ -52,7 +52,7 @@ extension MessageReceiver {
public static func showTypingIndicatorIfNeeded(for senderPublicKey: String) {
var threadOrNil: TSContactThread?
Storage.read { transaction in
threadOrNil = TSContactThread.getWithContactId(senderPublicKey, transaction: transaction)
threadOrNil = TSContactThread.getWithContactSessionID(senderPublicKey, transaction: transaction)
}
guard let thread = threadOrNil else { return }
func showTypingIndicatorsIfNeeded() {
@ -70,7 +70,7 @@ extension MessageReceiver {
public static func hideTypingIndicatorIfNeeded(for senderPublicKey: String) {
var threadOrNil: TSContactThread?
Storage.read { transaction in
threadOrNil = TSContactThread.getWithContactId(senderPublicKey, transaction: transaction)
threadOrNil = TSContactThread.getWithContactSessionID(senderPublicKey, transaction: transaction)
}
guard let thread = threadOrNil else { return }
func hideTypingIndicatorsIfNeeded() {
@ -88,7 +88,7 @@ extension MessageReceiver {
public static func cancelTypingIndicatorsIfNeeded(for senderPublicKey: String) {
var threadOrNil: TSContactThread?
Storage.read { transaction in
threadOrNil = TSContactThread.getWithContactId(senderPublicKey, transaction: transaction)
threadOrNil = TSContactThread.getWithContactSessionID(senderPublicKey, transaction: transaction)
}
guard let thread = threadOrNil else { return }
func cancelTypingIndicatorsIfNeeded() {
@ -110,7 +110,7 @@ extension MessageReceiver {
private static func handleDataExtractionNotification(_ message: DataExtractionNotification, using transaction: Any) {
let transaction = transaction as! YapDatabaseReadWriteTransaction
guard message.groupPublicKey == nil,
let thread = TSContactThread.getWithContactId(message.sender!, transaction: transaction) else { return }
let thread = TSContactThread.getWithContactSessionID(message.sender!, transaction: transaction) else { return }
let type: TSInfoMessageType
switch message.kind! {
case .screenshot: type = .screenshotNotification
@ -140,7 +140,7 @@ extension MessageReceiver {
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
threadOrNil = TSGroupThread.fetch(uniqueId: TSGroupThread.threadId(fromGroupId: groupID), transaction: transaction)
} else {
threadOrNil = TSContactThread.getWithContactId(syncTarget ?? senderPublicKey, transaction: transaction)
threadOrNil = TSContactThread.getWithContactSessionID(syncTarget ?? senderPublicKey, transaction: transaction)
}
guard let thread = threadOrNil else { return }
let configuration = OWSDisappearingMessagesConfiguration(threadId: thread.uniqueId!, enabled: true, durationSeconds: duration)
@ -160,7 +160,7 @@ extension MessageReceiver {
let groupID = LKGroupUtilities.getEncodedClosedGroupIDAsData(groupPublicKey)
threadOrNil = TSGroupThread.fetch(uniqueId: TSGroupThread.threadId(fromGroupId: groupID), transaction: transaction)
} else {
threadOrNil = TSContactThread.getWithContactId(syncTarget ?? senderPublicKey, transaction: transaction)
threadOrNil = TSContactThread.getWithContactSessionID(syncTarget ?? senderPublicKey, transaction: transaction)
}
guard let thread = threadOrNil else { return }
let configuration = OWSDisappearingMessagesConfiguration(threadId: thread.uniqueId!, enabled: false, durationSeconds: 24 * 60 * 60)
@ -201,7 +201,7 @@ extension MessageReceiver {
userProfile.avatarUrlPath = contact.profilePictureURL
userProfile.profileName = contact.displayName
userProfile.save(with: transaction)
let thread = TSContactThread.getOrCreateThread(withContactId: sessionID, transaction: transaction)
let thread = TSContactThread.getOrCreateThread(withContactSessionID: sessionID, transaction: transaction)
thread.shouldBeVisible = true
thread.save(with: transaction)
}

@ -24,7 +24,7 @@ extension MessageSender {
// Send a closed group update message to all members individually
var promises: [Promise<Void>] = []
for member in members {
let thread = TSContactThread.getOrCreateThread(withContactId: member, transaction: transaction)
let thread = TSContactThread.getOrCreateThread(withContactSessionID: member, transaction: transaction)
thread.save(with: transaction)
let closedGroupControlMessageKind = ClosedGroupControlMessage.Kind.new(publicKey: Data(hex: groupPublicKey), name: name,
encryptionKeyPair: encryptionKeyPair, members: membersAsData, admins: adminsAsData)
@ -170,7 +170,7 @@ extension MessageSender {
MessageSender.send(closedGroupControlMessage, in: thread, using: transaction)
// Send updates to the new members individually
for member in newMembers {
let thread = TSContactThread.getOrCreateThread(withContactId: member, transaction: transaction)
let thread = TSContactThread.getOrCreateThread(withContactSessionID: member, transaction: transaction)
thread.save(with: transaction)
let closedGroupControlMessageKind = ClosedGroupControlMessage.Kind.new(publicKey: Data(hex: groupPublicKey), name: group.groupName!,
encryptionKeyPair: encryptionKeyPair, members: membersAsData, admins: adminsAsData)
@ -323,7 +323,7 @@ extension MessageSender {
// Send it
guard let proto = try? SNProtoKeyPair.builder(publicKey: encryptionKeyPair.publicKey,
privateKey: encryptionKeyPair.privateKey).build(), let plaintext = try? proto.serializedData() else { return }
let contactThread = TSContactThread.getOrCreateThread(withContactId: publicKey, transaction: transaction)
let contactThread = TSContactThread.getOrCreateThread(withContactSessionID: publicKey, transaction: transaction)
guard let ciphertext = try? MessageSender.encryptWithSessionProtocol(plaintext, for: publicKey) else { return }
SNLog("Sending latest encryption key pair to: \(publicKey).")
let wrapper = ClosedGroupControlMessage.KeyPairWrapper(publicKey: publicKey, encryptedKeyPair: ciphertext)

@ -155,7 +155,7 @@ NSString *const kOutgoingReadReceiptManagerCollection = @"kOutgoingReadReceiptMa
continue;
}
TSThread *thread = [TSContactThread getOrCreateThreadWithContactId:recipientId];
TSThread *thread = [TSContactThread getOrCreateThreadWithContactSessionID:recipientId];
if (thread.isGroupThread) { // Don't send receipts in group threads
continue;

@ -10,21 +10,21 @@ extern NSString *const TSContactThreadPrefix;
@interface TSContactThread : TSThread
- (instancetype)initWithContactId:(NSString *)contactId;
- (instancetype)initWithContactSessionID:(NSString *)contactSessionID;
+ (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId NS_SWIFT_NAME(getOrCreateThread(contactId:));
+ (instancetype)getOrCreateThreadWithContactSessionID:(NSString *)contactSessionID NS_SWIFT_NAME(getOrCreateThread(contactSessionID:));
+ (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId
transaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (instancetype)getOrCreateThreadWithContactSessionID:(NSString *)contactSessionID
transaction:(YapDatabaseReadWriteTransaction *)transaction;
// Unlike getOrCreateThreadWithContactId, this will _NOT_ create a thread if one does not already exist.
+ (nullable instancetype)getThreadWithContactId:(NSString *)contactId transaction:(YapDatabaseReadTransaction *)transaction;
// Unlike getOrCreateThreadWithContactSessionID, this will _NOT_ create a thread if one does not already exist.
+ (nullable instancetype)getThreadWithContactSessionID:(NSString *)contactSessionID transaction:(YapDatabaseReadTransaction *)transaction;
- (NSString *)contactIdentifier;
- (NSString *)contactSessionID;
+ (NSString *)contactIdFromThreadId:(NSString *)threadId;
+ (NSString *)contactSessionIDFromThreadID:(NSString *)threadId;
+ (NSString *)threadIdFromContactId:(NSString *)contactId;
+ (NSString *)threadIDFromContactSessionID:(NSString *)contactSessionID;
@end

@ -4,7 +4,6 @@
#import "TSContactThread.h"
#import <YapDatabase/YapDatabase.h>
#import <SessionMessagingKit/OWSIdentityManager.h>
#import <SessionMessagingKit/SessionMessagingKit-Swift.h>
NS_ASSUME_NONNULL_BEGIN
@ -13,49 +12,49 @@ NSString *const TSContactThreadPrefix = @"c";
@implementation TSContactThread
- (instancetype)initWithContactId:(NSString *)contactId {
NSString *uniqueIdentifier = [[self class] threadIdFromContactId:contactId];
- (instancetype)initWithContactSessionID:(NSString *)contactSessionID {
NSString *uniqueIdentifier = [[self class] threadIDFromContactSessionID:contactSessionID];
self = [super initWithUniqueId:uniqueIdentifier];
return self;
}
+ (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId
+ (instancetype)getOrCreateThreadWithContactSessionID:(NSString *)contactSessionID
transaction:(YapDatabaseReadWriteTransaction *)transaction {
TSContactThread *thread =
[self fetchObjectWithUniqueID:[self threadIdFromContactId:contactId] transaction:transaction];
[self fetchObjectWithUniqueID:[self threadIDFromContactSessionID:contactSessionID] transaction:transaction];
if (!thread) {
thread = [[TSContactThread alloc] initWithContactId:contactId];
thread = [[TSContactThread alloc] initWithContactSessionID:contactSessionID];
[thread saveWithTransaction:transaction];
}
return thread;
}
+ (instancetype)getOrCreateThreadWithContactId:(NSString *)contactId
+ (instancetype)getOrCreateThreadWithContactSessionID:(NSString *)contactSessionID
{
__block TSContactThread *thread;
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
thread = [self getOrCreateThreadWithContactId:contactId transaction:transaction];
thread = [self getOrCreateThreadWithContactSessionID:contactSessionID transaction:transaction];
}];
return thread;
}
+ (nullable instancetype)getThreadWithContactId:(NSString *)contactId transaction:(YapDatabaseReadTransaction *)transaction;
+ (nullable instancetype)getThreadWithContactSessionID:(NSString *)contactSessionID transaction:(YapDatabaseReadTransaction *)transaction;
{
return [TSContactThread fetchObjectWithUniqueID:[self threadIdFromContactId:contactId] transaction:transaction];
return [TSContactThread fetchObjectWithUniqueID:[self threadIDFromContactSessionID:contactSessionID] transaction:transaction];
}
- (NSString *)contactIdentifier {
return [[self class] contactIdFromThreadId:self.uniqueId];
- (NSString *)contactSessionID {
return [[self class] contactSessionIDFromThreadID:self.uniqueId];
}
- (NSArray<NSString *> *)recipientIdentifiers
{
return @[ self.contactIdentifier ];
return @[ self.contactSessionID ];
}
- (BOOL)isGroupThread
@ -65,16 +64,16 @@ NSString *const TSContactThreadPrefix = @"c";
- (NSString *)name
{
NSString *sessionID = self.contactIdentifier;
NSString *sessionID = self.contactSessionID;
SNContact *contact = [LKStorage.shared getContactWithSessionID:sessionID];
return [contact displayNameFor:SNContactContextRegular] ?: sessionID;
}
+ (NSString *)threadIdFromContactId:(NSString *)contactId {
return [TSContactThreadPrefix stringByAppendingString:contactId];
+ (NSString *)threadIDFromContactSessionID:(NSString *)contactSessionID {
return [TSContactThreadPrefix stringByAppendingString:contactSessionID];
}
+ (NSString *)contactIdFromThreadId:(NSString *)threadId {
+ (NSString *)contactSessionIDFromThreadID:(NSString *)threadId {
return [threadId substringWithRange:NSMakeRange(1, threadId.length - 1)];
}

@ -128,7 +128,7 @@ BOOL IsNoteToSelfEnabled(void)
{
if (!IsNoteToSelfEnabled()) { return NO; }
if (![self isKindOfClass:TSContactThread.class]) { return NO; }
return [self.contactIdentifier isEqual:[SNGeneralUtilities getUserPublicKey]];
return [self.contactSessionID isEqual:[SNGeneralUtilities getUserPublicKey]];
}
#pragma mark To be subclassed.
@ -138,7 +138,7 @@ BOOL IsNoteToSelfEnabled(void)
}
// Override in ContactThread
- (nullable NSString *)contactIdentifier
- (nullable NSString *)contactSessionID
{
return nil;
}

@ -162,7 +162,7 @@ public class FullTextSearchFinder: NSObject {
}
private static let contactThreadIndexer: SearchIndexer<TSContactThread> = SearchIndexer { (contactThread: TSContactThread, transaction: YapDatabaseReadTransaction) in
let recipientId = contactThread.contactIdentifier()
let recipientId = contactThread.contactSessionID()
var result = recipientIndexer.index(recipientId, transaction: transaction)
if IsNoteToSelfEnabled(),

@ -15,7 +15,7 @@ public class ContactsMigration : OWSDatabaseMigration {
var contacts: [Contact] = []
TSContactThread.enumerateCollectionObjects { object, _ in
guard let thread = object as? TSContactThread else { return }
let sessionID = thread.contactIdentifier()
let sessionID = thread.contactSessionID()
if let contact = Storage.shared.getContact(with: sessionID) {
contact.isTrusted = true
contacts.append(contact)

@ -202,7 +202,7 @@ NS_ASSUME_NONNULL_BEGIN
withMappings:self.threadMappings];
if (!thread.shouldBeVisible) { continue; }
if ([thread isKindOfClass:TSContactThread.class]) {
NSString *publicKey = ((TSContactThread *)thread).contactIdentifier;
NSString *publicKey = ((TSContactThread *)thread).contactSessionID;
if ([[LKStorage.shared getContactWithSessionID:publicKey] name] == nil) { continue; }
[threads addObject:thread];
} else {

@ -162,7 +162,7 @@ public class MessageApprovalViewController: OWSViewController, UITextViewDelegat
return recipientRow
}
let publicKey = contactThread.contactIdentifier()
let publicKey = contactThread.contactSessionID()
nameLabel.text = Storage.shared.getContact(with: publicKey)?.displayName(for: .regular) ?? publicKey
nameLabel.textColor = Theme.primaryColor
@ -188,7 +188,7 @@ public class MessageApprovalViewController: OWSViewController, UITextViewDelegat
}
private func profileName(contactThread: TSContactThread) -> String? {
let publicKey = contactThread.contactIdentifier()
let publicKey = contactThread.contactSessionID()
return Storage.shared.getContact(with: publicKey)?.displayName(for: .regular) ?? publicKey
}

@ -86,7 +86,7 @@ public class BlockListCache: NSObject {
switch thread {
case let contactThread as TSContactThread:
return serialQueue.sync {
blockedRecipientIds.contains(contactThread.contactIdentifier())
blockedRecipientIds.contains(contactThread.contactSessionID())
}
case let groupThread as TSGroupThread:
return serialQueue.sync {

@ -27,7 +27,7 @@ typedef void (^BlockAlertCompletionBlock)(UIAlertAction *action);
{
if ([thread isKindOfClass:[TSContactThread class]]) {
TSContactThread *contactThread = (TSContactThread *)thread;
[self showBlockPhoneNumberActionSheet:contactThread.contactIdentifier
[self showBlockPhoneNumberActionSheet:contactThread.contactSessionID
fromViewController:fromViewController
blockingManager:blockingManager
completionBlock:completionBlock];
@ -257,7 +257,7 @@ typedef void (^BlockAlertCompletionBlock)(UIAlertAction *action);
{
if ([thread isKindOfClass:[TSContactThread class]]) {
TSContactThread *contactThread = (TSContactThread *)thread;
[self showUnblockPhoneNumberActionSheet:contactThread.contactIdentifier
[self showUnblockPhoneNumberActionSheet:contactThread.contactSessionID
fromViewController:fromViewController
blockingManager:blockingManager
completionBlock:completionBlock];

@ -36,7 +36,7 @@ extension ConfigurationMessage {
OWSUserProfile.enumerateCollectionObjects(with: transaction) { object, stop in
guard let profile = object as? OWSUserProfile, let displayName = profile.profileName else { return }
let publicKey = profile.recipientId
let threadID = TSContactThread.threadId(fromContactId: publicKey)
let threadID = TSContactThread.threadID(fromContactSessionID: publicKey)
guard let thread = TSContactThread.fetch(uniqueId: threadID, transaction: transaction), thread.shouldBeVisible
&& !SSKEnvironment.shared.blockingManager.isRecipientIdBlocked(publicKey) else { return }
let profilePictureURL = profile.avatarUrlPath

@ -243,7 +243,7 @@ public class FullTextSearcher: NSObject {
let searchResult = ConversationSearchResult(thread: threadViewModel, sortKey: sortKey)
if let contactThread = thread as? TSContactThread {
let recipientId = contactThread.contactIdentifier()
let recipientId = contactThread.contactSessionID()
existingConversationRecipientIds.insert(recipientId)
}
@ -360,7 +360,7 @@ public class FullTextSearcher: NSObject {
}
private lazy var contactThreadSearcher: Searcher<TSContactThread> = Searcher { (contactThread: TSContactThread) in
let recipientId = contactThread.contactIdentifier()
let recipientId = contactThread.contactSessionID()
return self.conversationIndexingString(recipientId: recipientId)
}

@ -11,7 +11,7 @@ public class ThreadViewModel: NSObject {
@objc public let isGroupThread: Bool
@objc public let threadRecord: TSThread
@objc public let unreadCount: UInt
@objc public let contactIdentifier: String?
@objc public let contactSessionID: String?
@objc public let name: String
@objc public let isMuted: Bool
@ -35,9 +35,9 @@ public class ThreadViewModel: NSObject {
self.lastMessageDate = lastInteraction?.dateForUI() ?? thread.creationDate
if let contactThread = thread as? TSContactThread {
self.contactIdentifier = contactThread.contactIdentifier()
self.contactSessionID = contactThread.contactSessionID()
} else {
self.contactIdentifier = nil
self.contactSessionID = nil
}
self.unreadCount = thread.unreadMessageCount(transaction: transaction)

@ -82,8 +82,8 @@ public final class ProfilePictureView : UIView {
update()
} else { // A one-to-one chat
let thread = thread as! TSContactThread
hasTappableProfilePicture = OWSProfileManager.shared().profileAvatar(forRecipientId: thread.contactIdentifier()) != nil
update(for: thread.contactIdentifier())
hasTappableProfilePicture = OWSProfileManager.shared().profileAvatar(forRecipientId: thread.contactSessionID()) != nil
update(for: thread.contactSessionID())
}
}

@ -269,7 +269,7 @@ NS_ASSUME_NONNULL_BEGIN
__block TSThread *thread = nil;
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
thread = [TSContactThread getOrCreateThreadWithContactId:signalAccount.recipientId transaction:transaction];
thread = [TSContactThread getOrCreateThreadWithContactSessionID:signalAccount.recipientId transaction:transaction];
}];
OWSAssertDebug(thread);

@ -130,7 +130,7 @@ const CGFloat kContactCellAvatarTextMargin = 12;
self.recipientId = recipientId;
[self.primaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
self.thread = [TSContactThread getThreadWithContactId:recipientId transaction:transaction];
self.thread = [TSContactThread getThreadWithContactSessionID:recipientId transaction:transaction];
}];
BOOL isNoteToSelf = (IsNoteToSelfEnabled() && [recipientId isEqualToString:self.tsAccountManager.localNumber]);
@ -175,13 +175,13 @@ const CGFloat kContactCellAvatarTextMargin = 12;
}
BOOL isNoteToSelf
= ([thread isKindOfClass:TSContactThread.class] && [((TSContactThread *)thread).contactIdentifier isEqualToString:self.tsAccountManager.localNumber]);
= ([thread isKindOfClass:TSContactThread.class] && [((TSContactThread *)thread).contactSessionID isEqualToString:self.tsAccountManager.localNumber]);
if (isNoteToSelf) {
threadName = NSLocalizedString(@"NOTE_TO_SELF", @"Label for 1:1 conversation with yourself.");
}
if ([thread isKindOfClass:[TSContactThread class]]) {
self.recipientId = ((TSContactThread *)thread).contactIdentifier;
self.recipientId = ((TSContactThread *)thread).contactSessionID;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(otherUsersProfileDidChange:)

Loading…
Cancel
Save