diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index 64b11798c..90863d958 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -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 diff --git a/Session/Conversations/ConversationVC.swift b/Session/Conversations/ConversationVC.swift index 961e3186d..b048216b8 100644 --- a/Session/Conversations/ConversationVC.swift +++ b/Session/Conversations/ConversationVC.swift @@ -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 { diff --git a/Session/Conversations/Message Cells/VisibleMessageCell.swift b/Session/Conversations/Message Cells/VisibleMessageCell.swift index c60c0d191..528d6ba60 100644 --- a/Session/Conversations/Message Cells/VisibleMessageCell.swift +++ b/Session/Conversations/Message Cells/VisibleMessageCell.swift @@ -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) diff --git a/Session/Conversations/Settings/OWSConversationSettingsViewController.m b/Session/Conversations/Settings/OWSConversationSettingsViewController.m index c7cd2ccc8..22ae752fc 100644 --- a/Session/Conversations/Settings/OWSConversationSettingsViewController.m +++ b/Session/Conversations/Settings/OWSConversationSettingsViewController.m @@ -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]; } } diff --git a/Session/Conversations/Views & Modals/ConversationTitleView.swift b/Session/Conversations/Views & Modals/ConversationTitleView.swift index af4ce2701..caa4b674d 100644 --- a/Session/Conversations/Views & Modals/ConversationTitleView.swift +++ b/Session/Conversations/Views & Modals/ConversationTitleView.swift @@ -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" diff --git a/Session/DMs/NewDMVC.swift b/Session/DMs/NewDMVC.swift index d3254b47d..4e9e77f9d 100644 --- a/Session/DMs/NewDMVC.swift +++ b/Session/DMs/NewDMVC.swift @@ -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) } diff --git a/Session/Home/HomeVC.swift b/Session/Home/HomeVC.swift index 427b4c2f4..45012a7f3 100644 --- a/Session/Home/HomeVC.swift +++ b/Session/Home/HomeVC.swift @@ -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 diff --git a/Session/Meta/SignalApp.m b/Session/Meta/SignalApp.m index 4ddb9c63d..e60a49773 100644 --- a/Session/Meta/SignalApp.m +++ b/Session/Meta/SignalApp.m @@ -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]; } diff --git a/Session/Settings/QRCodeVC.swift b/Session/Settings/QRCodeVC.swift index b2d085a78..1658a9f73 100644 --- a/Session/Settings/QRCodeVC.swift +++ b/Session/Settings/QRCodeVC.swift @@ -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) } diff --git a/Session/Shared/ConversationCell.swift b/Session/Shared/ConversationCell.swift index dd3066c1c..a50ef3d48 100644 --- a/Session/Shared/ConversationCell.swift +++ b/Session/Shared/ConversationCell.swift @@ -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 } } diff --git a/Session/Utilities/ContactUtilities.swift b/Session/Utilities/ContactUtilities.swift index c2b8ff554..2ca6ad644 100644 --- a/Session/Utilities/ContactUtilities.swift +++ b/Session/Utilities/ContactUtilities.swift @@ -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 { diff --git a/SessionMessagingKit/Database/Storage+Messaging.swift b/SessionMessagingKit/Database/Storage+Messaging.swift index ca4149fa0..576112258 100644 --- a/SessionMessagingKit/Database/Storage+Messaging.swift +++ b/SessionMessagingKit/Database/Storage+Messaging.swift @@ -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 } diff --git a/SessionMessagingKit/Messages/Message+Destination.swift b/SessionMessagingKit/Messages/Message+Destination.swift index 8587d5619..acfa6c281 100644 --- a/SessionMessagingKit/Messages/Message+Destination.swift +++ b/SessionMessagingKit/Messages/Message+Destination.swift @@ -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) diff --git a/SessionMessagingKit/Messages/Signal/TSErrorMessage.m b/SessionMessagingKit/Messages/Signal/TSErrorMessage.m index 61654fca9..a678823e2 100644 --- a/SessionMessagingKit/Messages/Signal/TSErrorMessage.m +++ b/SessionMessagingKit/Messages/Signal/TSErrorMessage.m @@ -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. diff --git a/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m b/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m index 065042c09..84377a30b 100644 --- a/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m +++ b/SessionMessagingKit/Messages/Signal/TSIncomingMessage.m @@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN } if (_authorId == nil) { - _authorId = [TSContactThread contactIdFromThreadId:self.uniqueThreadId]; + _authorId = [TSContactThread contactSessionIDFromThreadID:self.uniqueThreadId]; } return self; diff --git a/SessionMessagingKit/Sending & Receiving/Blocking/OWSBlockingManager.m b/SessionMessagingKit/Sending & Receiving/Blocking/OWSBlockingManager.m index 2ef11e634..97e347ad1 100644 --- a/SessionMessagingKit/Sending & Receiving/Blocking/OWSBlockingManager.m +++ b/SessionMessagingKit/Sending & Receiving/Blocking/OWSBlockingManager.m @@ -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]; diff --git a/SessionMessagingKit/Sending & Receiving/Data Extraction/DataExtractionNotificationInfoMessage.swift b/SessionMessagingKit/Sending & Receiving/Data Extraction/DataExtractionNotificationInfoMessage.swift index c1f856637..df2477e25 100644 --- a/SessionMessagingKit/Sending & Receiving/Data Extraction/DataExtractionNotificationInfoMessage.swift +++ b/SessionMessagingKit/Sending & Receiving/Data Extraction/DataExtractionNotificationInfoMessage.swift @@ -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." diff --git a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift index 5091523a6..6d5b53998 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift @@ -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) } diff --git a/SessionMessagingKit/Sending & Receiving/MessageSender+ClosedGroups.swift b/SessionMessagingKit/Sending & Receiving/MessageSender+ClosedGroups.swift index 9d00e0a3b..8e54cb894 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageSender+ClosedGroups.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageSender+ClosedGroups.swift @@ -24,7 +24,7 @@ extension MessageSender { // Send a closed group update message to all members individually var promises: [Promise] = [] 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) diff --git a/SessionMessagingKit/Sending & Receiving/Read Tracking/OWSOutgoingReceiptManager.m b/SessionMessagingKit/Sending & Receiving/Read Tracking/OWSOutgoingReceiptManager.m index 261cd393d..7df3fa741 100644 --- a/SessionMessagingKit/Sending & Receiving/Read Tracking/OWSOutgoingReceiptManager.m +++ b/SessionMessagingKit/Sending & Receiving/Read Tracking/OWSOutgoingReceiptManager.m @@ -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; diff --git a/SessionMessagingKit/Threads/TSContactThread.h b/SessionMessagingKit/Threads/TSContactThread.h index 3d99e34be..f40a7b98c 100644 --- a/SessionMessagingKit/Threads/TSContactThread.h +++ b/SessionMessagingKit/Threads/TSContactThread.h @@ -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 diff --git a/SessionMessagingKit/Threads/TSContactThread.m b/SessionMessagingKit/Threads/TSContactThread.m index 319aa9484..1024389f7 100644 --- a/SessionMessagingKit/Threads/TSContactThread.m +++ b/SessionMessagingKit/Threads/TSContactThread.m @@ -4,7 +4,6 @@ #import "TSContactThread.h" #import -#import #import 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 *)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)]; } diff --git a/SessionMessagingKit/Threads/TSThread.m b/SessionMessagingKit/Threads/TSThread.m index f6fa3b820..d5107cf3b 100644 --- a/SessionMessagingKit/Threads/TSThread.m +++ b/SessionMessagingKit/Threads/TSThread.m @@ -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; } diff --git a/SessionMessagingKit/Utilities/FullTextSearchFinder.swift b/SessionMessagingKit/Utilities/FullTextSearchFinder.swift index 9f0a95f90..05ae92508 100644 --- a/SessionMessagingKit/Utilities/FullTextSearchFinder.swift +++ b/SessionMessagingKit/Utilities/FullTextSearchFinder.swift @@ -162,7 +162,7 @@ public class FullTextSearchFinder: NSObject { } private static let contactThreadIndexer: SearchIndexer = SearchIndexer { (contactThread: TSContactThread, transaction: YapDatabaseReadTransaction) in - let recipientId = contactThread.contactIdentifier() + let recipientId = contactThread.contactSessionID() var result = recipientIndexer.index(recipientId, transaction: transaction) if IsNoteToSelfEnabled(), diff --git a/SignalUtilitiesKit/Database/Migrations/ContactsMigration.swift b/SignalUtilitiesKit/Database/Migrations/ContactsMigration.swift index 82ec5ead9..1c6c2e4cc 100644 --- a/SignalUtilitiesKit/Database/Migrations/ContactsMigration.swift +++ b/SignalUtilitiesKit/Database/Migrations/ContactsMigration.swift @@ -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) diff --git a/SignalUtilitiesKit/Database/ThreadViewHelper.m b/SignalUtilitiesKit/Database/ThreadViewHelper.m index f918d574f..ae9e317b5 100644 --- a/SignalUtilitiesKit/Database/ThreadViewHelper.m +++ b/SignalUtilitiesKit/Database/ThreadViewHelper.m @@ -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 { diff --git a/SignalUtilitiesKit/Media Viewing & Editing/MessageApprovalViewController.swift b/SignalUtilitiesKit/Media Viewing & Editing/MessageApprovalViewController.swift index 253140d2d..8c83c0510 100644 --- a/SignalUtilitiesKit/Media Viewing & Editing/MessageApprovalViewController.swift +++ b/SignalUtilitiesKit/Media Viewing & Editing/MessageApprovalViewController.swift @@ -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 } diff --git a/SignalUtilitiesKit/Messaging/BlockListCache.swift b/SignalUtilitiesKit/Messaging/BlockListCache.swift index 77f0c0295..37b64c564 100644 --- a/SignalUtilitiesKit/Messaging/BlockListCache.swift +++ b/SignalUtilitiesKit/Messaging/BlockListCache.swift @@ -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 { diff --git a/SignalUtilitiesKit/Messaging/BlockListUIUtils.m b/SignalUtilitiesKit/Messaging/BlockListUIUtils.m index 45f5b5489..67bac3464 100644 --- a/SignalUtilitiesKit/Messaging/BlockListUIUtils.m +++ b/SignalUtilitiesKit/Messaging/BlockListUIUtils.m @@ -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]; diff --git a/SignalUtilitiesKit/Messaging/ConfigurationMessage+Convenience.swift b/SignalUtilitiesKit/Messaging/ConfigurationMessage+Convenience.swift index 007cc17f9..d968af906 100644 --- a/SignalUtilitiesKit/Messaging/ConfigurationMessage+Convenience.swift +++ b/SignalUtilitiesKit/Messaging/ConfigurationMessage+Convenience.swift @@ -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 diff --git a/SignalUtilitiesKit/Messaging/FullTextSearcher.swift b/SignalUtilitiesKit/Messaging/FullTextSearcher.swift index 8feb88a97..438a46212 100644 --- a/SignalUtilitiesKit/Messaging/FullTextSearcher.swift +++ b/SignalUtilitiesKit/Messaging/FullTextSearcher.swift @@ -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 = Searcher { (contactThread: TSContactThread) in - let recipientId = contactThread.contactIdentifier() + let recipientId = contactThread.contactSessionID() return self.conversationIndexingString(recipientId: recipientId) } diff --git a/SignalUtilitiesKit/Messaging/ThreadViewModel.swift b/SignalUtilitiesKit/Messaging/ThreadViewModel.swift index a164f96fb..98bbf91d5 100644 --- a/SignalUtilitiesKit/Messaging/ThreadViewModel.swift +++ b/SignalUtilitiesKit/Messaging/ThreadViewModel.swift @@ -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) diff --git a/SignalUtilitiesKit/Profile Pictures/ProfilePictureView.swift b/SignalUtilitiesKit/Profile Pictures/ProfilePictureView.swift index f04b52d97..c1485ad68 100644 --- a/SignalUtilitiesKit/Profile Pictures/ProfilePictureView.swift +++ b/SignalUtilitiesKit/Profile Pictures/ProfilePictureView.swift @@ -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()) } } diff --git a/SignalUtilitiesKit/Sharing/SelectThreadViewController.m b/SignalUtilitiesKit/Sharing/SelectThreadViewController.m index 4fe846768..0a2f5ffe8 100644 --- a/SignalUtilitiesKit/Sharing/SelectThreadViewController.m +++ b/SignalUtilitiesKit/Sharing/SelectThreadViewController.m @@ -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); diff --git a/SignalUtilitiesKit/To Do/ContactCellView.m b/SignalUtilitiesKit/To Do/ContactCellView.m index 2f2570ba3..7190ae587 100644 --- a/SignalUtilitiesKit/To Do/ContactCellView.m +++ b/SignalUtilitiesKit/To Do/ContactCellView.m @@ -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:)