Added code to show a HTTP LinkPreview error

Added code to indicate the app won't load LinkPreviews for HTTP urls.
Updated the title & subtitle layout to better handle LinkPreview errors.
Missed an Objective C change in the last commit.
This commit is contained in:
Morgan Pretty 2022-01-13 16:08:23 +11:00
parent 2018e94df8
commit f02f53fc49
25 changed files with 72 additions and 22 deletions

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Mit Session teilen";
"vc_share_loading_message" = "Anlagen werden vorbereitet...";
"vc_share_sending_message" = "Wird gesendet ...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Share to Session";
"vc_share_loading_message" = "Preparing attachments...";
"vc_share_sending_message" = "Sending...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Compartir en Session";
"vc_share_loading_message" = "Preparando archivos adjuntos...";
"vc_share_sending_message" = "Enviando...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "اشتراک گذاری با Session";
"vc_share_loading_message" = "آماده سازی پیوست‌ها...";
"vc_share_sending_message" = "در حال ارسال...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Jaa Sessioniin";
"vc_share_loading_message" = "Valmistellaan liitteitä...";
"vc_share_sending_message" = "Lähetetään...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Partager en Session";
"vc_share_loading_message" = "Préparation des pièces jointes ...";
"vc_share_sending_message" = "Envoi...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "सत्र में साझा करें";
"vc_share_loading_message" = "अटैचमेंट तैयार किए जा रहे हैं...";
"vc_share_sending_message" = "भेजा जा रहा है...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Podijeli sa Session-om";
"vc_share_loading_message" = "Priprema privitaka...";
"vc_share_sending_message" = "Slanje...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Share to Session";
"vc_share_loading_message" = "Preparing attachments...";
"vc_share_sending_message" = "Sending...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Condividi con Session";
"vc_share_loading_message" = "Preparazione allegati...";
"vc_share_sending_message" = "Invio...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Sessionと共有";
"vc_share_loading_message" = "添付ファイルを準備しています...";
"vc_share_sending_message" = "送信中…";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Delen naar de Session";
"vc_share_loading_message" = "Bijlagen voorbereiden...";
"vc_share_sending_message" = "Aan het verzenden...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Udostępnij w Session";
"vc_share_loading_message" = "Przygotowywanie załączników...";
"vc_share_sending_message" = "Wysyłanie...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Compartilhar no Session";
"vc_share_loading_message" = "Preparando anexos...";
"vc_share_sending_message" = "Enviando...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Поделиться в Session";
"vc_share_loading_message" = "Подготовка вложений...";
"vc_share_sending_message" = "Отправка...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Share to Session";
"vc_share_loading_message" = "Preparing attachments...";
"vc_share_sending_message" = "Sending...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Share to Session";
"vc_share_loading_message" = "Pripravujú sa prílohy...";
"vc_share_sending_message" = "Odosiela sa...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Dela i Session";
"vc_share_loading_message" = "Förbereder bilagor...";
"vc_share_sending_message" = "Skickar...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "เชิญมาใช้ Session";
"vc_share_loading_message" = "รวบรวมสิ่งแนบ...";
"vc_share_sending_message" = "กำลังส่ง...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "Share to Session";
"vc_share_loading_message" = "Preparing attachments...";
"vc_share_sending_message" = "Sending...";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "分享至 Session";
"vc_share_loading_message" = "準備附件中⋯";
"vc_share_sending_message" = "傳送中⋯";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -543,6 +543,7 @@
"vc_share_title" = "分享到 Session";
"vc_share_loading_message" = "正在准备附件......";
"vc_share_sending_message" = "正在发送…";
"vc_share_link_previews_unsecure" = "Preview not loaded for unsecure link";
"vc_share_link_previews_error" = "Unable to load preview";
"vc_share_link_previews_disabled_title" = "Link Previews Disabled";
"vc_share_link_previews_disabled_explanation" = "Enabling link previews will show previews for URLs you share. This can be useful, but Session will need to contact linked websites to generate previews.\n\nYou can enable link previews in Session's settings.";

View File

@ -43,6 +43,7 @@ typedef NS_ENUM(NSUInteger, OWSAudioBehavior) {
@property (nonatomic) BOOL isLooping;
@property (nonatomic) BOOL isPlaying;
@property (nonatomic) float playbackRate;
@property (nonatomic) NSTimeInterval duration;
- (instancetype)initWithMediaUrl:(NSURL *)mediaUrl audioBehavior:(OWSAudioBehavior)audioBehavior;
- (instancetype)initWithMediaUrl:(NSURL *)mediaUrl audioBehavior:(OWSAudioBehavior)audioBehavior delegate:(id<OWSAudioPlayerDelegate>)delegate;

View File

@ -168,6 +168,11 @@ NS_ASSUME_NONNULL_BEGIN
return self.audioPlayer.rate;
}
- (NSTimeInterval)duration
{
return [self.audioPlayer duration];
}
- (void)setPlaybackRate:(float)rate
{
[self.audioPlayer setRate:rate];

View File

@ -221,6 +221,22 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
return button
}()
private lazy var titleStackView: UIStackView = {
let stackView: UIStackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
stackView.alignment = (attachment.fileType == .url ? .leading : .center)
stackView.distribution = .fill
switch mode {
case .attachmentApproval: stackView.spacing = 2
case .large: stackView.spacing = 10
case .small: stackView.spacing = 5
}
return stackView
}()
private lazy var titleLabel: UILabel = {
let label: UILabel = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
@ -278,7 +294,7 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
return label
}()
private lazy var fileSizeLabel: UILabel = {
private lazy var subtitleLabel: UILabel = {
let label: UILabel = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
@ -303,7 +319,7 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
case .url:
// If we have no link preview info at this point then assume link previews are disabled
if linkPreviewInfo == nil {
guard let linkPreviewURL: String = linkPreviewInfo?.url else {
label.text = "vc_share_link_previews_disabled_explanation".localized()
label.textColor = Colors.text
label.textAlignment = .center
@ -311,6 +327,13 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
break
}
// We only load Link Previews for HTTPS urls so append an explanation for not
if let targetUrl: URL = URL(string: linkPreviewURL), targetUrl.scheme?.lowercased() != "https" {
label.font = UIFont.ows_regularFont(withSize: Values.verySmallFontSize)
label.text = "vc_share_link_previews_unsecure".localized()
label.textColor = (mode == .attachmentApproval ? Colors.pinIcon : Colors.accent)
}
default:
// Format string for file size label in call interstitial view.
// Embeds: {{file size as 'N mb' or 'N kb'}}.
@ -339,8 +362,10 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
stackView.addArrangedSubview(imageView)
stackView.addArrangedSubview(animatedImageView)
if !titleLabel.isHidden { stackView.addArrangedSubview(UIView.vhSpacer(10, 10)) }
stackView.addArrangedSubview(titleLabel)
stackView.addArrangedSubview(fileSizeLabel)
stackView.addArrangedSubview(titleStackView)
titleStackView.addArrangedSubview(titleLabel)
titleStackView.addArrangedSubview(subtitleLabel)
imageView.addSubview(fileTypeImageView)
@ -425,11 +450,7 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
// If we don't have a valid image then use the 'generic' case
break
case .url:
switch mode {
case .large: return 120
case .attachmentApproval, .small: return 80
}
case .url: return 80
// Use the 'generic' case for these
case .audio, .unknown: break
@ -510,7 +531,7 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
if (attachment.fileType != .url) {
NSLayoutConstraint.activate([
titleLabel.widthAnchor.constraint(equalTo: stackView.widthAnchor, constant: -(32 * 2)),
fileSizeLabel.widthAnchor.constraint(equalTo: stackView.widthAnchor, constant: -(32 * 2))
subtitleLabel.widthAnchor.constraint(equalTo: stackView.widthAnchor, constant: -(32 * 2))
])
}
@ -550,21 +571,22 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
}
}
.catch { [weak self] _ in
self?.titleLabel.attributedText = NSMutableAttributedString(string: linkPreviewURL)
.rtlSafeAppend("\n")
.rtlSafeAppend(
"vc_share_link_previews_error".localized(),
attributes: [
NSAttributedString.Key.font: UIFont.ows_regularFont(
withSize: Values.verySmallFontSize
),
NSAttributedString.Key.foregroundColor: self?.fileSizeLabel.textColor
]
.compactMapValues { $0 }
)
self?.loadingView.alpha = 0
self?.loadingView.stopAnimating()
self?.imageView.alpha = 1
self?.titleLabel.numberOfLines = 1 // Truncates the URL at 1 line so the error is more readable
self?.subtitleLabel.isHidden = false
// Set the error text appropriately
if let targetUrl: URL = URL(string: linkPreviewURL), targetUrl.scheme?.lowercased() != "https" {
// This error case is handled already in the 'subtitleLabel' creation
}
else {
self?.subtitleLabel.font = UIFont.ows_regularFont(withSize: Values.verySmallFontSize)
self?.subtitleLabel.text = "vc_share_link_previews_error".localized()
self?.subtitleLabel.textColor = (self?.mode == .attachmentApproval ? Colors.pinIcon : Colors.accent )
self?.subtitleLabel.textAlignment = .left
}
}
.retainUntilComplete()
}