From c57b0d98cb9d422dde6e0fefe652b28bea64fe00 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 17 Jan 2019 16:47:36 -0500 Subject: [PATCH 1/3] Add link previews setting. --- .../PrivacySettingsTableViewController.m | 19 ++++++++++++- .../translations/en.lproj/Localizable.strings | 3 ++ .../Interactions/OWSLinkPreview.swift | 13 +++++++++ .../src/Util/SSKPreferences.swift | 28 +++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 SignalServiceKit/src/Util/SSKPreferences.swift diff --git a/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m b/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m index 6f0f59f0f..428381d7e 100644 --- a/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m +++ b/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. // #import "PrivacySettingsTableViewController.h" @@ -309,6 +309,17 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s }]]; [contents addSection:unidentifiedDeliveryLearnMoreSection]; + OWSTableSection *linkPreviewsSection = [OWSTableSection new]; + [linkPreviewsSection + addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_LINK_PREVIEWS", + @"Setting for enabling & disabling link previews.") + isOn:SSKPreferences.areLinkPreviewsEnabled + target:weakSelf + selector:@selector(didToggleLinkPreviewsEnabled:)]]; + linkPreviewsSection.footerTitle + = NSLocalizedString(@"SETTINGS_LINK_PREVIEWS", @"Setting for enabling & disabling link previews."); + [contents addSection:linkPreviewsSection]; + self.contents = contents; } @@ -417,6 +428,12 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s [self.preferences setShouldShowUnidentifiedDeliveryIndicators:sender.isOn]; } +- (void)didToggleLinkPreviewsEnabled:(UISwitch *)sender +{ + OWSLogInfo(@"toggled to: %@", (sender.isOn ? @"ON" : @"OFF")); + [SSKPreferences setAreLinkPreviewsEnabledWithValue:sender.isOn]; +} + - (void)show2FASettings { OWSLogInfo(@""); diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 62d1b0629..0d7ed36a9 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -2090,6 +2090,9 @@ /* table cell label */ "SETTINGS_LEGAL_TERMS_CELL" = "Terms & Privacy Policy"; +/* Setting for enabling & disabling link previews. */ +"SETTINGS_LINK_PREVIEWS" = "Link Previews"; + /* Title for settings activity */ "SETTINGS_NAV_BAR_TITLE" = "Settings"; diff --git a/SignalServiceKit/src/Messages/Interactions/OWSLinkPreview.swift b/SignalServiceKit/src/Messages/Interactions/OWSLinkPreview.swift index 1256c230d..4f0e8112b 100644 --- a/SignalServiceKit/src/Messages/Interactions/OWSLinkPreview.swift +++ b/SignalServiceKit/src/Messages/Interactions/OWSLinkPreview.swift @@ -101,6 +101,9 @@ public class OWSLinkPreview: MTLModel { guard OWSLinkPreview.featureEnabled else { throw LinkPreviewError.noPreview } + guard SSKPreferences.areLinkPreviewsEnabled() else { + throw LinkPreviewError.noPreview + } guard let previewProto = dataMessage.preview.first else { throw LinkPreviewError.noPreview } @@ -162,6 +165,9 @@ public class OWSLinkPreview: MTLModel { guard OWSLinkPreview.featureEnabled else { throw LinkPreviewError.noPreview } + guard SSKPreferences.areLinkPreviewsEnabled() else { + throw LinkPreviewError.noPreview + } let imageAttachmentId = OWSLinkPreview.saveAttachmentIfPossible(inputFilePath: info.imageFilePath, transaction: transaction) @@ -361,6 +367,9 @@ public class OWSLinkPreview: MTLModel { guard OWSLinkPreview.featureEnabled else { return nil } + guard SSKPreferences.areLinkPreviewsEnabled() else { + return nil + } guard let body = body else { return nil } @@ -407,6 +416,10 @@ public class OWSLinkPreview: MTLModel { completion(nil) return } + guard SSKPreferences.areLinkPreviewsEnabled() else { + completion(nil) + return + } guard let previewUrl = previewUrl else { completion(nil) return diff --git a/SignalServiceKit/src/Util/SSKPreferences.swift b/SignalServiceKit/src/Util/SSKPreferences.swift new file mode 100644 index 000000000..e264cd34b --- /dev/null +++ b/SignalServiceKit/src/Util/SSKPreferences.swift @@ -0,0 +1,28 @@ +// +// Copyright (c) 2019 Open Whisper Systems. All rights reserved. +// + +import Foundation + +@objc +public class SSKPreferences: NSObject { + // Never instantiate this class. + private override init() {} + + private static let collection = "SSKPreferences" + private static let areLinkPreviewsEnabledKey = "areLinkPreviewsEnabled" + + @objc + public class func areLinkPreviewsEnabled() -> Bool { + return OWSPrimaryStorage.dbReadConnection().bool(forKey: areLinkPreviewsEnabledKey, + inCollection: collection, + defaultValue: true) + } + + @objc + public class func setAreLinkPreviewsEnabled(value: Bool) { + return OWSPrimaryStorage.dbReadWriteConnection().setBool(value, + forKey: areLinkPreviewsEnabledKey, + inCollection: collection) + } +} From 1b87e3165c2047865828acf448e93c5eb82d021f Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 17 Jan 2019 16:48:55 -0500 Subject: [PATCH 2/3] Add link previews setting. --- .../AppSettings/PrivacySettingsTableViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m b/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m index 428381d7e..4a6369968 100644 --- a/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m +++ b/Signal/src/ViewControllers/AppSettings/PrivacySettingsTableViewController.m @@ -316,7 +316,7 @@ static NSString *const kSealedSenderInfoURL = @"https://signal.org/blog/sealed-s isOn:SSKPreferences.areLinkPreviewsEnabled target:weakSelf selector:@selector(didToggleLinkPreviewsEnabled:)]]; - linkPreviewsSection.footerTitle + linkPreviewsSection.headerTitle = NSLocalizedString(@"SETTINGS_LINK_PREVIEWS", @"Setting for enabling & disabling link previews."); [contents addSection:linkPreviewsSection]; From feaf5253ac6b8d2f17d9c5b44086ba2fbe2c94df Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 23 Jan 2019 09:19:29 -0500 Subject: [PATCH 3/3] Update Cocoapods. --- Pods | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pods b/Pods index 8b2c886d3..6438a8ea5 160000 --- a/Pods +++ b/Pods @@ -1 +1 @@ -Subproject commit 8b2c886d38cb286341dad31a83ba59a25c30879f +Subproject commit 6438a8ea501bb83f12c4224fd87dd9491319fc3e