Add link previews setting.

pull/1/head
Matthew Chen 6 years ago
parent 8c7c9b27a2
commit c57b0d98cb

@ -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(@"");

@ -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";

@ -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

@ -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)
}
}
Loading…
Cancel
Save