Removed an initial request occurring when pushing the conversation screen (could hold up main thread)

Removed the old OWSPreferences file (everything left over seems to be unused)
pull/612/head
Morgan Pretty 3 years ago
parent af073657a2
commit 4dced25e85

@ -191,8 +191,6 @@
B8856DF8256F1633001CE70E /* NSString+SSK.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDB12255A580800E217F9 /* NSString+SSK.h */; settings = {ATTRIBUTES = (Public, ); }; };
B8856E09256F1676001CE70E /* UIDevice+featureSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = C38EF237255B6D65007E1867 /* UIDevice+featureSupport.swift */; };
B8856E1A256F1700001CE70E /* OWSMath.h in Headers */ = {isa = PBXBuildFile; fileRef = C33FDB14255A580800E217F9 /* OWSMath.h */; settings = {ATTRIBUTES = (Public, ); }; };
B8856ECE256F1E58001CE70E /* OWSPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = C38EF308255B6DBE007E1867 /* OWSPreferences.m */; };
B8856ED7256F1EB4001CE70E /* OWSPreferences.h in Headers */ = {isa = PBXBuildFile; fileRef = C38EF2F1255B6DBB007E1867 /* OWSPreferences.h */; settings = {ATTRIBUTES = (Public, ); }; };
B886B4A72398B23E00211ABE /* QRCodeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B886B4A62398B23E00211ABE /* QRCodeVC.swift */; };
B886B4A92398BA1500211ABE /* QRCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = B886B4A82398BA1500211ABE /* QRCode.swift */; };
B88FA7B826045D100049422F /* OpenGroupAPIV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = B88FA7B726045D100049422F /* OpenGroupAPIV2.swift */; };
@ -1286,7 +1284,6 @@
C38EF2E2255B6DB9007E1867 /* OWSScreenLock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = OWSScreenLock.swift; path = "SignalUtilitiesKit/Screen Lock/OWSScreenLock.swift"; sourceTree = SOURCE_ROOT; };
C38EF2EC255B6DBA007E1867 /* ProximityMonitoringManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ProximityMonitoringManager.swift; path = SessionMessagingKit/Utilities/ProximityMonitoringManager.swift; sourceTree = SOURCE_ROOT; };
C38EF2EF255B6DBB007E1867 /* Weak.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Weak.swift; path = SessionUtilitiesKit/General/Weak.swift; sourceTree = SOURCE_ROOT; };
C38EF2F1255B6DBB007E1867 /* OWSPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWSPreferences.h; path = SessionMessagingKit/Utilities/OWSPreferences.h; sourceTree = SOURCE_ROOT; };
C38EF2F2255B6DBC007E1867 /* Searcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Searcher.swift; path = SignalUtilitiesKit/Utilities/Searcher.swift; sourceTree = SOURCE_ROOT; };
C38EF2F3255B6DBC007E1867 /* UIImage+OWS.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIImage+OWS.swift"; path = "SignalUtilitiesKit/Utilities/UIImage+OWS.swift"; sourceTree = SOURCE_ROOT; };
C38EF2F5255B6DBC007E1867 /* OWSAudioPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWSAudioPlayer.h; path = SessionMessagingKit/Utilities/OWSAudioPlayer.h; sourceTree = SOURCE_ROOT; };
@ -1299,7 +1296,6 @@
C38EF305255B6DBE007E1867 /* OWSFormat.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSFormat.m; path = SignalUtilitiesKit/Utilities/OWSFormat.m; sourceTree = SOURCE_ROOT; };
C38EF306255B6DBE007E1867 /* OWSWindowManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSWindowManager.m; path = SessionMessagingKit/Utilities/OWSWindowManager.m; sourceTree = SOURCE_ROOT; };
C38EF307255B6DBE007E1867 /* UIGestureRecognizer+OWS.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIGestureRecognizer+OWS.swift"; path = "SignalUtilitiesKit/Utilities/UIGestureRecognizer+OWS.swift"; sourceTree = SOURCE_ROOT; };
C38EF308255B6DBE007E1867 /* OWSPreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSPreferences.m; path = SessionMessagingKit/Utilities/OWSPreferences.m; sourceTree = SOURCE_ROOT; };
C38EF309255B6DBE007E1867 /* DeviceSleepManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DeviceSleepManager.swift; path = SessionMessagingKit/Utilities/DeviceSleepManager.swift; sourceTree = SOURCE_ROOT; };
C38EF30A255B6DBE007E1867 /* UIUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UIUtil.h; path = SignalUtilitiesKit/Utilities/UIUtil.h; sourceTree = SOURCE_ROOT; };
C38EF33F255B6DC5007E1867 /* SheetViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SheetViewController.swift; path = "SignalUtilitiesKit/Shared View Controllers/SheetViewController.swift"; sourceTree = SOURCE_ROOT; };
@ -2742,8 +2738,6 @@
C38EF281255B6D84007E1867 /* OWSAudioSession.swift */,
C33FDB38255A580B00E217F9 /* OWSBackgroundTask.h */,
C33FDC1B255A581F00E217F9 /* OWSBackgroundTask.m */,
C38EF2F1255B6DBB007E1867 /* OWSPreferences.h */,
C38EF308255B6DBE007E1867 /* OWSPreferences.m */,
FDF0B75D280AAF35004C14C5 /* Preferences.swift */,
C38EF2FB255B6DBD007E1867 /* OWSWindowManager.h */,
C38EF306255B6DBE007E1867 /* OWSWindowManager.m */,
@ -3434,7 +3428,6 @@
C3C2A6F425539DE700C340D1 /* SessionMessagingKit.h in Headers */,
C32C5C46256DCBB2003C73A2 /* AppReadiness.h in Headers */,
C32C5FC4256E0209003C73A2 /* OWSBackgroundTask.h in Headers */,
B8856ED7256F1EB4001CE70E /* OWSPreferences.h in Headers */,
C32A026C25A801AF000ED5D4 /* NSData+messagePadding.h in Headers */,
B8856D72256F1421001CE70E /* OWSWindowManager.h in Headers */,
B8856CF7256F105E001CE70E /* OWSAudioPlayer.h in Headers */,
@ -4390,7 +4383,6 @@
FD09799127FD499200936362 /* BoxKeyPair+Utilities.swift in Sources */,
FDB4BBC92839BEF000B7C95D /* ProfileManagerError.swift in Sources */,
FDF0B7552807C4BB004C14C5 /* Environment.swift in Sources */,
B8856ECE256F1E58001CE70E /* OWSPreferences.m in Sources */,
FD3E0C84283B5835002A425C /* SessionThreadViewModel.swift in Sources */,
FD09C5EC282B8F18000CE219 /* AttachmentError.swift in Sources */,
FD17D79927F40AB800122BE0 /* _003_YDBToGRDBMigration.swift in Sources */,

@ -336,21 +336,16 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers
setUpNavBarStyle()
navigationItem.titleView = titleView
titleView.update(
with: viewModel.threadData.displayName,
mutedUntilTimestamp: viewModel.threadData.threadMutedUntilTimestamp,
onlyNotifyForMentions: (viewModel.threadData.threadOnlyNotifyForMentions == true),
userCount: viewModel.threadData.userCount
)
updateNavBarButtons(threadData: viewModel.threadData)
// Note: We need to update the nav bar buttons here (with invalid data) because if we don't the
// nav will be offset incorrectly during the push animation (unfortunately the profile icon still
// doesn't appear until after the animation, I assume it's taking a snapshot or something, but
// there isn't much we can do about that unfortunately)
updateNavBarButtons(threadData: nil)
// Constraints
view.addSubview(tableView)
tableView.pin(to: view)
// Blocked banner
addOrRemoveBlockedBanner(threadIsBlocked: (viewModel.threadData.threadIsBlocked == true))
// Message requests view & scroll to bottom
view.addSubview(scrollButton)
view.addSubview(messageRequestView)
@ -366,8 +361,6 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers
self.scrollButtonBottomConstraint = scrollButton.pin(.bottom, to: .bottom, of: view, withInset: -16)
self.scrollButtonBottomConstraint?.isActive = false // Note: Need to disable this to avoid a conflict with the other bottom constraint
self.scrollButtonMessageRequestsBottomConstraint = scrollButton.pin(.bottom, to: .top, of: messageRequestView, withInset: -16)
self.scrollButtonMessageRequestsBottomConstraint?.isActive = (viewModel.threadData.threadIsMessageRequest == true)
self.scrollButtonBottomConstraint?.isActive = (viewModel.threadData.threadIsMessageRequest == false)
messageRequestDescriptionLabel.pin(.top, to: .top, of: messageRequestView, withInset: 10)
messageRequestDescriptionLabel.pin(.left, to: .left, of: messageRequestView, withInset: 40)
@ -399,7 +392,6 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers
unreadCountView.pin(.trailing, to: .trailing, of: unreadCountLabel, withInset: 4)
unreadCountView.centerYAnchor.constraint(equalTo: scrollButton.topAnchor).isActive = true
unreadCountView.center(.horizontal, in: scrollButton)
updateUnreadCountView(unreadCount: viewModel.threadData.threadUnreadCount)
// Notifications
NotificationCenter.default.addObserver(
@ -425,14 +417,6 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers
name: UIResponder.keyboardWillHideNotification,
object: nil
)
// Draft
if let draft: String = viewModel.threadData.threadMessageDraft, !draft.isEmpty {
snInputView.text = draft
}
// Update the input state
snInputView.setEnabledMessageTypes(viewModel.threadData.enabledMessageTypes, message: nil)
}
override func viewWillAppear(_ animated: Bool) {
@ -555,8 +539,17 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers
updateNavBarButtons(threadData: updatedThreadData)
}
if viewModel.threadData.currentUserIsClosedGroupMember != updatedThreadData.currentUserIsClosedGroupMember {
reloadInputViews()
if initialLoad || viewModel.threadData.threadIsBlocked != updatedThreadData.threadIsBlocked {
addOrRemoveBlockedBanner(threadIsBlocked: (updatedThreadData.threadIsBlocked == true))
}
if initialLoad || viewModel.threadData.threadIsMessageRequest != updatedThreadData.threadIsMessageRequest {
scrollButtonMessageRequestsBottomConstraint?.isActive = (updatedThreadData.threadIsMessageRequest == true)
scrollButtonBottomConstraint?.isActive = (updatedThreadData.threadIsMessageRequest == false)
}
if initialLoad || viewModel.threadData.threadUnreadCount != updatedThreadData.threadUnreadCount {
updateUnreadCountView(unreadCount: updatedThreadData.threadUnreadCount)
}
if initialLoad || viewModel.threadData.enabledMessageTypes != updatedThreadData.enabledMessageTypes {
@ -566,12 +559,13 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers
)
}
if initialLoad || viewModel.threadData.threadIsBlocked != updatedThreadData.threadIsBlocked {
addOrRemoveBlockedBanner(threadIsBlocked: (updatedThreadData.threadIsBlocked == true))
// Only set the draft content on the initial load
if initialLoad, let draft: String = updatedThreadData.threadMessageDraft, !draft.isEmpty {
snInputView.text = draft
}
if initialLoad || viewModel.threadData.threadUnreadCount != updatedThreadData.threadUnreadCount {
updateUnreadCountView(unreadCount: updatedThreadData.threadUnreadCount)
if viewModel.threadData.currentUserIsClosedGroupMember != updatedThreadData.currentUserIsClosedGroupMember {
reloadInputViews()
}
// Now we have done all the needed diffs, update the viewModel with the latest data
@ -638,7 +632,7 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers
let numItemsInUpdatedData: [Int] = updatedData.map { $0.elements.count }
let itemChangeInfo: ItemChangeInfo = {
guard
changeset.map { $0.elementInserted.count }.reduce(0, +) > 0,
changeset.map({ $0.elementInserted.count }).reduce(0, +) > 0,
let oldSectionIndex: Int = self.viewModel.interactionData.firstIndex(where: { $0.model == .messages }),
let newSectionIndex: Int = updatedData.firstIndex(where: { $0.model == .messages }),
let newFirstItemIndex: Int = updatedData[newSectionIndex].elements
@ -843,27 +837,25 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers
// Scroll to the last unread message if possible; otherwise scroll to the bottom.
// When the unread message count is more than the number of view items of a page,
// the screen will scroll to the bottom instead of the first unread message
DispatchQueue.main.async {
if let focusedInteractionId: Int64 = self.viewModel.focusedInteractionId {
self.scrollToInteractionIfNeeded(with: focusedInteractionId, isAnimated: false, highlight: true)
}
else if let firstUnreadInteractionId: Int64 = self.viewModel.threadData.threadFirstUnreadInteractionId {
self.scrollToInteractionIfNeeded(with: firstUnreadInteractionId, position: .top, isAnimated: false)
self.unreadCountView.alpha = self.scrollButton.alpha
}
else {
self.scrollToBottom(isAnimated: false)
}
self.scrollButton.alpha = self.getScrollButtonOpacity()
// Now that the data has loaded we need to check if either of the "load more" sections are
// visible and trigger them if so
//
// Note: We do it this way as we want to trigger the load behaviour for the first section
// if it has one before trying to trigger the load behaviour for the last section
self.autoLoadNextPageIfNeeded()
if let focusedInteractionId: Int64 = self.viewModel.focusedInteractionId {
self.scrollToInteractionIfNeeded(with: focusedInteractionId, isAnimated: false, highlight: true)
}
else if let firstUnreadInteractionId: Int64 = self.viewModel.threadData.threadFirstUnreadInteractionId {
self.scrollToInteractionIfNeeded(with: firstUnreadInteractionId, position: .top, isAnimated: false)
self.unreadCountView.alpha = self.scrollButton.alpha
}
else {
self.scrollToBottom(isAnimated: false)
}
self.scrollButton.alpha = self.getScrollButtonOpacity()
// Now that the data has loaded we need to check if either of the "load more" sections are
// visible and trigger them if so
//
// Note: We do it this way as we want to trigger the load behaviour for the first section
// if it has one before trying to trigger the load behaviour for the last section
self.autoLoadNextPageIfNeeded()
}
private func autoLoadNextPageIfNeeded() {
@ -907,7 +899,7 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers
}
}
func updateNavBarButtons(threadData: SessionThreadViewModel) {
func updateNavBarButtons(threadData: SessionThreadViewModel?) {
navigationItem.hidesBackButton = isShowingSearchUI
if isShowingSearchUI {
@ -915,7 +907,7 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers
navigationItem.rightBarButtonItems = []
}
else {
guard threadData.threadRequiresApproval == false else {
guard let threadData: SessionThreadViewModel = threadData, threadData.threadRequiresApproval == false else {
// Note: Adding an empty button because without it the title alignment is
// busted (Note: The size was taken from the layout inspector for the back
// button in Xcode
@ -950,7 +942,7 @@ final class ConversationVC: BaseVC, OWSConversationSettingsViewDelegate, Convers
let rightBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: profilePictureView)
rightBarButtonItem.accessibilityLabel = "Settings button"
rightBarButtonItem.isAccessibilityElement = true
navigationItem.rightBarButtonItem = rightBarButtonItem
default:

@ -33,21 +33,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
// MARK: - Initialization
init?(threadId: String, focusedInteractionId: Int64?) {
let maybeThreadData: SessionThreadViewModel? = GRDBStorage.shared.read { db in
let userPublicKey: String = getUserHexEncodedPublicKey(db)
return try SessionThreadViewModel
.conversationQuery(
threadId: threadId,
userPublicKey: userPublicKey
)
.fetchOne(db)
}
guard let threadData: SessionThreadViewModel = maybeThreadData else { return nil }
self.threadId = threadId
self.threadData = threadData
self.focusedInteractionId = focusedInteractionId
self.pagedDataObserver = nil
@ -147,7 +133,7 @@ public class ConversationViewModel: OWSAudioPlayerDelegate {
// MARK: - Thread Data
/// This value is the current state of the view
public private(set) var threadData: SessionThreadViewModel
public private(set) var threadData: SessionThreadViewModel = SessionThreadViewModel()
/// This is all the data the screen needs to populate itself, please see the following link for tips to help optimise
/// performance https://github.com/groue/GRDB.swift#valueobservation-performance

@ -32,7 +32,6 @@
#import <SignalCoreKit/Threading.h>
#import <SessionMessagingKit/OWSAudioPlayer.h>
#import <SignalUtilitiesKit/OWSFormat.h>
#import <SessionMessagingKit/OWSPreferences.h>
#import <SignalUtilitiesKit/OWSViewController.h>
#import <SignalUtilitiesKit/UIColor+OWS.h>
#import <SignalUtilitiesKit/UIFont+OWS.h>

@ -6,7 +6,6 @@
#import "Session-Swift.h"
#import <SignalCoreKit/NSString+OWS.h>
#import <SessionMessagingKit/OWSPreferences.h>
#import <SignalUtilitiesKit/UIColor+OWS.h>
#import <SignalUtilitiesKit/SignalUtilitiesKit-Swift.h>

@ -5,6 +5,7 @@ import GRDB
import PromiseKit
import SessionSnodeKit
import SessionMessagingKit
import SessionUtilitiesKit
@objc(LKBackgroundPoller)
public final class BackgroundPoller : NSObject {
@ -77,8 +78,6 @@ public final class BackgroundPoller : NSObject {
let processedMessage: ProcessedMessage? = try Message.processRawReceivedMessage(db, rawMessage: message)
let key: String = (processedMessage?.threadId ?? Message.nonThreadMessageId)
// Persist the received message after the MessageReceiveJob is created
_ = try message.info.saved(db)
threadMessages[key] = (threadMessages[key] ?? [])
.appending(processedMessage?.messageInfo)
}

@ -1245,6 +1245,7 @@ enum _003_YDBToGRDBMigration: Migration {
try autoreleasepool {
try attachmentDownloadJobs.forEach { legacyJob in
guard let interactionId: Int64 = legacyInteractionToIdMap[legacyJob.tsMessageID] else {
// This can happen if an UnsendRequest came before an AttachmentDownloadJob completed
SNLog("[Migration Warning] attachmentDownload job with no interaction found - ignoring")
return
}

@ -7,5 +7,4 @@ FOUNDATION_EXPORT const unsigned char SessionMessagingKitVersionString[];
#import <SessionMessagingKit/NSData+messagePadding.h>
#import <SessionMessagingKit/OWSAudioPlayer.h>
#import <SessionMessagingKit/OWSBackgroundTask.h>
#import <SessionMessagingKit/OWSPreferences.h>
#import <SessionMessagingKit/OWSWindowManager.h>

@ -213,6 +213,9 @@ public final class ClosedGroupPoller: NSObject {
SNLog("Received \(messageCount) new message\(messageCount == 1 ? "" : "s") in closed group with public key: \(groupPublicKey) (duplicates: \(messages.count - messageCount))")
}
else {
SNLog("Received no new messages in closed group with public key: \(groupPublicKey)")
}
}
.map { _ in }

@ -185,6 +185,9 @@ public final class Poller {
SNLog("Received \(messageCount) new message\(messageCount == 1 ? "" : "s") (duplicates: \(messages.count - messageCount))")
}
else {
SNLog("Received no new messages")
}
self?.pollCount += 1

@ -1,67 +0,0 @@
//
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <SessionMessagingKit/YapDatabaseConnection+OWS.h>
#import <SessionMessagingKit/YapDatabaseTransaction+OWS.h>
#import <SessionUtilitiesKit/SessionUtilitiesKit.h>
NS_ASSUME_NONNULL_BEGIN
// Used when migrating logging to NSUserDefaults.
extern NSString *const OWSPreferencesSignalDatabaseCollection;
extern NSString *const OWSPreferencesCallLoggingDidChangeNotification;
@class YapDatabaseReadWriteTransaction;
@interface OWSPreferences : NSObject
#pragma mark - Helpers
- (nullable id)tryGetValueForKey:(NSString *)key;
- (void)setValueForKey:(NSString *)key toValue:(nullable id)value;
- (void)clear;
#pragma mark - Specific Preferences
- (BOOL)hasSentAMessage;
- (void)setHasSentAMessage:(BOOL)enabled;
- (BOOL)hasDeclinedNoContactsView;
- (void)setHasDeclinedNoContactsView:(BOOL)value;
- (void)setIOSUpgradeNagDate:(NSDate *)value;
- (nullable NSDate *)iOSUpgradeNagDate;
- (BOOL)shouldShowUnidentifiedDeliveryIndicators;
- (void)setShouldShowUnidentifiedDeliveryIndicators:(BOOL)value;
#pragma mark Callkit
- (BOOL)isSystemCallLogEnabled;
- (void)setIsSystemCallLogEnabled:(BOOL)flag;
#pragma mark - Legacy CallKit settings
- (void)applyCallLoggingSettingsForLegacyUsersWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
- (BOOL)isCallKitEnabled;
- (void)setIsCallKitEnabled:(BOOL)flag;
// Returns YES IFF isCallKitEnabled has been set by user.
- (BOOL)isCallKitEnabledSet;
- (BOOL)isCallKitPrivacyEnabled;
- (void)setIsCallKitPrivacyEnabled:(BOOL)flag;
// Returns YES IFF isCallKitPrivacyEnabled has been set by user.
- (BOOL)isCallKitPrivacySet;
#pragma mark direct call connectivity (non-TURN)
- (BOOL)doCallsHideIPAddress;
- (void)setDoCallsHideIPAddress:(BOOL)flag;
@end
NS_ASSUME_NONNULL_END

@ -1,256 +0,0 @@
//
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
#import "OWSPreferences.h"
NS_ASSUME_NONNULL_BEGIN
NSString *const OWSPreferencesSignalDatabaseCollection = @"SignalPreferences";
NSString *const OWSPreferencesCallLoggingDidChangeNotification = @"OWSPreferencesCallLoggingDidChangeNotification";
NSString *const OWSPreferencesKeyCallKitEnabled = @"CallKitEnabled";
NSString *const OWSPreferencesKeyCallKitPrivacyEnabled = @"CallKitPrivacyEnabled";
NSString *const OWSPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress";
NSString *const OWSPreferencesKeyHasDeclinedNoContactsView = @"hasDeclinedNoContactsView";
NSString *const OWSPreferencesKeyShouldShowUnidentifiedDeliveryIndicators
= @"OWSPreferencesKeyShouldShowUnidentifiedDeliveryIndicators";
NSString *const OWSPreferencesKeyIOSUpgradeNagDate = @"iOSUpgradeNagDate";
NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySystemCallLogEnabled";
@implementation OWSPreferences
- (instancetype)init
{
self = [super init];
if (!self) {
return self;
}
return self;
}
#pragma mark - Helpers
- (void)clear
{
[NSUserDefaults removeAll];
}
- (nullable id)tryGetValueForKey:(NSString *)key
{
__block id result;
[LKStorage readWithBlock:^(YapDatabaseReadTransaction *transaction) {
result = [self tryGetValueForKey:key transaction:transaction];
}];
return result;
}
- (nullable id)tryGetValueForKey:(NSString *)key transaction:(YapDatabaseReadTransaction *)transaction
{
return [transaction objectForKey:key inCollection:OWSPreferencesSignalDatabaseCollection];
}
- (void)setValueForKey:(NSString *)key toValue:(nullable id)value
{
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[self setValueForKey:key toValue:value transaction:transaction];
}];
}
- (void)setValueForKey:(NSString *)key
toValue:(nullable id)value
transaction:(YapDatabaseReadWriteTransaction *)transaction
{
[transaction setObject:value forKey:key inCollection:OWSPreferencesSignalDatabaseCollection];
}
#pragma mark - Specific Preferences
- (BOOL)hasDeclinedNoContactsView
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyHasDeclinedNoContactsView];
// Default to NO.
return preference ? [preference boolValue] : NO;
}
- (void)setHasDeclinedNoContactsView:(BOOL)value
{
[self setValueForKey:OWSPreferencesKeyHasDeclinedNoContactsView toValue:@(value)];
}
- (void)setIOSUpgradeNagDate:(NSDate *)value
{
[self setValueForKey:OWSPreferencesKeyIOSUpgradeNagDate toValue:value];
}
- (nullable NSDate *)iOSUpgradeNagDate
{
return [self tryGetValueForKey:OWSPreferencesKeyIOSUpgradeNagDate];
}
- (BOOL)shouldShowUnidentifiedDeliveryIndicators
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyShouldShowUnidentifiedDeliveryIndicators];
return preference ? [preference boolValue] : NO;
}
- (void)setShouldShowUnidentifiedDeliveryIndicators:(BOOL)value
{
[self setValueForKey:OWSPreferencesKeyShouldShowUnidentifiedDeliveryIndicators toValue:@(value)];
}
#pragma mark - Calling
#pragma mark CallKit
- (BOOL)isSystemCallLogEnabled
{
if (@available(iOS 11, *)) {
// do nothing
} else {
return NO;
}
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeySystemCallLogEnabled];
return preference ? preference.boolValue : YES;
}
- (void)setIsSystemCallLogEnabled:(BOOL)flag
{
if (@available(iOS 11, *)) {
// do nothing
} else {
return;
}
[self setValueForKey:OWSPreferencesKeySystemCallLogEnabled toValue:@(flag)];
}
// In iOS 10.2.1, Apple fixed a bug wherein call history was backed up to iCloud.
//
// See: https://support.apple.com/en-us/HT207482
//
// In iOS 11, Apple introduced a property CXProviderConfiguration.includesCallsInRecents
// that allows us to prevent Signal calls made with CallKit from showing up in the device's
// call history.
//
// Therefore in versions of iOS after 11, we have no need of call privacy.
#pragma mark Legacy CallKit
// Be a little conservative with system call logging with legacy users, even though it's
// not synced to iCloud, users could be concerned to suddenly see caller names in their
// recent calls list.
- (void)applyCallLoggingSettingsForLegacyUsersWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
NSNumber *_Nullable callKitPreference =
[self tryGetValueForKey:OWSPreferencesKeyCallKitEnabled transaction:transaction];
BOOL wasUsingCallKit = callKitPreference ? [callKitPreference boolValue] : YES;
NSNumber *_Nullable callKitPrivacyPreference =
[self tryGetValueForKey:OWSPreferencesKeyCallKitPrivacyEnabled transaction:transaction];
BOOL wasUsingCallKitPrivacy = callKitPrivacyPreference ? callKitPrivacyPreference.boolValue : YES;
BOOL shouldLogCallsInRecents = ^{
if (wasUsingCallKit && !wasUsingCallKitPrivacy) {
// User was using CallKit and explicitly opted in to showing names/numbers,
// so it's OK to continue to show names/numbers in the system recents list.
return YES;
} else {
// User was not previously showing names/numbers in the system
// recents list, so don't opt them in.
return NO;
}
}();
[self setValueForKey:OWSPreferencesKeySystemCallLogEnabled
toValue:@(shouldLogCallsInRecents)
transaction:transaction];
// We need to reload the callService.callUIAdapter here, but SignalMessaging doesn't know about CallService, so we use
// notifications to decouple the code. This is admittedly awkward, but it only happens once, and the alternative would
// be importing all the call related classes into SignalMessaging.
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:OWSPreferencesCallLoggingDidChangeNotification object:nil];
}
- (BOOL)isCallKitEnabled
{
if (@available(iOS 11, *)) {
return YES;
}
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallKitEnabled];
return preference ? [preference boolValue] : YES;
}
- (void)setIsCallKitEnabled:(BOOL)flag
{
if (@available(iOS 11, *)) {
return;
}
[self setValueForKey:OWSPreferencesKeyCallKitEnabled toValue:@(flag)];
// Rev callUIAdaptee to get new setting
}
- (BOOL)isCallKitEnabledSet
{
if (@available(iOS 11, *)) {
return NO;
}
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallKitEnabled];
return preference != nil;
}
- (BOOL)isCallKitPrivacyEnabled
{
if (@available(iOS 11, *)) {
return NO;
}
NSNumber *_Nullable preference = [self tryGetValueForKey:OWSPreferencesKeyCallKitPrivacyEnabled];
if (preference) {
return [preference boolValue];
} else {
// Private by default.
return YES;
}
}
- (void)setIsCallKitPrivacyEnabled:(BOOL)flag
{
if (@available(iOS 11, *)) {
return;
}
[self setValueForKey:OWSPreferencesKeyCallKitPrivacyEnabled toValue:@(flag)];
}
- (BOOL)isCallKitPrivacySet
{
if (@available(iOS 11, *)) {
return NO;
}
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallKitPrivacyEnabled];
return preference != nil;
}
#pragma mark direct call connectivity (non-TURN)
// Allow callers to connect directly, when desirable, vs. enforcing TURN only proxy connectivity
- (BOOL)doCallsHideIPAddress
{
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallsHideIPAddress];
return preference ? [preference boolValue] : NO;
}
- (void)setDoCallsHideIPAddress:(BOOL)flag
{
[self setValueForKey:OWSPreferencesKeyCallsHideIPAddress toValue:@(flag)];
}
@end
NS_ASSUME_NONNULL_END

@ -9,7 +9,6 @@
#import <SignalCoreKit/NSObject+OWS.h>
#import <SignalCoreKit/OWSAsserts.h>
#import <SignalCoreKit/OWSLogs.h>
#import <SessionMessagingKit/OWSPreferences.h>
#import <SignalUtilitiesKit/UIColor+OWS.h>
#import <SignalUtilitiesKit/UIFont+OWS.h>
#import <SessionUtilitiesKit/UIView+OWS.h>

Loading…
Cancel
Save