Further refactoring work
Refactored usages and removed AFNetworking Updated the media screens to use Combine # Conflicts: # Session/Closed Groups/GroupMembersViewModel.swift # Session/Media Viewing & Editing/GIFs/GifPickerCell.swift # Session/Media Viewing & Editing/GIFs/GiphyAPI.swift # Session/Media Viewing & Editing/PhotoCapture.swift
This commit is contained in:
parent
c9fdee9f24
commit
8ac6b25ced
2
Podfile
2
Podfile
|
@ -19,7 +19,6 @@ abstract_target 'GlobalDependencies' do
|
|||
pod 'SocketRocket', '~> 0.5.1'
|
||||
|
||||
target 'Session' do
|
||||
pod 'AFNetworking'
|
||||
pod 'Reachability'
|
||||
pod 'PureLayout', '~> 3.1.8'
|
||||
pod 'NVActivityIndicatorView'
|
||||
|
@ -45,7 +44,6 @@ abstract_target 'GlobalDependencies' do
|
|||
|
||||
# Dependencies that are shared across a number of extensions/frameworks but not all
|
||||
abstract_target 'ExtendedDependencies' do
|
||||
pod 'AFNetworking'
|
||||
pod 'PureLayout', '~> 3.1.8'
|
||||
|
||||
target 'SessionShareExtension' do
|
||||
|
|
20
Podfile.lock
20
Podfile.lock
|
@ -1,19 +1,4 @@
|
|||
PODS:
|
||||
- AFNetworking (4.0.1):
|
||||
- AFNetworking/NSURLSession (= 4.0.1)
|
||||
- AFNetworking/Reachability (= 4.0.1)
|
||||
- AFNetworking/Security (= 4.0.1)
|
||||
- AFNetworking/Serialization (= 4.0.1)
|
||||
- AFNetworking/UIKit (= 4.0.1)
|
||||
- AFNetworking/NSURLSession (4.0.1):
|
||||
- AFNetworking/Reachability
|
||||
- AFNetworking/Security
|
||||
- AFNetworking/Serialization
|
||||
- AFNetworking/Reachability (4.0.1)
|
||||
- AFNetworking/Security (4.0.1)
|
||||
- AFNetworking/Serialization (4.0.1)
|
||||
- AFNetworking/UIKit (4.0.1):
|
||||
- AFNetworking/NSURLSession
|
||||
- CocoaLumberjack (3.7.4):
|
||||
- CocoaLumberjack/Core (= 3.7.4)
|
||||
- CocoaLumberjack/Core (3.7.4)
|
||||
|
@ -139,7 +124,6 @@ PODS:
|
|||
- ZXingObjC/All (3.6.5)
|
||||
|
||||
DEPENDENCIES:
|
||||
- AFNetworking
|
||||
- CryptoSwift
|
||||
- Curve25519Kit (from `https://github.com/oxen-io/session-ios-curve-25519-kit.git`, branch `session-version`)
|
||||
- DifferenceKit
|
||||
|
@ -163,7 +147,6 @@ DEPENDENCIES:
|
|||
|
||||
SPEC REPOS:
|
||||
https://github.com/CocoaPods/Specs.git:
|
||||
- AFNetworking
|
||||
- CocoaLumberjack
|
||||
- CryptoSwift
|
||||
- DifferenceKit
|
||||
|
@ -217,7 +200,6 @@ CHECKOUT OPTIONS:
|
|||
:git: https://github.com/signalapp/YYImage
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
AFNetworking: 7864c38297c79aaca1500c33288e429c3451fdce
|
||||
CocoaLumberjack: 543c79c114dadc3b1aba95641d8738b06b05b646
|
||||
CryptoSwift: a532e74ed010f8c95f611d00b8bbae42e9fe7c17
|
||||
Curve25519Kit: e63f9859ede02438ae3defc5e1a87e09d1ec7ee6
|
||||
|
@ -242,6 +224,6 @@ SPEC CHECKSUMS:
|
|||
YYImage: f1ddd15ac032a58b78bbed1e012b50302d318331
|
||||
ZXingObjC: fdbb269f25dd2032da343e06f10224d62f537bdb
|
||||
|
||||
PODFILE CHECKSUM: 7452ce88370eadd58d21fdf6a4c4945d6554ee95
|
||||
PODFILE CHECKSUM: ce9209e5c7ea252b767ee08075d4e4f8b49e487b
|
||||
|
||||
COCOAPODS: 1.11.3
|
||||
|
|
|
@ -1724,7 +1724,6 @@
|
|||
FD245C612850664300B966DD /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
|
||||
FD28A4F527EAD44C00FF65E7 /* Storage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Storage.swift; sourceTree = "<group>"; };
|
||||
FD2AAAEF28ED57B500A49611 /* SynchronousStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SynchronousStorage.swift; sourceTree = "<group>"; };
|
||||
FD2AAAF328EE882B00A49611 /* HTTPError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPError.swift; sourceTree = "<group>"; };
|
||||
FD37E9C228A1C6F3003AE748 /* ThemeManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeManager.swift; sourceTree = "<group>"; };
|
||||
FD37E9C528A1D4EC003AE748 /* Theme+ClassicDark.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Theme+ClassicDark.swift"; sourceTree = "<group>"; };
|
||||
FD37E9C728A1D73F003AE748 /* Theme+Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Theme+Colors.swift"; sourceTree = "<group>"; };
|
||||
|
@ -1753,7 +1752,6 @@
|
|||
FD37EA1428AB42CB003AE748 /* IdentitySpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentitySpec.swift; sourceTree = "<group>"; };
|
||||
FD37EA1628AC5605003AE748 /* NotificationContentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationContentViewModel.swift; sourceTree = "<group>"; };
|
||||
FD37EA1828AC5CCA003AE748 /* NotificationSoundViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationSoundViewModel.swift; sourceTree = "<group>"; };
|
||||
FD37EA1A28ACB51F003AE748 /* _007_HomeQueryOptimisationIndexes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _007_HomeQueryOptimisationIndexes.swift; sourceTree = "<group>"; };
|
||||
FD37F5572908F5C3005A5E92 /* RemoveUsersModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoveUsersModal.swift; sourceTree = "<group>"; };
|
||||
FD37F559290F9E9A005A5E92 /* GroupMembersViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupMembersViewModel.swift; sourceTree = "<group>"; };
|
||||
FD37F55F291867A8005A5E92 /* ImagePickerHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePickerHandler.swift; sourceTree = "<group>"; };
|
||||
|
|
|
@ -4,7 +4,6 @@ import Foundation
|
|||
import CallKit
|
||||
import GRDB
|
||||
import WebRTC
|
||||
import PromiseKit
|
||||
import SignalUtilitiesKit
|
||||
import SessionMessagingKit
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
import UIKit
|
||||
import GRDB
|
||||
import DifferenceKit
|
||||
import PromiseKit
|
||||
import SessionUIKit
|
||||
import SessionMessagingKit
|
||||
import SignalUtilitiesKit
|
||||
|
@ -317,34 +316,39 @@ final class NewClosedGroupVC: BaseVC, UITableViewDataSource, UITableViewDelegate
|
|||
let message: String? = (selectedContacts.count > 20 ? "GROUP_CREATION_PLEASE_WAIT".localized() : nil)
|
||||
ModalActivityIndicatorViewController.present(fromViewController: navigationController!, message: message) { [weak self] _ in
|
||||
Storage.shared
|
||||
.writeAsync { db in
|
||||
try MessageSender.createClosedGroup(db, name: name, members: selectedContacts)
|
||||
.writePublisherFlatMap { db in
|
||||
MessageSender.createClosedGroup(db, name: name, members: selectedContacts)
|
||||
}
|
||||
.done(on: DispatchQueue.main) { thread in
|
||||
Storage.shared.writeAsync { db in
|
||||
try? MessageSender
|
||||
.syncConfiguration(db, forceSyncNow: true)
|
||||
.sinkUntilComplete()
|
||||
.sinkUntilComplete(
|
||||
receiveCompletion: { result in
|
||||
switch result {
|
||||
case .finished: break
|
||||
case .failure:
|
||||
self?.dismiss(animated: true, completion: nil) // Dismiss the loader
|
||||
|
||||
let modal: ConfirmationModal = ConfirmationModal(
|
||||
targetView: self?.view,
|
||||
info: ConfirmationModal.Info(
|
||||
title: "GROUP_CREATION_ERROR_TITLE".localized(),
|
||||
explanation: "GROUP_CREATION_ERROR_MESSAGE".localized(),
|
||||
cancelTitle: "BUTTON_OK".localized(),
|
||||
cancelStyle: .alert_text
|
||||
)
|
||||
)
|
||||
self?.present(modal, animated: true)
|
||||
}
|
||||
},
|
||||
receiveValue: { thread in
|
||||
Storage.shared.writeAsync { db in
|
||||
try? MessageSender
|
||||
.syncConfiguration(db, forceSyncNow: true)
|
||||
.sinkUntilComplete()
|
||||
}
|
||||
|
||||
self?.presentingViewController?.dismiss(animated: true, completion: nil)
|
||||
SessionApp.presentConversation(for: thread.id, action: .compose, animated: false)
|
||||
}
|
||||
|
||||
self?.presentingViewController?.dismiss(animated: true, completion: nil)
|
||||
SessionApp.presentConversation(for: thread.id, action: .compose, animated: false)
|
||||
}
|
||||
.catch(on: DispatchQueue.main) { [weak self] _ in
|
||||
self?.dismiss(animated: true, completion: nil) // Dismiss the loader
|
||||
|
||||
let modal: ConfirmationModal = ConfirmationModal(
|
||||
targetView: self?.view,
|
||||
info: ConfirmationModal.Info(
|
||||
title: "GROUP_CREATION_ERROR_TITLE".localized(),
|
||||
explanation: "GROUP_CREATION_ERROR_MESSAGE".localized(),
|
||||
cancelTitle: "BUTTON_OK".localized(),
|
||||
cancelStyle: .alert_text
|
||||
)
|
||||
)
|
||||
self?.present(modal, animated: true)
|
||||
}
|
||||
.retainUntilComplete()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import UIKit
|
||||
import Combine
|
||||
import SessionUIKit
|
||||
import SessionMessagingKit
|
||||
|
||||
|
@ -9,6 +10,7 @@ final class InputView: UIView, InputViewButtonDelegate, InputTextViewDelegate, M
|
|||
|
||||
private static let linkPreviewViewInset: CGFloat = 6
|
||||
|
||||
private var disposables: Set<AnyCancellable> = Set()
|
||||
private let threadVariant: SessionThread.Variant
|
||||
private weak var delegate: InputViewDelegate?
|
||||
|
||||
|
@ -326,19 +328,26 @@ final class InputView: UIView, InputViewButtonDelegate, InputTextViewDelegate, M
|
|||
|
||||
// Build the link preview
|
||||
LinkPreview.tryToBuildPreviewInfo(previewUrl: linkPreviewURL)
|
||||
.done { [weak self] draft in
|
||||
guard self?.linkPreviewInfo?.url == linkPreviewURL else { return } // Obsolete
|
||||
|
||||
self?.linkPreviewInfo = (url: linkPreviewURL, draft: draft)
|
||||
self?.linkPreviewView.update(with: LinkPreview.DraftState(linkPreviewDraft: draft), isOutgoing: false)
|
||||
}
|
||||
.catch { [weak self] _ in
|
||||
guard self?.linkPreviewInfo?.url == linkPreviewURL else { return } // Obsolete
|
||||
|
||||
self?.linkPreviewInfo = nil
|
||||
self?.additionalContentContainer.subviews.forEach { $0.removeFromSuperview() }
|
||||
}
|
||||
.retainUntilComplete()
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink(
|
||||
receiveCompletion: { [weak self] result in
|
||||
switch result {
|
||||
case .finished: break
|
||||
case .failure:
|
||||
guard self?.linkPreviewInfo?.url == linkPreviewURL else { return } // Obsolete
|
||||
|
||||
self?.linkPreviewInfo = nil
|
||||
self?.additionalContentContainer.subviews.forEach { $0.removeFromSuperview() }
|
||||
}
|
||||
},
|
||||
receiveValue: { [weak self] draft in
|
||||
guard self?.linkPreviewInfo?.url == linkPreviewURL else { return } // Obsolete
|
||||
|
||||
self?.linkPreviewInfo = (url: linkPreviewURL, draft: draft)
|
||||
self?.linkPreviewView.update(with: LinkPreview.DraftState(linkPreviewDraft: draft), isOutgoing: false)
|
||||
}
|
||||
)
|
||||
.store(in: &disposables)
|
||||
}
|
||||
|
||||
func setEnabledMessageTypes(_ messageTypes: MessageInputTypes, message: String?) {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import UIKit
|
||||
import GRDB
|
||||
import PromiseKit
|
||||
import SessionUIKit
|
||||
import SessionMessagingKit
|
||||
|
||||
|
|
|
@ -184,44 +184,50 @@ final class NewDMVC: BaseVC, UIPageViewControllerDataSource, UIPageViewControlle
|
|||
.present(fromViewController: navigationController!, canCancel: false) { [weak self] modalActivityIndicator in
|
||||
SnodeAPI
|
||||
.getSessionID(for: onsNameOrPublicKey)
|
||||
.done { sessionID in
|
||||
modalActivityIndicator.dismiss {
|
||||
self?.startNewDM(with: sessionID)
|
||||
}
|
||||
}
|
||||
.catch { error in
|
||||
modalActivityIndicator.dismiss {
|
||||
var messageOrNil: String?
|
||||
if let error = error as? SnodeAPIError {
|
||||
switch error {
|
||||
case .decryptionFailed, .hashingFailed, .validationFailed:
|
||||
messageOrNil = error.errorDescription
|
||||
default: break
|
||||
}
|
||||
.sinkUntilComplete(
|
||||
receiveCompletion: { result in
|
||||
switch result {
|
||||
case .finished: break
|
||||
case .failure(let error):
|
||||
modalActivityIndicator.dismiss {
|
||||
var messageOrNil: String?
|
||||
if let error = error as? SnodeAPIError {
|
||||
switch error {
|
||||
case .decryptionFailed, .hashingFailed, .validationFailed:
|
||||
messageOrNil = error.errorDescription
|
||||
default: break
|
||||
}
|
||||
}
|
||||
let message: String = {
|
||||
if let messageOrNil: String = messageOrNil {
|
||||
return messageOrNil
|
||||
}
|
||||
|
||||
return (maybeSessionId?.prefix == .blinded ?
|
||||
"DM_ERROR_DIRECT_BLINDED_ID".localized() :
|
||||
"DM_ERROR_INVALID".localized()
|
||||
)
|
||||
}()
|
||||
|
||||
let modal: ConfirmationModal = ConfirmationModal(
|
||||
targetView: self?.view,
|
||||
info: ConfirmationModal.Info(
|
||||
title: "ALERT_ERROR_TITLE".localized(),
|
||||
explanation: message,
|
||||
cancelTitle: "BUTTON_OK".localized(),
|
||||
cancelStyle: .alert_text
|
||||
)
|
||||
)
|
||||
self?.present(modal, animated: true)
|
||||
}
|
||||
}
|
||||
},
|
||||
receiveValue: { sessionId in
|
||||
modalActivityIndicator.dismiss {
|
||||
self?.startNewDM(with: sessionId)
|
||||
}
|
||||
let message: String = {
|
||||
if let messageOrNil: String = messageOrNil {
|
||||
return messageOrNil
|
||||
}
|
||||
|
||||
return (maybeSessionId?.prefix == .blinded ?
|
||||
"DM_ERROR_DIRECT_BLINDED_ID".localized() :
|
||||
"DM_ERROR_INVALID".localized()
|
||||
)
|
||||
}()
|
||||
|
||||
let modal: ConfirmationModal = ConfirmationModal(
|
||||
targetView: self?.view,
|
||||
info: ConfirmationModal.Info(
|
||||
title: "ALERT_ERROR_TITLE".localized(),
|
||||
explanation: message,
|
||||
cancelTitle: "BUTTON_OK".localized(),
|
||||
cancelStyle: .alert_text
|
||||
)
|
||||
)
|
||||
self?.present(modal, animated: true)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
//
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import PromiseKit
|
||||
import SignalUtilitiesKit
|
||||
import SignalUtilitiesKit
|
||||
import Combine
|
||||
import YYImage
|
||||
import SignalCoreKit
|
||||
import SignalUtilitiesKit
|
||||
|
||||
class GifPickerCell: UICollectionViewCell {
|
||||
|
||||
|
@ -245,29 +241,27 @@ class GifPickerCell: UICollectionViewCell {
|
|||
}
|
||||
}
|
||||
|
||||
public func requestRenditionForSending() -> Promise<ProxiedContentAsset> {
|
||||
public func requestRenditionForSending() -> AnyPublisher<ProxiedContentAsset, Error> {
|
||||
guard let renditionForSending = self.renditionForSending else {
|
||||
owsFailDebug("renditionForSending was unexpectedly nil")
|
||||
return Promise(error: GiphyError.assertionError(description: "renditionForSending was unexpectedly nil"))
|
||||
return Fail(error: GiphyError.assertionError(description: "renditionForSending was unexpectedly nil"))
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
let (promise, resolver) = Promise<ProxiedContentAsset>.pending()
|
||||
|
||||
// We don't retain a handle on the asset request, since there will only ever
|
||||
// be one selected asset, and we never want to cancel it.
|
||||
_ = GiphyDownloader.giphyDownloader.requestAsset(assetDescription: renditionForSending,
|
||||
priority: .high,
|
||||
success: { _, asset in
|
||||
resolver.fulfill(asset)
|
||||
},
|
||||
failure: { _ in
|
||||
// TODO GiphyDownloader API should pass through a useful failing error
|
||||
// so we can pass it through here
|
||||
Logger.error("request failed")
|
||||
resolver.reject(GiphyError.fetchFailure)
|
||||
})
|
||||
|
||||
return promise
|
||||
return GiphyDownloader.giphyDownloader
|
||||
.requestAsset(
|
||||
assetDescription: renditionForSending,
|
||||
priority: .high
|
||||
)
|
||||
.mapError { _ -> Error in
|
||||
// TODO: GiphyDownloader API should pass through a useful failing error so we can pass it through here
|
||||
Logger.error("request failed")
|
||||
return GiphyError.fetchFailure
|
||||
}
|
||||
.map { asset, _ in asset }
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
private func clearViewState() {
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
//
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import Reachability
|
||||
import SignalUtilitiesKit
|
||||
import PromiseKit
|
||||
import SessionUIKit
|
||||
import SignalCoreKit
|
||||
|
||||
|
@ -43,6 +41,8 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|||
private let kCellReuseIdentifier = "kCellReuseIdentifier"
|
||||
|
||||
var progressiveSearchTimer: Timer?
|
||||
|
||||
private var disposables: Set<AnyCancellable> = Set()
|
||||
|
||||
// MARK: - Initialization
|
||||
|
||||
|
@ -360,47 +360,52 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|||
|
||||
public func getFileForCell(_ cell: GifPickerCell) {
|
||||
GiphyDownloader.giphyDownloader.cancelAllRequests()
|
||||
|
||||
firstly {
|
||||
cell.requestRenditionForSending()
|
||||
}.done { [weak self] (asset: ProxiedContentAsset) in
|
||||
guard let strongSelf = self else {
|
||||
Logger.info("ignoring send, since VC was dismissed before fetching finished.")
|
||||
return
|
||||
}
|
||||
guard let rendition = asset.assetDescription as? GiphyRendition else {
|
||||
owsFailDebug("Invalid asset description.")
|
||||
return
|
||||
}
|
||||
|
||||
let filePath = asset.filePath
|
||||
guard let dataSource = DataSourcePath.dataSource(withFilePath: filePath,
|
||||
shouldDeleteOnDeallocation: false) else {
|
||||
owsFailDebug("couldn't load asset.")
|
||||
return
|
||||
}
|
||||
let attachment = SignalAttachment.attachment(dataSource: dataSource, dataUTI: rendition.utiType, imageQuality: .medium)
|
||||
|
||||
strongSelf.dismiss(animated: true) {
|
||||
// Delegate presents view controllers, so it's important that *this* controller be dismissed before that occurs.
|
||||
strongSelf.delegate?.gifPickerDidSelect(attachment: attachment)
|
||||
}
|
||||
}.catch { [weak self] error in
|
||||
let modal: ConfirmationModal = ConfirmationModal(
|
||||
targetView: self?.view,
|
||||
info: ConfirmationModal.Info(
|
||||
title: "GIF_PICKER_FAILURE_ALERT_TITLE".localized(),
|
||||
explanation: error.localizedDescription,
|
||||
confirmTitle: CommonStrings.retryButton,
|
||||
cancelTitle: CommonStrings.dismissButton,
|
||||
cancelStyle: .alert_text,
|
||||
onConfirm: { _ in
|
||||
self?.getFileForCell(cell)
|
||||
|
||||
cell
|
||||
.requestRenditionForSending()
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink(
|
||||
receiveCompletion: { [weak self] result in
|
||||
switch result {
|
||||
case .finished: break
|
||||
case .failure(let error):
|
||||
let modal: ConfirmationModal = ConfirmationModal(
|
||||
targetView: self?.view,
|
||||
info: ConfirmationModal.Info(
|
||||
title: "GIF_PICKER_FAILURE_ALERT_TITLE".localized(),
|
||||
explanation: error.localizedDescription,
|
||||
confirmTitle: CommonStrings.retryButton,
|
||||
cancelTitle: CommonStrings.dismissButton,
|
||||
cancelStyle: .alert_text,
|
||||
onConfirm: { _ in
|
||||
self?.getFileForCell(cell)
|
||||
}
|
||||
)
|
||||
)
|
||||
self?.present(modal, animated: true)
|
||||
}
|
||||
)
|
||||
},
|
||||
receiveValue: { [weak self] asset in
|
||||
guard let rendition = asset.assetDescription as? GiphyRendition else {
|
||||
owsFailDebug("Invalid asset description.")
|
||||
return
|
||||
}
|
||||
|
||||
let filePath = asset.filePath
|
||||
guard let dataSource = DataSourcePath.dataSource(withFilePath: filePath,
|
||||
shouldDeleteOnDeallocation: false) else {
|
||||
owsFailDebug("couldn't load asset.")
|
||||
return
|
||||
}
|
||||
let attachment = SignalAttachment.attachment(dataSource: dataSource, dataUTI: rendition.utiType, imageQuality: .medium)
|
||||
|
||||
self?.dismiss(animated: true) {
|
||||
// Delegate presents view controllers, so it's important that *this* controller be dismissed before that occurs.
|
||||
self?.delegate?.gifPickerDidSelect(attachment: attachment)
|
||||
}
|
||||
}
|
||||
)
|
||||
self?.present(modal, animated: true)
|
||||
}.retainUntilComplete()
|
||||
.store(in: &disposables)
|
||||
}
|
||||
|
||||
public func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
|
||||
|
@ -487,22 +492,30 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|||
assert(progressiveSearchTimer == nil)
|
||||
assert(searchBar.text == nil || searchBar.text?.count == 0)
|
||||
|
||||
GiphyAPI.sharedInstance.trending()
|
||||
.done { [weak self] imageInfos in
|
||||
Logger.info("showing trending")
|
||||
|
||||
if imageInfos.count > 0 {
|
||||
self?.imageInfos = imageInfos
|
||||
self?.viewMode = .results
|
||||
GiphyAPI.trending()
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink(
|
||||
receiveCompletion: { result in
|
||||
switch result {
|
||||
case .finished: break
|
||||
case .failure(let error):
|
||||
// Don't both showing error UI feedback for default "trending" results.
|
||||
Logger.error("error: \(error)")
|
||||
}
|
||||
},
|
||||
receiveValue: { [weak self] imageInfos in
|
||||
Logger.info("showing trending")
|
||||
|
||||
if imageInfos.count > 0 {
|
||||
self?.imageInfos = imageInfos
|
||||
self?.viewMode = .results
|
||||
}
|
||||
else {
|
||||
owsFailDebug("trending results was unexpectedly empty")
|
||||
}
|
||||
}
|
||||
else {
|
||||
owsFailDebug("trending results was unexpectedly empty")
|
||||
}
|
||||
}
|
||||
.catch { error in
|
||||
// Don't both showing error UI feedback for default "trending" results.
|
||||
Logger.error("error: \(error)")
|
||||
}
|
||||
)
|
||||
.store(in: &disposables)
|
||||
}
|
||||
|
||||
private func search(query: String) {
|
||||
|
@ -515,10 +528,20 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|||
lastQuery = query
|
||||
self.collectionView.contentOffset = CGPoint.zero
|
||||
|
||||
GiphyAPI.sharedInstance
|
||||
.search(
|
||||
query: query,
|
||||
success: { [weak self] imageInfos in
|
||||
GiphyAPI
|
||||
.search(query: query)
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink(
|
||||
receiveCompletion: { [weak self] result in
|
||||
switch result {
|
||||
case .finished: break
|
||||
case .failure:
|
||||
Logger.info("search failed.")
|
||||
// TODO: Present this error to the user.
|
||||
self?.viewMode = .error
|
||||
}
|
||||
},
|
||||
receiveValue: { [weak self] imageInfos in
|
||||
Logger.info("search complete")
|
||||
self?.imageInfos = imageInfos
|
||||
|
||||
|
@ -528,13 +551,9 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
|||
else {
|
||||
self?.viewMode = .noResults
|
||||
}
|
||||
},
|
||||
failure: { [weak self] _ in
|
||||
Logger.info("search failed.")
|
||||
// TODO: Present this error to the user.
|
||||
self?.viewMode = .error
|
||||
}
|
||||
)
|
||||
.store(in: &disposables)
|
||||
}
|
||||
|
||||
// MARK: - GifPickerLayoutDelegate
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import AFNetworking
|
||||
import Foundation
|
||||
import PromiseKit
|
||||
import Combine
|
||||
import CoreServices
|
||||
import SignalCoreKit
|
||||
import SessionUtilitiesKit
|
||||
|
||||
// There's no UTI type for webp!
|
||||
enum GiphyFormat {
|
||||
|
@ -15,13 +14,12 @@ enum GiphyError: Error {
|
|||
case assertionError(description: String)
|
||||
case fetchFailure
|
||||
}
|
||||
|
||||
extension GiphyError: LocalizedError {
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .assertionError:
|
||||
return NSLocalizedString("GIF_PICKER_ERROR_GENERIC", comment: "Generic error displayed when picking a GIF")
|
||||
case .fetchFailure:
|
||||
return NSLocalizedString("GIF_PICKER_ERROR_FETCH_FAILURE", comment: "Error displayed when there is a failure fetching a GIF from the remote service.")
|
||||
case .assertionError: return "GIF_PICKER_ERROR_GENERIC".localized()
|
||||
case .fetchFailure: return "GIF_PICKER_ERROR_FETCH_FAILURE".localized()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +29,7 @@ extension GiphyError: LocalizedError {
|
|||
// They vary in content size (i.e. width, height),
|
||||
// format (.jpg, .gif, .mp4, webp, etc.),
|
||||
// quality, etc.
|
||||
@objc class GiphyRendition: ProxiedContentAssetDescription {
|
||||
class GiphyRendition: ProxiedContentAssetDescription {
|
||||
let format: GiphyFormat
|
||||
let name: String
|
||||
let width: UInt
|
||||
|
@ -90,7 +88,7 @@ extension GiphyError: LocalizedError {
|
|||
}
|
||||
|
||||
// Represents a single Giphy image.
|
||||
@objc class GiphyImageInfo: NSObject {
|
||||
class GiphyImageInfo: NSObject {
|
||||
let giphyId: String
|
||||
let renditions: [GiphyRendition]
|
||||
// We special-case the "original" rendition because it is the
|
||||
|
@ -264,115 +262,114 @@ extension GiphyError: LocalizedError {
|
|||
}
|
||||
}
|
||||
|
||||
@objc class GiphyAPI: NSObject {
|
||||
enum GiphyAPI {
|
||||
private static let kGiphyBaseURL = "https://api.giphy.com"
|
||||
private static let urlSession: URLSession = {
|
||||
let configuration: URLSessionConfiguration = ContentProxy.sessionConfiguration()
|
||||
|
||||
// Don't use any caching to protect privacy of these requests.
|
||||
configuration.urlCache = nil
|
||||
configuration.requestCachePolicy = .reloadIgnoringCacheData
|
||||
|
||||
return URLSession(configuration: configuration)
|
||||
}()
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
static let sharedInstance = GiphyAPI()
|
||||
|
||||
// Force usage as a singleton
|
||||
override private init() {
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
private let kGiphyBaseURL = "https://api.giphy.com/"
|
||||
|
||||
private func giphyAPISessionManager() -> AFHTTPSessionManager? {
|
||||
return AFHTTPSessionManager(baseURL: URL(string: kGiphyBaseURL), sessionConfiguration: .ephemeral)
|
||||
}
|
||||
|
||||
// MARK: Search
|
||||
// This is the Signal iOS API key.
|
||||
let kGiphyApiKey = "ZsUpUm2L6cVbvei347EQNp7HrROjbOdc"
|
||||
let kGiphyPageSize = 20
|
||||
// MARK: - Search
|
||||
|
||||
public func trending() -> Promise<[GiphyImageInfo]> {
|
||||
guard let sessionManager = giphyAPISessionManager() else {
|
||||
Logger.error("Couldn't create session manager.")
|
||||
return Promise.value([])
|
||||
}
|
||||
// This is the Signal iOS API key.
|
||||
private static let kGiphyApiKey = "ZsUpUm2L6cVbvei347EQNp7HrROjbOdc"
|
||||
private static let kGiphyPageSize = 20
|
||||
|
||||
public static func trending() -> AnyPublisher<[GiphyImageInfo], Error> {
|
||||
let urlString = "/v1/gifs/trending?api_key=\(kGiphyApiKey)&limit=\(kGiphyPageSize)"
|
||||
let (promise, resolver) = Promise<[GiphyImageInfo]>.pending()
|
||||
sessionManager.get(urlString,
|
||||
parameters: [String: AnyObject](),
|
||||
headers:nil,
|
||||
progress: nil,
|
||||
success: { _, value in
|
||||
Logger.error("search request succeeded")
|
||||
if let imageInfos = self.parseGiphyImages(responseJson: value) {
|
||||
resolver.fulfill(imageInfos)
|
||||
} else {
|
||||
Logger.error("unable to parse trending images")
|
||||
resolver.fulfill([])
|
||||
}
|
||||
|
||||
},
|
||||
failure: { _, error in
|
||||
Logger.error("search request failed: \(error)")
|
||||
resolver.reject(error)
|
||||
})
|
||||
|
||||
return promise
|
||||
|
||||
guard let url: URL = URL(string: "\(kGiphyBaseURL)\(urlString)") else {
|
||||
return Fail(error: HTTPError.invalidURL)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
return urlSession
|
||||
.dataTaskPublisher(for: url)
|
||||
.subscribe(on: DispatchQueue.global(qos: .userInitiated))
|
||||
.mapError { urlError in
|
||||
Logger.error("search request failed: \(urlError)")
|
||||
|
||||
// URLError codes are negative values
|
||||
return HTTPError.generic
|
||||
}
|
||||
.map { data, _ in
|
||||
Logger.error("search request succeeded")
|
||||
|
||||
guard let imageInfos = self.parseGiphyImages(responseData: data) else {
|
||||
Logger.error("unable to parse trending images")
|
||||
return []
|
||||
}
|
||||
|
||||
return imageInfos
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
public func search(query: String, success: @escaping (([GiphyImageInfo]) -> Void), failure: @escaping ((NSError?) -> Void)) {
|
||||
guard let sessionManager = giphyAPISessionManager() else {
|
||||
Logger.error("Couldn't create session manager.")
|
||||
failure(nil)
|
||||
return
|
||||
}
|
||||
guard NSURL(string: kGiphyBaseURL) != nil else {
|
||||
Logger.error("Invalid base URL.")
|
||||
failure(nil)
|
||||
return
|
||||
}
|
||||
|
||||
public static func search(query: String) -> AnyPublisher<[GiphyImageInfo], Error> {
|
||||
let kGiphyPageOffset = 0
|
||||
guard let queryEncoded = query.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
|
||||
Logger.error("Could not URL encode query: \(query).")
|
||||
failure(nil)
|
||||
return
|
||||
|
||||
guard
|
||||
let queryEncoded = query.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed),
|
||||
let url: URL = URL(
|
||||
string: [
|
||||
kGiphyBaseURL,
|
||||
"/v1/gifs/search?api_key=\(kGiphyApiKey)",
|
||||
"&offset=\(kGiphyPageOffset)",
|
||||
"&limit=\(kGiphyPageSize)",
|
||||
"&q=\(queryEncoded)"
|
||||
].joined()
|
||||
)
|
||||
else {
|
||||
return Fail(error: HTTPError.invalidURL)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
let urlString = "/v1/gifs/search?api_key=\(kGiphyApiKey)&offset=\(kGiphyPageOffset)&limit=\(kGiphyPageSize)&q=\(queryEncoded)"
|
||||
|
||||
guard ContentProxy.configureSessionManager(sessionManager: sessionManager, forUrl: urlString) else {
|
||||
|
||||
var request: URLRequest = URLRequest(url: url)
|
||||
|
||||
guard ContentProxy.configureProxiedRequest(request: &request) else {
|
||||
owsFailDebug("Could not configure query: \(query).")
|
||||
failure(nil)
|
||||
return
|
||||
return Fail(error: HTTPError.generic)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
sessionManager.get(urlString,
|
||||
parameters: [String: AnyObject](),
|
||||
headers: nil,
|
||||
progress: nil,
|
||||
success: { _, value in
|
||||
Logger.error("search request succeeded")
|
||||
guard let imageInfos = self.parseGiphyImages(responseJson: value) else {
|
||||
failure(nil)
|
||||
return
|
||||
}
|
||||
success(imageInfos)
|
||||
},
|
||||
failure: { _, error in
|
||||
Logger.error("search request failed: \(error)")
|
||||
failure(error as NSError)
|
||||
})
|
||||
|
||||
return urlSession
|
||||
.dataTaskPublisher(for: request)
|
||||
.subscribe(on: DispatchQueue.global(qos: .userInitiated))
|
||||
.mapError { urlError in
|
||||
Logger.error("search request failed: \(urlError)")
|
||||
|
||||
// URLError codes are negative values
|
||||
return HTTPError.generic
|
||||
}
|
||||
.flatMap { data, _ -> AnyPublisher<[GiphyImageInfo], Error> in
|
||||
Logger.error("search request succeeded")
|
||||
|
||||
guard let imageInfos = self.parseGiphyImages(responseData: data) else {
|
||||
return Fail(error: HTTPError.invalidResponse)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
return Just(imageInfos)
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
// MARK: Parse API Responses
|
||||
// MARK: - Parse API Responses
|
||||
|
||||
private func parseGiphyImages(responseJson: Any?) -> [GiphyImageInfo]? {
|
||||
guard let responseJson = responseJson else {
|
||||
private static func parseGiphyImages(responseData: Data?) -> [GiphyImageInfo]? {
|
||||
guard let responseData: Data = responseData else {
|
||||
Logger.error("Missing response.")
|
||||
return nil
|
||||
}
|
||||
guard let responseDict = responseJson as? [String: Any] else {
|
||||
guard let responseDict: [String: Any] = try? JSONSerialization
|
||||
.jsonObject(with: responseData, options: [ .fragmentsAllowed ]) as? [String: Any] else {
|
||||
Logger.error("Invalid response.")
|
||||
return nil
|
||||
}
|
||||
|
@ -386,7 +383,7 @@ extension GiphyError: LocalizedError {
|
|||
}
|
||||
|
||||
// Giphy API results are often incomplete or malformed, so we need to be defensive.
|
||||
private func parseGiphyImage(imageDict: [String: Any]) -> GiphyImageInfo? {
|
||||
private static func parseGiphyImage(imageDict: [String: Any]) -> GiphyImageInfo? {
|
||||
guard let giphyId = imageDict["id"] as? String else {
|
||||
Logger.warn("Image dict missing id.")
|
||||
return nil
|
||||
|
@ -421,12 +418,14 @@ extension GiphyError: LocalizedError {
|
|||
return nil
|
||||
}
|
||||
|
||||
return GiphyImageInfo(giphyId: giphyId,
|
||||
renditions: renditions,
|
||||
originalRendition: originalRendition)
|
||||
return GiphyImageInfo(
|
||||
giphyId: giphyId,
|
||||
renditions: renditions,
|
||||
originalRendition: originalRendition
|
||||
)
|
||||
}
|
||||
|
||||
private func findOriginalRendition(renditions: [GiphyRendition]) -> GiphyRendition? {
|
||||
private static func findOriginalRendition(renditions: [GiphyRendition]) -> GiphyRendition? {
|
||||
for rendition in renditions where rendition.name == "original" {
|
||||
return rendition
|
||||
}
|
||||
|
@ -436,8 +435,10 @@ extension GiphyError: LocalizedError {
|
|||
// Giphy API results are often incomplete or malformed, so we need to be defensive.
|
||||
//
|
||||
// We should discard renditions which are missing or have invalid properties.
|
||||
private func parseGiphyRendition(renditionName: String,
|
||||
renditionDict: [String: Any]) -> GiphyRendition? {
|
||||
private static func parseGiphyRendition(
|
||||
renditionName: String,
|
||||
renditionDict: [String: Any]
|
||||
) -> GiphyRendition? {
|
||||
guard let width = parsePositiveUInt(dict: renditionDict, key: "width", typeName: "rendition") else {
|
||||
return nil
|
||||
}
|
||||
|
@ -485,7 +486,7 @@ extension GiphyError: LocalizedError {
|
|||
)
|
||||
}
|
||||
|
||||
private func parsePositiveUInt(dict: [String: Any], key: String, typeName: String) -> UInt? {
|
||||
private static func parsePositiveUInt(dict: [String: Any], key: String, typeName: String) -> UInt? {
|
||||
guard let value = dict[key] else {
|
||||
return nil
|
||||
}
|
||||
|
@ -502,7 +503,7 @@ extension GiphyError: LocalizedError {
|
|||
return parsedValue
|
||||
}
|
||||
|
||||
private func parseLenientUInt(dict: [String: Any], key: String) -> UInt {
|
||||
private static func parseLenientUInt(dict: [String: Any], key: String) -> UInt {
|
||||
let defaultValue = UInt(0)
|
||||
|
||||
guard let value = dict[key] else {
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
//
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import SignalUtilitiesKit
|
||||
|
||||
@objc
|
||||
public class GiphyDownloader: ProxiedContentDownloader {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
@objc
|
||||
public static let giphyDownloader = GiphyDownloader(downloadFolderName: "GIFs")
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
//
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import Photos
|
||||
import PromiseKit
|
||||
import SessionUIKit
|
||||
import SignalUtilitiesKit
|
||||
import SignalCoreKit
|
||||
|
@ -14,7 +12,7 @@ protocol ImagePickerGridControllerDelegate: AnyObject {
|
|||
func imagePickerDidCancel(_ imagePicker: ImagePickerGridController)
|
||||
|
||||
func imagePicker(_ imagePicker: ImagePickerGridController, isAssetSelected asset: PHAsset) -> Bool
|
||||
func imagePicker(_ imagePicker: ImagePickerGridController, didSelectAsset asset: PHAsset, attachmentPromise: Promise<SignalAttachment>)
|
||||
func imagePicker(_ imagePicker: ImagePickerGridController, didSelectAsset asset: PHAsset, attachmentPublisher: AnyPublisher<SignalAttachment, Error>)
|
||||
func imagePicker(_ imagePicker: ImagePickerGridController, didDeselectAsset asset: PHAsset)
|
||||
|
||||
var isInBatchSelectMode: Bool { get }
|
||||
|
@ -181,8 +179,11 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
|
|||
return
|
||||
}
|
||||
|
||||
let attachmentPromise: Promise<SignalAttachment> = photoCollectionContents.outgoingAttachment(for: asset)
|
||||
delegate.imagePicker(self, didSelectAsset: asset, attachmentPromise: attachmentPromise)
|
||||
delegate.imagePicker(
|
||||
self,
|
||||
didSelectAsset: asset,
|
||||
attachmentPublisher: photoCollectionContents.outgoingAttachment(for: asset)
|
||||
)
|
||||
collectionView.selectItem(at: indexPath, animated: true, scrollPosition: [])
|
||||
case .deselect:
|
||||
delegate.imagePicker(self, didDeselectAsset: asset)
|
||||
|
@ -492,8 +493,11 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
|
|||
}
|
||||
|
||||
let asset: PHAsset = photoCollectionContents.asset(at: indexPath.item)
|
||||
let attachmentPromise: Promise<SignalAttachment> = photoCollectionContents.outgoingAttachment(for: asset)
|
||||
delegate.imagePicker(self, didSelectAsset: asset, attachmentPromise: attachmentPromise)
|
||||
delegate.imagePicker(
|
||||
self,
|
||||
didSelectAsset: asset,
|
||||
attachmentPublisher: photoCollectionContents.outgoingAttachment(for: asset)
|
||||
)
|
||||
|
||||
if !delegate.isInBatchSelectMode {
|
||||
// Don't show "selected" badge unless we're in batch mode
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import UIKit
|
||||
import GRDB
|
||||
import PromiseKit
|
||||
import SessionUIKit
|
||||
import SessionMessagingKit
|
||||
import SignalUtilitiesKit
|
||||
|
@ -922,24 +921,17 @@ extension MediaGalleryViewModel.Item: GalleryRailItem {
|
|||
let imageView: UIImageView = UIImageView()
|
||||
imageView.contentMode = .scaleAspectFill
|
||||
|
||||
getRailImage()
|
||||
.map { [weak imageView] image in
|
||||
guard let imageView = imageView else { return }
|
||||
imageView.image = image
|
||||
}
|
||||
.retainUntilComplete()
|
||||
self.thumbnailImage { [weak imageView] image in
|
||||
imageView?.image = image
|
||||
}
|
||||
|
||||
return imageView
|
||||
}
|
||||
|
||||
public func getRailImage() -> Guarantee<UIImage> {
|
||||
return Guarantee<UIImage> { fulfill in
|
||||
self.thumbnailImage(async: { image in fulfill(image) })
|
||||
}
|
||||
}
|
||||
|
||||
public func isEqual(to other: GalleryRailItem?) -> Bool {
|
||||
guard let otherItem: MediaGalleryViewModel.Item = other as? MediaGalleryViewModel.Item else { return false }
|
||||
guard let otherItem: MediaGalleryViewModel.Item = other as? MediaGalleryViewModel.Item else {
|
||||
return false
|
||||
}
|
||||
|
||||
return (self == otherItem)
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import AVFoundation
|
||||
import PromiseKit
|
||||
import CoreServices
|
||||
import SignalCoreKit
|
||||
|
||||
|
@ -81,77 +81,113 @@ class PhotoCapture: NSObject {
|
|||
Environment.shared?.audioSession.endAudioActivity(recordingAudioActivity)
|
||||
}
|
||||
|
||||
func startCapture() -> Promise<Void> {
|
||||
return sessionQueue.async(.promise) { [weak self] in
|
||||
guard let self = self else { return }
|
||||
func startCapture() -> AnyPublisher<Void, Error> {
|
||||
return Just(())
|
||||
.subscribe(on: sessionQueue)
|
||||
.setFailureType(to: Error.self)
|
||||
.flatMap { [weak self] _ -> AnyPublisher<Void, Error> in
|
||||
self?.session.beginConfiguration()
|
||||
defer { self?.session.commitConfiguration() }
|
||||
|
||||
self.session.beginConfiguration()
|
||||
defer { self.session.commitConfiguration() }
|
||||
|
||||
try self.updateCurrentInput(position: .back)
|
||||
|
||||
guard let photoOutput = self.captureOutput.photoOutput else {
|
||||
throw PhotoCaptureError.initializationFailed
|
||||
}
|
||||
|
||||
guard self.session.canAddOutput(photoOutput) else {
|
||||
throw PhotoCaptureError.initializationFailed
|
||||
}
|
||||
|
||||
if let connection = photoOutput.connection(with: .video) {
|
||||
if connection.isVideoStabilizationSupported {
|
||||
connection.preferredVideoStabilizationMode = .auto
|
||||
do {
|
||||
try self?.updateCurrentInput(position: .back)
|
||||
}
|
||||
catch {
|
||||
return Fail(error: error)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
|
||||
self.session.addOutput(photoOutput)
|
||||
guard let photoOutput = self?.captureOutput.photoOutput else {
|
||||
return Fail(error: PhotoCaptureError.initializationFailed)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
let movieOutput = self.captureOutput.movieOutput
|
||||
guard self?.session.canAddOutput(photoOutput) == true else {
|
||||
return Fail(error: PhotoCaptureError.initializationFailed)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
if self.session.canAddOutput(movieOutput) {
|
||||
self.session.addOutput(movieOutput)
|
||||
self.session.sessionPreset = .high
|
||||
if let connection = movieOutput.connection(with: .video) {
|
||||
if let connection = photoOutput.connection(with: .video) {
|
||||
if connection.isVideoStabilizationSupported {
|
||||
connection.preferredVideoStabilizationMode = .auto
|
||||
}
|
||||
}
|
||||
|
||||
self?.session.addOutput(photoOutput)
|
||||
|
||||
if
|
||||
let movieOutput = self?.captureOutput.movieOutput,
|
||||
self?.session.canAddOutput(movieOutput) == true
|
||||
{
|
||||
self?.session.addOutput(movieOutput)
|
||||
self?.session.sessionPreset = .high
|
||||
|
||||
if let connection = movieOutput.connection(with: .video) {
|
||||
if connection.isVideoStabilizationSupported {
|
||||
connection.preferredVideoStabilizationMode = .auto
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Just(())
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
}.done(on: sessionQueue) {
|
||||
self.session.startRunning()
|
||||
}
|
||||
.handleEvents(
|
||||
receiveCompletion: { [weak self] result in
|
||||
switch result {
|
||||
case .failure: break
|
||||
case .finished: self?.session.startRunning()
|
||||
}
|
||||
}
|
||||
)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func stopCapture() -> Guarantee<Void> {
|
||||
return sessionQueue.async(.promise) {
|
||||
self.session.stopRunning()
|
||||
}
|
||||
func stopCapture() -> AnyPublisher<Void, Never> {
|
||||
return Just(())
|
||||
.subscribe(on: sessionQueue)
|
||||
.handleEvents(
|
||||
receiveOutput: { [weak self] in self?.session.stopRunning() }
|
||||
)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func assertIsOnSessionQueue() {
|
||||
assertOnQueue(sessionQueue)
|
||||
}
|
||||
|
||||
func switchCamera() -> Promise<Void> {
|
||||
func switchCamera() -> AnyPublisher<Void, Error> {
|
||||
AssertIsOnMainThread()
|
||||
let newPosition: AVCaptureDevice.Position
|
||||
switch desiredPosition {
|
||||
case .front:
|
||||
newPosition = .back
|
||||
case .back:
|
||||
newPosition = .front
|
||||
case .unspecified:
|
||||
newPosition = .front
|
||||
}
|
||||
desiredPosition = newPosition
|
||||
|
||||
return sessionQueue.async(.promise) { [weak self] in
|
||||
guard let self = self else { return }
|
||||
|
||||
self.session.beginConfiguration()
|
||||
defer { self.session.commitConfiguration() }
|
||||
try self.updateCurrentInput(position: newPosition)
|
||||
}
|
||||
desiredPosition = {
|
||||
switch desiredPosition {
|
||||
case .front: return .back
|
||||
case .back: return .front
|
||||
case .unspecified: return .front
|
||||
}
|
||||
}()
|
||||
|
||||
return Just(())
|
||||
.setFailureType(to: Error.self)
|
||||
.subscribe(on: sessionQueue)
|
||||
.flatMap { [weak self, newPosition = self.desiredPosition] _ -> AnyPublisher<Void, Error> in
|
||||
self?.session.beginConfiguration()
|
||||
defer { self?.session.commitConfiguration() }
|
||||
|
||||
do {
|
||||
try self?.updateCurrentInput(position: newPosition)
|
||||
}
|
||||
catch {
|
||||
return Fail(error: error)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
return Just(())
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
// This method should be called on the serial queue,
|
||||
|
@ -177,20 +213,29 @@ class PhotoCapture: NSObject {
|
|||
resetFocusAndExposure()
|
||||
}
|
||||
|
||||
func switchFlashMode() -> Guarantee<Void> {
|
||||
return sessionQueue.async(.promise) {
|
||||
switch self.captureOutput.flashMode {
|
||||
case .auto:
|
||||
Logger.debug("new flashMode: on")
|
||||
self.captureOutput.flashMode = .on
|
||||
case .on:
|
||||
Logger.debug("new flashMode: off")
|
||||
self.captureOutput.flashMode = .off
|
||||
case .off:
|
||||
Logger.debug("new flashMode: auto")
|
||||
self.captureOutput.flashMode = .auto
|
||||
}
|
||||
}
|
||||
func switchFlashMode() -> AnyPublisher<Void, Never> {
|
||||
return Just(())
|
||||
.subscribe(on: sessionQueue)
|
||||
.handleEvents(
|
||||
receiveOutput: { [weak self] _ in
|
||||
switch self?.captureOutput.flashMode {
|
||||
case .auto:
|
||||
Logger.debug("new flashMode: on")
|
||||
self?.captureOutput.flashMode = .on
|
||||
|
||||
case .on:
|
||||
Logger.debug("new flashMode: off")
|
||||
self?.captureOutput.flashMode = .off
|
||||
|
||||
case .off:
|
||||
Logger.debug("new flashMode: auto")
|
||||
self?.captureOutput.flashMode = .auto
|
||||
|
||||
default: break
|
||||
}
|
||||
}
|
||||
)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func focus(with focusMode: AVCaptureDevice.FocusMode,
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import UIKit
|
||||
import Combine
|
||||
import AVFoundation
|
||||
import PromiseKit
|
||||
import SessionUIKit
|
||||
import SignalUtilitiesKit
|
||||
import SignalCoreKit
|
||||
|
@ -40,9 +40,15 @@ class PhotoCaptureViewController: OWSViewController {
|
|||
deinit {
|
||||
UIDevice.current.endGeneratingDeviceOrientationNotifications()
|
||||
if let photoCapture = photoCapture {
|
||||
photoCapture.stopCapture().done {
|
||||
Logger.debug("stopCapture completed")
|
||||
}.retainUntilComplete()
|
||||
photoCapture.stopCapture()
|
||||
.sinkUntilComplete(
|
||||
receiveCompletion: { result in
|
||||
switch result {
|
||||
case .failure: break
|
||||
case .finished: Logger.debug("stopCapture completed")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,17 +193,29 @@ class PhotoCaptureViewController: OWSViewController {
|
|||
let epsilonToForceCounterClockwiseRotation: CGFloat = 0.00001
|
||||
self.switchCameraControl.button.transform = self.switchCameraControl.button.transform.rotate(.pi + epsilonToForceCounterClockwiseRotation)
|
||||
}
|
||||
photoCapture.switchCamera().catch { error in
|
||||
self.showFailureUI(error: error)
|
||||
}.retainUntilComplete()
|
||||
|
||||
photoCapture.switchCamera()
|
||||
.receiveOnMain()
|
||||
.sinkUntilComplete(
|
||||
receiveCompletion: { [weak self] result in
|
||||
switch result {
|
||||
case .finished: break
|
||||
case .failure(let error): self?.showFailureUI(error: error)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@objc
|
||||
func didTapFlashMode() {
|
||||
Logger.debug("")
|
||||
photoCapture.switchFlashMode().done {
|
||||
self.updateFlashModeControl()
|
||||
}.retainUntilComplete()
|
||||
photoCapture.switchFlashMode()
|
||||
.receiveOnMain()
|
||||
.sinkUntilComplete(
|
||||
receiveCompletion: { [weak self] _ in
|
||||
self?.updateFlashModeControl()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@objc
|
||||
|
@ -288,13 +306,15 @@ class PhotoCaptureViewController: OWSViewController {
|
|||
previewView = CapturePreviewView(session: photoCapture.session)
|
||||
|
||||
photoCapture.startCapture()
|
||||
.done { [weak self] in
|
||||
self?.showCaptureUI()
|
||||
}
|
||||
.catch { [weak self] error in
|
||||
self?.showFailureUI(error: error)
|
||||
}
|
||||
.retainUntilComplete()
|
||||
.receiveOnMain()
|
||||
.sinkUntilComplete(
|
||||
receiveCompletion: { [weak self] result in
|
||||
switch result {
|
||||
case .finished: self?.showCaptureUI()
|
||||
case .failure(let error): self?.showFailureUI(error: error)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private func showCaptureUI() {
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
//
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import Photos
|
||||
import PromiseKit
|
||||
import CoreServices
|
||||
import SignalUtilitiesKit
|
||||
import SignalCoreKit
|
||||
|
@ -138,44 +136,45 @@ class PhotoCollectionContents {
|
|||
_ = imageManager.requestImage(for: asset, targetSize: thumbnailSize, contentMode: .aspectFill, options: nil, resultHandler: resultHandler)
|
||||
}
|
||||
|
||||
private func requestImageDataSource(for asset: PHAsset) -> Promise<(dataSource: DataSource, dataUTI: String)> {
|
||||
return Promise { resolver in
|
||||
private func requestImageDataSource(for asset: PHAsset) -> AnyPublisher<(dataSource: DataSource, dataUTI: String), Error> {
|
||||
return Future { [weak self] resolver in
|
||||
|
||||
let options: PHImageRequestOptions = PHImageRequestOptions()
|
||||
options.isNetworkAccessAllowed = true
|
||||
|
||||
_ = imageManager.requestImageData(for: asset, options: options) { imageData, dataUTI, orientation, info in
|
||||
_ = self?.imageManager.requestImageData(for: asset, options: options) { imageData, dataUTI, orientation, info in
|
||||
|
||||
guard let imageData = imageData else {
|
||||
resolver.reject(PhotoLibraryError.assertionError(description: "imageData was unexpectedly nil"))
|
||||
resolver(Result.failure(PhotoLibraryError.assertionError(description: "imageData was unexpectedly nil")))
|
||||
return
|
||||
}
|
||||
|
||||
guard let dataUTI = dataUTI else {
|
||||
resolver.reject(PhotoLibraryError.assertionError(description: "dataUTI was unexpectedly nil"))
|
||||
resolver(Result.failure(PhotoLibraryError.assertionError(description: "dataUTI was unexpectedly nil")))
|
||||
return
|
||||
}
|
||||
|
||||
guard let dataSource = DataSourceValue.dataSource(with: imageData, utiType: dataUTI) else {
|
||||
resolver.reject(PhotoLibraryError.assertionError(description: "dataSource was unexpectedly nil"))
|
||||
resolver(Result.failure(PhotoLibraryError.assertionError(description: "dataSource was unexpectedly nil")))
|
||||
return
|
||||
}
|
||||
|
||||
resolver.fulfill((dataSource: dataSource, dataUTI: dataUTI))
|
||||
resolver(Result.success((dataSource: dataSource, dataUTI: dataUTI)))
|
||||
}
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
private func requestVideoDataSource(for asset: PHAsset) -> Promise<(dataSource: DataSource, dataUTI: String)> {
|
||||
return Promise { resolver in
|
||||
private func requestVideoDataSource(for asset: PHAsset) -> AnyPublisher<(dataSource: DataSource, dataUTI: String), Error> {
|
||||
return Future { [weak self] resolver in
|
||||
|
||||
let options: PHVideoRequestOptions = PHVideoRequestOptions()
|
||||
options.isNetworkAccessAllowed = true
|
||||
|
||||
_ = imageManager.requestExportSession(forVideo: asset, options: options, exportPreset: AVAssetExportPresetMediumQuality) { exportSession, foo in
|
||||
_ = self?.imageManager.requestExportSession(forVideo: asset, options: options, exportPreset: AVAssetExportPresetMediumQuality) { exportSession, foo in
|
||||
|
||||
guard let exportSession = exportSession else {
|
||||
resolver.reject(PhotoLibraryError.assertionError(description: "exportSession was unexpectedly nil"))
|
||||
resolver(Result.failure(PhotoLibraryError.assertionError(description: "exportSession was unexpectedly nil")))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -191,28 +190,38 @@ class PhotoCollectionContents {
|
|||
Logger.debug("Completed video export")
|
||||
|
||||
guard let dataSource = DataSourcePath.dataSource(with: exportURL, shouldDeleteOnDeallocation: true) else {
|
||||
resolver.reject(PhotoLibraryError.assertionError(description: "Failed to build data source for exported video URL"))
|
||||
resolver(Result.failure(PhotoLibraryError.assertionError(description: "Failed to build data source for exported video URL")))
|
||||
return
|
||||
}
|
||||
|
||||
resolver.fulfill((dataSource: dataSource, dataUTI: kUTTypeMPEG4 as String))
|
||||
resolver(Result.success((dataSource: dataSource, dataUTI: kUTTypeMPEG4 as String)))
|
||||
}
|
||||
}
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func outgoingAttachment(for asset: PHAsset) -> Promise<SignalAttachment> {
|
||||
func outgoingAttachment(for asset: PHAsset) -> AnyPublisher<SignalAttachment, Error> {
|
||||
switch asset.mediaType {
|
||||
case .image:
|
||||
return requestImageDataSource(for: asset).map { (dataSource: DataSource, dataUTI: String) in
|
||||
return SignalAttachment.attachment(dataSource: dataSource, dataUTI: dataUTI, imageQuality: .medium)
|
||||
}
|
||||
case .video:
|
||||
return requestVideoDataSource(for: asset).map { (dataSource: DataSource, dataUTI: String) in
|
||||
return SignalAttachment.attachment(dataSource: dataSource, dataUTI: dataUTI)
|
||||
}
|
||||
default:
|
||||
return Promise(error: PhotoLibraryError.unsupportedMediaType)
|
||||
case .image:
|
||||
return requestImageDataSource(for: asset)
|
||||
.map { (dataSource: DataSource, dataUTI: String) in
|
||||
SignalAttachment
|
||||
.attachment(dataSource: dataSource, dataUTI: dataUTI, imageQuality: .medium)
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
|
||||
case .video:
|
||||
return requestVideoDataSource(for: asset)
|
||||
.map { (dataSource: DataSource, dataUTI: String) in
|
||||
SignalAttachment
|
||||
.attachment(dataSource: dataSource, dataUTI: dataUTI)
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
|
||||
default:
|
||||
return Fail(error: PhotoLibraryError.unsupportedMediaType)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import UIKit
|
||||
import Combine
|
||||
import Photos
|
||||
import PromiseKit
|
||||
import SignalUtilitiesKit
|
||||
import SignalCoreKit
|
||||
|
||||
|
@ -16,6 +16,7 @@ class SendMediaNavigationController: UINavigationController {
|
|||
static let bottomButtonsCenterOffset: CGFloat = -50
|
||||
|
||||
private let threadId: String
|
||||
private var disposables: Set<AnyCancellable> = Set()
|
||||
|
||||
// MARK: - Initialization
|
||||
|
||||
|
@ -325,32 +326,40 @@ extension SendMediaNavigationController: ImagePickerGridControllerDelegate {
|
|||
func showApprovalAfterProcessingAnyMediaLibrarySelections() {
|
||||
let mediaLibrarySelections: [MediaLibrarySelection] = self.mediaLibrarySelections.orderedValues
|
||||
|
||||
let backgroundBlock: (ModalActivityIndicatorViewController) -> Void = { modal in
|
||||
let attachmentPromises: [Promise<MediaLibraryAttachment>] = mediaLibrarySelections.map { $0.promise }
|
||||
|
||||
when(fulfilled: attachmentPromises)
|
||||
.map { attachments in
|
||||
Logger.debug("built all attachments")
|
||||
modal.dismiss {
|
||||
self.attachmentDraftCollection.selectedFromPicker(attachments: attachments)
|
||||
self.pushApprovalViewController()
|
||||
let backgroundBlock: (ModalActivityIndicatorViewController) -> Void = { [weak self] modal in
|
||||
guard let strongSelf = self else { return }
|
||||
|
||||
Publishers
|
||||
.MergeMany(mediaLibrarySelections.map { $0.publisher })
|
||||
.collect()
|
||||
.sink(
|
||||
receiveCompletion: { result in
|
||||
switch result {
|
||||
case .finished: break
|
||||
case .failure(let error):
|
||||
Logger.error("failed to prepare attachments. error: \(error)")
|
||||
modal.dismiss { [weak self] in
|
||||
let modal: ConfirmationModal = ConfirmationModal(
|
||||
targetView: self?.view,
|
||||
info: ConfirmationModal.Info(
|
||||
title: "IMAGE_PICKER_FAILED_TO_PROCESS_ATTACHMENTS".localized(),
|
||||
cancelTitle: "BUTTON_OK".localized(),
|
||||
cancelStyle: .alert_text
|
||||
)
|
||||
)
|
||||
self?.present(modal, animated: true)
|
||||
}
|
||||
}
|
||||
},
|
||||
receiveValue: { attachments in
|
||||
Logger.debug("built all attachments")
|
||||
modal.dismiss {
|
||||
self?.attachmentDraftCollection.selectedFromPicker(attachments: attachments)
|
||||
self?.pushApprovalViewController()
|
||||
}
|
||||
}
|
||||
}
|
||||
.catch { error in
|
||||
Logger.error("failed to prepare attachments. error: \(error)")
|
||||
modal.dismiss { [weak self] in
|
||||
let modal: ConfirmationModal = ConfirmationModal(
|
||||
targetView: self?.view,
|
||||
info: ConfirmationModal.Info(
|
||||
title: "IMAGE_PICKER_FAILED_TO_PROCESS_ATTACHMENTS".localized(),
|
||||
cancelTitle: "BUTTON_OK".localized(),
|
||||
cancelStyle: .alert_text
|
||||
)
|
||||
)
|
||||
self?.present(modal, animated: true)
|
||||
}
|
||||
}
|
||||
.retainUntilComplete()
|
||||
)
|
||||
.store(in: &strongSelf.disposables)
|
||||
}
|
||||
|
||||
ModalActivityIndicatorViewController.present(
|
||||
|
@ -364,10 +373,13 @@ extension SendMediaNavigationController: ImagePickerGridControllerDelegate {
|
|||
return mediaLibrarySelections.hasValue(forKey: asset)
|
||||
}
|
||||
|
||||
func imagePicker(_ imagePicker: ImagePickerGridController, didSelectAsset asset: PHAsset, attachmentPromise: Promise<SignalAttachment>) {
|
||||
func imagePicker(_ imagePicker: ImagePickerGridController, didSelectAsset asset: PHAsset, attachmentPublisher: AnyPublisher<SignalAttachment, Error>) {
|
||||
guard !mediaLibrarySelections.hasValue(forKey: asset) else { return }
|
||||
|
||||
let libraryMedia = MediaLibrarySelection(asset: asset, signalAttachmentPromise: attachmentPromise)
|
||||
let libraryMedia = MediaLibrarySelection(
|
||||
asset: asset,
|
||||
signalAttachmentPublisher: attachmentPublisher
|
||||
)
|
||||
mediaLibrarySelections.append(key: asset, value: libraryMedia)
|
||||
updateButtons(topViewController: imagePicker)
|
||||
}
|
||||
|
@ -512,17 +524,17 @@ private final class AttachmentDraftCollection {
|
|||
|
||||
private struct MediaLibrarySelection: Hashable, Equatable {
|
||||
let asset: PHAsset
|
||||
let signalAttachmentPromise: Promise<SignalAttachment>
|
||||
let signalAttachmentPublisher: AnyPublisher<SignalAttachment, Error>
|
||||
|
||||
var hashValue: Int {
|
||||
return asset.hashValue
|
||||
}
|
||||
|
||||
var promise: Promise<MediaLibraryAttachment> {
|
||||
var publisher: AnyPublisher<MediaLibraryAttachment, Error> {
|
||||
let asset = self.asset
|
||||
return signalAttachmentPromise.map { signalAttachment in
|
||||
return MediaLibraryAttachment(asset: asset, signalAttachment: signalAttachment)
|
||||
}
|
||||
return signalAttachmentPublisher
|
||||
.map { MediaLibraryAttachment(asset: asset, signalAttachment: $0) }
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
static func ==(lhs: MediaLibrarySelection, rhs: MediaLibrarySelection) -> Bool {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import UIKit
|
||||
import PromiseKit
|
||||
|
||||
class MediaDismissAnimationController: NSObject {
|
||||
private let mediaItem: Media
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,5 +4,58 @@
|
|||
<dict>
|
||||
<key>StringsTable</key>
|
||||
<string>Root</string>
|
||||
<key>PreferenceSpecifiers</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
<key>Title</key>
|
||||
<string>Group</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Type</key>
|
||||
<string>PSTextFieldSpecifier</string>
|
||||
<key>Title</key>
|
||||
<string>Name</string>
|
||||
<key>Key</key>
|
||||
<string>name_preference</string>
|
||||
<key>DefaultValue</key>
|
||||
<string></string>
|
||||
<key>IsSecure</key>
|
||||
<false/>
|
||||
<key>KeyboardType</key>
|
||||
<string>Alphabet</string>
|
||||
<key>AutocapitalizationType</key>
|
||||
<string>None</string>
|
||||
<key>AutocorrectionType</key>
|
||||
<string>No</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Type</key>
|
||||
<string>PSToggleSwitchSpecifier</string>
|
||||
<key>Title</key>
|
||||
<string>Enabled</string>
|
||||
<key>Key</key>
|
||||
<string>enabled_preference</string>
|
||||
<key>DefaultValue</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>Type</key>
|
||||
<string>PSSliderSpecifier</string>
|
||||
<key>Key</key>
|
||||
<string>slider_preference</string>
|
||||
<key>DefaultValue</key>
|
||||
<real>0.5</real>
|
||||
<key>MinimumValue</key>
|
||||
<integer>0</integer>
|
||||
<key>MaximumValue</key>
|
||||
<integer>1</integer>
|
||||
<key>MinimumValueImage</key>
|
||||
<string></string>
|
||||
<key>MaximumValueImage</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,462 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>PreferenceSpecifiers</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>This application makes use of the following third party libraries:</string>
|
||||
<key>Title</key>
|
||||
<string>Acknowledgements</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2010-2021, Deusty, LLC
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of Deusty nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Deusty, LLC.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
</string>
|
||||
<key>Title</key>
|
||||
<string>CocoaLumberjack</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>Copyright (C) 2014-2017 Marcin Krzyżanowski <marcin.krzyzanowski@gmail.com>
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
|
||||
- The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation is required.
|
||||
- Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
- This notice may not be removed or altered from any source or binary distribution.
|
||||
- Redistributions of any form whatsoever must retain the following acknowledgment: 'This product includes software developed by the "Marcin Krzyzanowski" (http://krzyzanowskim.com/).'
|
||||
</string>
|
||||
<key>Title</key>
|
||||
<string>CryptoSwift</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>Copyright (C) 2015-2020 Gwendal Roué
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
</string>
|
||||
<key>Title</key>
|
||||
<string>GRDB.swift</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>Copyright 2016-present, Max Howell; mxcl@me.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
</string>
|
||||
<key>Title</key>
|
||||
<string>PromiseKit</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>Copyright (c) 2008, ZETETIC LLC
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the ZETETIC LLC nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY ZETETIC LLC ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL ZETETIC LLC BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
</string>
|
||||
<key>Title</key>
|
||||
<string>SQLCipher</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>
|
||||
Copyright 2012 Square Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
</string>
|
||||
<key>Title</key>
|
||||
<string>SocketRocket</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>ISC License
|
||||
|
||||
Copyright (c) 2014-2020, Frank Denis <j at pureftpd dot org>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
</string>
|
||||
<key>Title</key>
|
||||
<string>Sodium</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>Copyright (c) 2011, The WebRTC project authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
* Neither the name of Google nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
</string>
|
||||
<key>Title</key>
|
||||
<string>WebRTC-lib</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2013, yap.TV Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Neither the name of yap.TV nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior
|
||||
written permission of yap.TV Inc.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</string>
|
||||
<key>Title</key>
|
||||
<string>YapDatabase</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string> Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.</string>
|
||||
<key>Title</key>
|
||||
<string>DifferenceKit</string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>FooterText</key>
|
||||
<string>Generated by CocoaPods - https://cocoapods.org</string>
|
||||
<key>Title</key>
|
||||
<string></string>
|
||||
<key>Type</key>
|
||||
<string>PSGroupSpecifier</string>
|
||||
</dict>
|
||||
</array>
|
||||
<key>StringsTable</key>
|
||||
<string>Acknowledgements</string>
|
||||
<key>Title</key>
|
||||
<string>Acknowledgements</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>StringsTable</key>
|
||||
<string>Root</string>
|
||||
<key>PreferenceSpecifiers</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>Type</key>
|
||||
<string>Child Pane</string>
|
||||
<key>Title</key>
|
||||
<string>Acknowledgements</string>
|
||||
<key>Filename</key>
|
||||
<string>Acknowledgements.plist</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
Binary file not shown.
|
@ -1,9 +1,8 @@
|
|||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import GRDB
|
||||
import PromiseKit
|
||||
import AFNetworking
|
||||
import SignalCoreKit
|
||||
import SessionUtilitiesKit
|
||||
|
||||
|
@ -298,32 +297,45 @@ public extension LinkPreview {
|
|||
}
|
||||
}
|
||||
|
||||
static func tryToBuildPreviewInfo(previewUrl: String?) -> Promise<LinkPreviewDraft> {
|
||||
static func tryToBuildPreviewInfo(previewUrl: String?) -> AnyPublisher<LinkPreviewDraft, Error> {
|
||||
guard Storage.shared[.areLinkPreviewsEnabled] else {
|
||||
return Promise(error: LinkPreviewError.featureDisabled)
|
||||
return Fail(error: LinkPreviewError.featureDisabled)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
guard let previewUrl: String = previewUrl else {
|
||||
return Promise(error: LinkPreviewError.invalidInput)
|
||||
return Fail(error: LinkPreviewError.invalidInput)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
if let cachedInfo = cachedLinkPreview(forPreviewUrl: previewUrl) {
|
||||
return Promise.value(cachedInfo)
|
||||
return Just(cachedInfo)
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
return downloadLink(url: previewUrl)
|
||||
.then(on: DispatchQueue.global()) { data, response -> Promise<LinkPreviewDraft> in
|
||||
return parseLinkDataAndBuildDraft(linkData: data, response: response, linkUrlString: previewUrl)
|
||||
.flatMap { data, response in
|
||||
parseLinkDataAndBuildDraft(linkData: data, response: response, linkUrlString: previewUrl)
|
||||
}
|
||||
.then(on: DispatchQueue.global()) { linkPreviewDraft -> Promise<LinkPreviewDraft> in
|
||||
guard linkPreviewDraft.isValid() else { throw LinkPreviewError.noPreview }
|
||||
.flatMap { linkPreviewDraft -> AnyPublisher<LinkPreviewDraft, Error> in
|
||||
guard linkPreviewDraft.isValid() else {
|
||||
return Fail(error: LinkPreviewError.noPreview)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
setCachedLinkPreview(linkPreviewDraft, forPreviewUrl: previewUrl)
|
||||
|
||||
return Promise.value(linkPreviewDraft)
|
||||
return Just(linkPreviewDraft)
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
private static func downloadLink(url urlString: String, remainingRetries: UInt = 3) -> Promise<(Data, URLResponse)> {
|
||||
private static func downloadLink(
|
||||
url urlString: String,
|
||||
remainingRetries: UInt = 3
|
||||
) -> AnyPublisher<(Data, URLResponse), Error> {
|
||||
Logger.verbose("url: \(urlString)")
|
||||
|
||||
// let sessionConfiguration = ContentProxy.sessionConfiguration() // Loki: Signal's proxy appears to have been banned by YouTube
|
||||
|
@ -333,103 +345,103 @@ public extension LinkPreview {
|
|||
sessionConfiguration.requestCachePolicy = .reloadIgnoringLocalCacheData
|
||||
sessionConfiguration.urlCache = nil
|
||||
|
||||
// FIXME: Refactor to stop using AFHTTPRequest
|
||||
let sessionManager = AFHTTPSessionManager(baseURL: nil,
|
||||
sessionConfiguration: sessionConfiguration)
|
||||
sessionManager.requestSerializer = AFHTTPRequestSerializer()
|
||||
sessionManager.responseSerializer = AFHTTPResponseSerializer()
|
||||
|
||||
guard ContentProxy.configureSessionManager(sessionManager: sessionManager, forUrl: urlString) else {
|
||||
return Promise(error: LinkPreviewError.assertionFailure)
|
||||
guard
|
||||
var request: URLRequest = URL(string: urlString).map({ URLRequest(url: $0) }),
|
||||
ContentProxy.configureProxiedRequest(request: &request)
|
||||
else {
|
||||
return Fail(error: LinkPreviewError.assertionFailure)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
sessionManager.requestSerializer.setValue(self.userAgentString, forHTTPHeaderField: "User-Agent")
|
||||
request.setValue(self.userAgentString, forHTTPHeaderField: "User-Agent") // Set a fake value
|
||||
|
||||
let (promise, resolver) = Promise<(Data, URLResponse)>.pending()
|
||||
sessionManager.get(
|
||||
urlString,
|
||||
parameters: [String: AnyObject](),
|
||||
headers: nil,
|
||||
progress: nil,
|
||||
success: { task, value in
|
||||
guard let response = task.response as? HTTPURLResponse else {
|
||||
resolver.reject(LinkPreviewError.assertionFailure)
|
||||
return
|
||||
let session: URLSession = URLSession(configuration: sessionConfiguration)
|
||||
|
||||
return session
|
||||
.dataTaskPublisher(for: request)
|
||||
.subscribe(on: DispatchQueue.global(qos: .userInitiated))
|
||||
.mapError { _ -> Error in HTTPError.generic } // URLError codes are negative values
|
||||
.flatMap { data, response -> AnyPublisher<(Data, URLResponse), Error> in
|
||||
guard let urlResponse: HTTPURLResponse = response as? HTTPURLResponse else {
|
||||
return Fail(error: LinkPreviewError.assertionFailure)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
if let contentType = response.allHeaderFields["Content-Type"] as? String {
|
||||
if let contentType: String = urlResponse.allHeaderFields["Content-Type"] as? String {
|
||||
guard contentType.lowercased().hasPrefix("text/") else {
|
||||
resolver.reject(LinkPreviewError.invalidContent)
|
||||
return
|
||||
return Fail(error: LinkPreviewError.invalidContent)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
guard let data = value as? Data else {
|
||||
resolver.reject(LinkPreviewError.assertionFailure)
|
||||
return
|
||||
}
|
||||
guard data.count > 0 else {
|
||||
resolver.reject(LinkPreviewError.invalidContent)
|
||||
return
|
||||
return Fail(error: LinkPreviewError.invalidContent)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
resolver.fulfill((data, response))
|
||||
},
|
||||
failure: { _, error in
|
||||
guard isRetryable(error: error) else {
|
||||
resolver.reject(LinkPreviewError.couldNotDownload)
|
||||
return
|
||||
}
|
||||
|
||||
guard remainingRetries > 0 else {
|
||||
resolver.reject(LinkPreviewError.couldNotDownload)
|
||||
return
|
||||
}
|
||||
|
||||
LinkPreview.downloadLink(
|
||||
url: urlString,
|
||||
remainingRetries: (remainingRetries - 1)
|
||||
)
|
||||
.done(on: DispatchQueue.global()) { (data, response) in
|
||||
resolver.fulfill((data, response))
|
||||
}
|
||||
.catch(on: DispatchQueue.global()) { (error) in
|
||||
resolver.reject(error)
|
||||
}
|
||||
.retainUntilComplete()
|
||||
return Just((data, response))
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
)
|
||||
|
||||
return promise
|
||||
.catch { error -> AnyPublisher<(Data, URLResponse), Error> in
|
||||
guard isRetryable(error: error), remainingRetries > 0 else {
|
||||
return Fail(error: LinkPreviewError.couldNotDownload)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
return LinkPreview
|
||||
.downloadLink(
|
||||
url: urlString,
|
||||
remainingRetries: (remainingRetries - 1)
|
||||
)
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
private static func parseLinkDataAndBuildDraft(linkData: Data, response: URLResponse, linkUrlString: String) -> Promise<LinkPreviewDraft> {
|
||||
private static func parseLinkDataAndBuildDraft(
|
||||
linkData: Data,
|
||||
response: URLResponse,
|
||||
linkUrlString: String
|
||||
) -> AnyPublisher<LinkPreviewDraft, Error> {
|
||||
do {
|
||||
let contents = try parse(linkData: linkData, response: response)
|
||||
|
||||
let title = contents.title
|
||||
guard let imageUrl = contents.imageUrl else {
|
||||
return Promise.value(LinkPreviewDraft(urlString: linkUrlString, title: title))
|
||||
return Just(LinkPreviewDraft(urlString: linkUrlString, title: title))
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
guard URL(string: imageUrl) != nil else {
|
||||
return Promise.value(LinkPreviewDraft(urlString: linkUrlString, title: title))
|
||||
return Just(LinkPreviewDraft(urlString: linkUrlString, title: title))
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
guard let imageFileExtension = fileExtension(forImageUrl: imageUrl) else {
|
||||
return Promise.value(LinkPreviewDraft(urlString: linkUrlString, title: title))
|
||||
return Just(LinkPreviewDraft(urlString: linkUrlString, title: title))
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
guard let imageMimeType = mimetype(forImageFileExtension: imageFileExtension) else {
|
||||
return Promise.value(LinkPreviewDraft(urlString: linkUrlString, title: title))
|
||||
return Just(LinkPreviewDraft(urlString: linkUrlString, title: title))
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
return downloadImage(url: imageUrl, imageMimeType: imageMimeType)
|
||||
.map(on: DispatchQueue.global()) { (imageData: Data) -> LinkPreviewDraft in
|
||||
return LinkPreview
|
||||
.downloadImage(url: imageUrl, imageMimeType: imageMimeType)
|
||||
.map { imageData -> LinkPreviewDraft in
|
||||
// We always recompress images to Jpeg
|
||||
LinkPreviewDraft(urlString: linkUrlString, title: title, jpegImageData: imageData)
|
||||
}
|
||||
.recover(on: DispatchQueue.global()) { _ -> Promise<LinkPreviewDraft> in
|
||||
Promise.value(LinkPreviewDraft(urlString: linkUrlString, title: title))
|
||||
.catch { _ -> AnyPublisher<LinkPreviewDraft, Error> in
|
||||
return Just(LinkPreviewDraft(urlString: linkUrlString, title: title))
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
} catch {
|
||||
return Promise(error: error)
|
||||
return Fail(error: error)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -463,68 +475,86 @@ public extension LinkPreview {
|
|||
return Contents(title: title, imageUrl: imageUrlString)
|
||||
}
|
||||
|
||||
private static func downloadImage(url urlString: String, imageMimeType: String) -> Promise<Data> {
|
||||
guard let url = URL(string: urlString) else { return Promise(error: LinkPreviewError.invalidInput) }
|
||||
guard let assetDescription = ProxiedContentAssetDescription(url: url as NSURL) else {
|
||||
return Promise(error: LinkPreviewError.invalidInput)
|
||||
private static func downloadImage(
|
||||
url urlString: String,
|
||||
imageMimeType: String
|
||||
) -> AnyPublisher<Data, Error> {
|
||||
guard
|
||||
let url = URL(string: urlString),
|
||||
let assetDescription: ProxiedContentAssetDescription = ProxiedContentAssetDescription(
|
||||
url: url as NSURL
|
||||
)
|
||||
else {
|
||||
return Fail(error: LinkPreviewError.invalidInput)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
let (promise, resolver) = Promise<ProxiedContentAsset>.pending()
|
||||
DispatchQueue.main.async {
|
||||
_ = ProxiedContentDownloader.defaultDownloader.requestAsset(
|
||||
return ProxiedContentDownloader.defaultDownloader
|
||||
.requestAsset(
|
||||
assetDescription: assetDescription,
|
||||
priority: .high,
|
||||
success: { _, asset in
|
||||
resolver.fulfill(asset)
|
||||
},
|
||||
failure: { _ in
|
||||
resolver.reject(LinkPreviewError.couldNotDownload)
|
||||
},
|
||||
shouldIgnoreSignalProxy: true
|
||||
)
|
||||
}
|
||||
|
||||
return promise.then(on: DispatchQueue.global()) { (asset: ProxiedContentAsset) -> Promise<Data> in
|
||||
do {
|
||||
let imageSize = NSData.imageSize(forFilePath: asset.filePath, mimeType: imageMimeType)
|
||||
|
||||
guard imageSize.width > 0, imageSize.height > 0 else {
|
||||
return Promise(error: LinkPreviewError.invalidContent)
|
||||
}
|
||||
|
||||
let data = try Data(contentsOf: URL(fileURLWithPath: asset.filePath))
|
||||
|
||||
guard let srcImage = UIImage(data: data) else {
|
||||
return Promise(error: LinkPreviewError.invalidContent)
|
||||
}
|
||||
|
||||
// Loki: If it's a GIF then ensure its validity and don't download it as a JPG
|
||||
if (imageMimeType == OWSMimeTypeImageGif && NSData(data: data).ows_isValidImage(withMimeType: OWSMimeTypeImageGif)) { return Promise.value(data) }
|
||||
|
||||
let maxImageSize: CGFloat = 1024
|
||||
let shouldResize = imageSize.width > maxImageSize || imageSize.height > maxImageSize
|
||||
|
||||
guard shouldResize else {
|
||||
guard let dstData = srcImage.jpegData(compressionQuality: 0.8) else {
|
||||
return Promise(error: LinkPreviewError.invalidContent)
|
||||
.flatMap { asset, _ -> AnyPublisher<Data, Error> in
|
||||
do {
|
||||
let imageSize = NSData.imageSize(forFilePath: asset.filePath, mimeType: imageMimeType)
|
||||
|
||||
guard imageSize.width > 0, imageSize.height > 0 else {
|
||||
return Fail(error: LinkPreviewError.invalidContent)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
return Promise.value(dstData)
|
||||
}
|
||||
let data = try Data(contentsOf: URL(fileURLWithPath: asset.filePath))
|
||||
|
||||
guard let dstImage = srcImage.resized(withMaxDimensionPoints: maxImageSize) else {
|
||||
return Promise(error: LinkPreviewError.invalidContent)
|
||||
guard let srcImage = UIImage(data: data) else {
|
||||
return Fail(error: LinkPreviewError.invalidContent)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
// Loki: If it's a GIF then ensure its validity and don't download it as a JPG
|
||||
if
|
||||
imageMimeType == OWSMimeTypeImageGif &&
|
||||
NSData(data: data).ows_isValidImage(withMimeType: OWSMimeTypeImageGif)
|
||||
{
|
||||
return Just(data)
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
let maxImageSize: CGFloat = 1024
|
||||
let shouldResize = imageSize.width > maxImageSize || imageSize.height > maxImageSize
|
||||
|
||||
guard shouldResize else {
|
||||
guard let dstData = srcImage.jpegData(compressionQuality: 0.8) else {
|
||||
return Fail(error: LinkPreviewError.invalidContent)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
return Just(dstData)
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
guard let dstImage = srcImage.resized(withMaxDimensionPoints: maxImageSize) else {
|
||||
return Fail(error: LinkPreviewError.invalidContent)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
guard let dstData = dstImage.jpegData(compressionQuality: 0.8) else {
|
||||
return Fail(error: LinkPreviewError.invalidContent)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
return Just(dstData)
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
guard let dstData = dstImage.jpegData(compressionQuality: 0.8) else {
|
||||
return Promise(error: LinkPreviewError.invalidContent)
|
||||
catch {
|
||||
return Fail(error: LinkPreviewError.assertionFailure)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
return Promise.value(dstData)
|
||||
}
|
||||
catch {
|
||||
return Promise(error: LinkPreviewError.assertionFailure)
|
||||
}
|
||||
}
|
||||
.mapError { _ -> Error in LinkPreviewError.couldNotDownload }
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
private static func isRetryable(error: Error) -> Bool {
|
||||
|
|
|
@ -259,7 +259,6 @@ public final class SnodeAPI {
|
|||
)
|
||||
.subscribe(on: Threading.workQueue)
|
||||
.collect()
|
||||
.mapError { _ in SnodeAPIError.validationFailed }
|
||||
.flatMap { results -> AnyPublisher<String, Error> in
|
||||
guard results.count == validationCount, Set(results).count == 1 else {
|
||||
return Fail(error: SnodeAPIError.validationFailed)
|
||||
|
|
|
@ -8,9 +8,6 @@ import PromiseKit
|
|||
import SessionUtilitiesKit
|
||||
|
||||
public protocol OnionRequestAPIType {
|
||||
// static func sendOnionRequest(_ payload: Data, to snode: Snode) -> Promise<(ResponseInfoType, Data?)>
|
||||
// static func sendOnionRequest(_ request: URLRequest, to server: String, with x25519PublicKey: String) -> Promise<(ResponseInfoType, Data?)>
|
||||
|
||||
static func sendOnionRequest(_ payload: Data, to snode: Snode) -> AnyPublisher<(ResponseInfoType, Data?), Error>
|
||||
static func sendOnionRequest(_ request: URLRequest, to server: String, with x25519PublicKey: String) -> AnyPublisher<(ResponseInfoType, Data?), Error>
|
||||
}
|
||||
|
|
|
@ -1,19 +1,10 @@
|
|||
//
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import AFNetworking
|
||||
import Foundation
|
||||
|
||||
@objc
|
||||
public class ContentProxy: NSObject {
|
||||
public enum ContentProxy {
|
||||
|
||||
@available(*, unavailable, message:"do not instantiate this class.")
|
||||
private override init() {
|
||||
}
|
||||
|
||||
@objc
|
||||
public class func sessionConfiguration() -> URLSessionConfiguration {
|
||||
public static func sessionConfiguration() -> URLSessionConfiguration {
|
||||
let configuration = URLSessionConfiguration.ephemeral
|
||||
let proxyHost = "contentproxy.signal.org"
|
||||
let proxyPort = 443
|
||||
|
@ -28,32 +19,9 @@ public class ContentProxy: NSObject {
|
|||
return configuration
|
||||
}
|
||||
|
||||
@objc
|
||||
public class func sessionManager(baseUrl baseUrlString: String?) -> AFHTTPSessionManager? {
|
||||
guard let baseUrlString = baseUrlString else {
|
||||
return AFHTTPSessionManager(baseURL: nil, sessionConfiguration: sessionConfiguration())
|
||||
}
|
||||
guard let baseUrl = URL(string: baseUrlString) else {
|
||||
return nil
|
||||
}
|
||||
let sessionManager = AFHTTPSessionManager(baseURL: baseUrl,
|
||||
sessionConfiguration: sessionConfiguration())
|
||||
return sessionManager
|
||||
}
|
||||
|
||||
@objc
|
||||
public class func jsonSessionManager(baseUrl: String) -> AFHTTPSessionManager? {
|
||||
guard let sessionManager = self.sessionManager(baseUrl: baseUrl) else {
|
||||
return nil
|
||||
}
|
||||
sessionManager.requestSerializer = AFJSONRequestSerializer()
|
||||
sessionManager.responseSerializer = AFJSONResponseSerializer()
|
||||
return sessionManager
|
||||
}
|
||||
|
||||
static let userAgent = "Signal iOS (+https://signal.org/download)"
|
||||
|
||||
public class func configureProxiedRequest(request: inout URLRequest) -> Bool {
|
||||
public static func configureProxiedRequest(request: inout URLRequest) -> Bool {
|
||||
request.addValue(userAgent, forHTTPHeaderField: "User-Agent")
|
||||
|
||||
padRequestSize(request: &request)
|
||||
|
@ -66,39 +34,7 @@ public class ContentProxy: NSObject {
|
|||
return true
|
||||
}
|
||||
|
||||
// This mutates the session manager state, so its the caller's obligation to avoid conflicts by:
|
||||
//
|
||||
// * Using a new session manager for each request.
|
||||
// * Pooling session managers.
|
||||
// * Using a single session manager on a single queue.
|
||||
@objc
|
||||
public class func configureSessionManager(sessionManager: AFHTTPSessionManager,
|
||||
forUrl urlString: String) -> Bool {
|
||||
|
||||
guard let url = URL(string: urlString, relativeTo: sessionManager.baseURL) else {
|
||||
return false
|
||||
}
|
||||
|
||||
var request = URLRequest(url: url)
|
||||
|
||||
guard configureProxiedRequest(request: &request) else {
|
||||
return false
|
||||
}
|
||||
|
||||
// Remove all headers from the request.
|
||||
for headerField in sessionManager.requestSerializer.httpRequestHeaders.keys {
|
||||
sessionManager.requestSerializer.setValue(nil, forHTTPHeaderField: headerField)
|
||||
}
|
||||
// Honor the request's headers.
|
||||
if let allHTTPHeaderFields = request.allHTTPHeaderFields {
|
||||
for (headerField, headerValue) in allHTTPHeaderFields {
|
||||
sessionManager.requestSerializer.setValue(headerValue, forHTTPHeaderField: headerField)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public class func padRequestSize(request: inout URLRequest) {
|
||||
public static func padRequestSize(request: inout URLRequest) {
|
||||
// Generate 1-64 chars of padding.
|
||||
let paddingLength: Int = 1 + Int(arc4random_uniform(64))
|
||||
let padding = self.padding(withLength: paddingLength)
|
||||
|
@ -106,7 +42,7 @@ public class ContentProxy: NSObject {
|
|||
request.addValue(padding, forHTTPHeaderField: "X-SignalPadding")
|
||||
}
|
||||
|
||||
private class func padding(withLength length: Int) -> String {
|
||||
private static func padding(withLength length: Int) -> String {
|
||||
// Pick a random ASCII char in the range 48-122
|
||||
var result = ""
|
||||
// Min and max values, inclusive.
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import ObjectiveC
|
||||
|
||||
// Stills should be loaded before full GIFs.
|
||||
|
@ -496,6 +497,40 @@ open class ProxiedContentDownloader: NSObject, URLSessionTaskDelegate, URLSessio
|
|||
processRequestQueueAsync()
|
||||
return assetRequest
|
||||
}
|
||||
|
||||
public func requestAsset(
|
||||
assetDescription: ProxiedContentAssetDescription,
|
||||
priority: ProxiedContentRequestPriority,
|
||||
shouldIgnoreSignalProxy: Bool = false
|
||||
) -> AnyPublisher<(ProxiedContentAsset, ProxiedContentAssetRequest?), Error> {
|
||||
if let asset = assetMap.get(key: assetDescription.url) {
|
||||
// Synchronous cache hit.
|
||||
return Just((asset, nil))
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
// Cache miss.
|
||||
//
|
||||
// Asset requests are done queued and performed asynchronously.
|
||||
return Future { [weak self] resolver in
|
||||
let assetRequest = ProxiedContentAssetRequest(
|
||||
assetDescription: assetDescription,
|
||||
priority: priority,
|
||||
success: { request, asset in resolver(Result.success((asset, request))) },
|
||||
failure: { request in
|
||||
resolver(Result.failure(HTTPError.generic))
|
||||
}
|
||||
)
|
||||
assetRequest.shouldIgnoreSignalProxy = shouldIgnoreSignalProxy
|
||||
self?.assetRequestQueue.append(assetRequest)
|
||||
// Process the queue (which may start this request)
|
||||
// asynchronously so that the caller has time to store
|
||||
// a reference to the asset request returned by this
|
||||
// method before its success/failure handler is called.
|
||||
self?.processRequestQueueAsync()
|
||||
}.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
public func cancelAllRequests() {
|
||||
self.assetRequestQueue.forEach { $0.cancel() }
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
import Combine
|
||||
import MediaPlayer
|
||||
import YYImage
|
||||
import NVActivityIndicatorView
|
||||
|
@ -21,6 +22,7 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
|
|||
|
||||
// MARK: Properties
|
||||
|
||||
private var disposables: Set<AnyCancellable> = Set()
|
||||
public let mode: Mode
|
||||
public let attachment: SignalAttachment
|
||||
|
||||
|
@ -565,44 +567,51 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
|
|||
loadingView.startAnimating()
|
||||
|
||||
LinkPreview.tryToBuildPreviewInfo(previewUrl: linkPreviewURL)
|
||||
.done { [weak self] draft in
|
||||
// TODO: Look at refactoring this behaviour to consolidate attachment mutations
|
||||
self?.attachment.linkPreviewDraft = draft
|
||||
self?.linkPreviewInfo = (url: linkPreviewURL, draft: draft)
|
||||
|
||||
// Update the UI
|
||||
self?.titleLabel.text = (draft.title ?? self?.titleLabel.text)
|
||||
self?.loadingView.alpha = 0
|
||||
self?.loadingView.stopAnimating()
|
||||
self?.imageView.alpha = 1
|
||||
|
||||
if let jpegImageData: Data = draft.jpegImageData, let loadedImage: UIImage = UIImage(data: jpegImageData) {
|
||||
self?.imageView.image = loadedImage
|
||||
self?.imageView.contentMode = .scaleAspectFill
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink(
|
||||
receiveCompletion: { [weak self] result in
|
||||
switch result {
|
||||
case .finished: break
|
||||
case .failure:
|
||||
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.themeTextColor = (self?.mode == .attachmentApproval ?
|
||||
.textSecondary :
|
||||
.primary
|
||||
)
|
||||
self?.subtitleLabel.textAlignment = .left
|
||||
}
|
||||
}
|
||||
},
|
||||
receiveValue: { [weak self] draft in
|
||||
// TODO: Look at refactoring this behaviour to consolidate attachment mutations
|
||||
self?.attachment.linkPreviewDraft = draft
|
||||
self?.linkPreviewInfo = (url: linkPreviewURL, draft: draft)
|
||||
|
||||
// Update the UI
|
||||
self?.titleLabel.text = (draft.title ?? self?.titleLabel.text)
|
||||
self?.loadingView.alpha = 0
|
||||
self?.loadingView.stopAnimating()
|
||||
self?.imageView.alpha = 1
|
||||
|
||||
if let jpegImageData: Data = draft.jpegImageData, let loadedImage: UIImage = UIImage(data: jpegImageData) {
|
||||
self?.imageView.image = loadedImage
|
||||
self?.imageView.contentMode = .scaleAspectFill
|
||||
}
|
||||
}
|
||||
}
|
||||
.catch { [weak self] _ in
|
||||
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.themeTextColor = (self?.mode == .attachmentApproval ?
|
||||
.textSecondary :
|
||||
.primary
|
||||
)
|
||||
self?.subtitleLabel.textAlignment = .left
|
||||
}
|
||||
}
|
||||
.retainUntilComplete()
|
||||
)
|
||||
.store(in: &disposables)
|
||||
}
|
||||
|
||||
// MARK: - Functions
|
||||
|
|
|
@ -27,7 +27,7 @@ public enum AppSetup {
|
|||
// initializers injected.
|
||||
OWSBackgroundTaskManager.shared().observeNotifications()
|
||||
|
||||
// AFNetworking (via CFNetworking) spools it's attachments to NSTemporaryDirectory().
|
||||
// Attachments can be stored to NSTemporaryDirectory()
|
||||
// If you receive a media message while the device is locked, the download will fail if
|
||||
// the temporary directory is NSFileProtectionComplete
|
||||
let success: Bool = OWSFileSystem.protectFileOrFolder(
|
||||
|
|
Loading…
Reference in New Issue