Merge branch 'charlesmchen/saeVsMainThread'
This commit is contained in:
commit
194ae2dfd5
@ -375,7 +375,7 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
|
||||
}
|
||||
|
||||
func presentAudioSourcePicker() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let actionSheetController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
|
||||
|
||||
@ -933,41 +933,41 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
|
||||
// MARK: - CallObserver
|
||||
|
||||
internal func stateDidChange(call: SignalCall, state: CallState) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.TAG) new call status: \(state)")
|
||||
self.updateCallUI(callState: state)
|
||||
}
|
||||
|
||||
internal func hasLocalVideoDidChange(call: SignalCall, hasLocalVideo: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
self.updateCallUI(callState: call.state)
|
||||
}
|
||||
|
||||
internal func muteDidChange(call: SignalCall, isMuted: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
self.updateCallUI(callState: call.state)
|
||||
}
|
||||
|
||||
func holdDidChange(call: SignalCall, isOnHold: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
self.updateCallUI(callState: call.state)
|
||||
}
|
||||
|
||||
internal func audioSourceDidChange(call: SignalCall, audioSource: AudioSource?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
self.updateCallUI(callState: call.state)
|
||||
}
|
||||
|
||||
// MARK: CallAudioServiceDelegate
|
||||
|
||||
func callAudioService(_ callAudioService: CallAudioService, didUpdateIsSpeakerphoneEnabled isSpeakerphoneEnabled: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
updateAudioSourceButtonIsSelected()
|
||||
}
|
||||
|
||||
func callAudioServiceDidChangeAudioSession(_ callAudioService: CallAudioService) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
// Which sources are available depends on the state of your Session.
|
||||
// When the audio session is not yet in PlayAndRecord none are available
|
||||
@ -984,7 +984,7 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
|
||||
// MARK: - Video
|
||||
|
||||
internal func updateLocalVideoTrack(localVideoTrack: RTCVideoTrack?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard self.localVideoTrack != localVideoTrack else {
|
||||
return
|
||||
}
|
||||
@ -1007,7 +1007,7 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
|
||||
}
|
||||
|
||||
internal func updateRemoteVideoTrack(remoteVideoTrack: RTCVideoTrack?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard self.remoteVideoTrack != remoteVideoTrack else {
|
||||
return
|
||||
}
|
||||
@ -1088,7 +1088,7 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver,
|
||||
internal func didUpdateVideoTracks(call: SignalCall?,
|
||||
localVideoTrack: RTCVideoTrack?,
|
||||
remoteVideoTrack: RTCVideoTrack?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
updateLocalVideoTrack(localVideoTrack: localVideoTrack)
|
||||
updateRemoteVideoTrack(remoteVideoTrack: remoteVideoTrack)
|
||||
|
||||
@ -3899,7 +3899,7 @@ typedef enum : NSUInteger {
|
||||
|
||||
- (void)handleKeyboardNotification:(NSNotification *)notification
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
NSDictionary *userInfo = [notification userInfo];
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@ -15,7 +15,7 @@ class GifPickerCell: UICollectionViewCell {
|
||||
|
||||
var imageInfo: GiphyImageInfo? {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
ensureCellState()
|
||||
}
|
||||
@ -25,7 +25,7 @@ class GifPickerCell: UICollectionViewCell {
|
||||
// Here's a bit of logic to not preload offscreen cells that are prefetched.
|
||||
var isCellVisible = false {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
ensureCellState()
|
||||
}
|
||||
@ -42,7 +42,7 @@ class GifPickerCell: UICollectionViewCell {
|
||||
|
||||
var isCellSelected: Bool = false {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
ensureCellState()
|
||||
}
|
||||
}
|
||||
@ -137,8 +137,8 @@ class GifPickerCell: UICollectionViewCell {
|
||||
if stillAsset != nil || animatedAsset != nil {
|
||||
clearStillAssetRequest()
|
||||
} else if stillAssetRequest == nil {
|
||||
stillAssetRequest = GiphyDownloader.sharedInstance.requestAsset(rendition:stillRendition,
|
||||
priority:.high,
|
||||
stillAssetRequest = GiphyDownloader.sharedInstance.requestAsset(rendition: stillRendition,
|
||||
priority: .high,
|
||||
success: { [weak self] assetRequest, asset in
|
||||
guard let strongSelf = self else { return }
|
||||
if assetRequest != nil && assetRequest != strongSelf.stillAssetRequest {
|
||||
@ -163,8 +163,8 @@ class GifPickerCell: UICollectionViewCell {
|
||||
if animatedAsset != nil {
|
||||
clearAnimatedAssetRequest()
|
||||
} else if animatedAssetRequest == nil {
|
||||
animatedAssetRequest = GiphyDownloader.sharedInstance.requestAsset(rendition:animatedRendition,
|
||||
priority:.low,
|
||||
animatedAssetRequest = GiphyDownloader.sharedInstance.requestAsset(rendition: animatedRendition,
|
||||
priority: .low,
|
||||
success: { [weak self] assetRequest, asset in
|
||||
guard let strongSelf = self else { return }
|
||||
if assetRequest != nil && assetRequest != strongSelf.animatedAssetRequest {
|
||||
@ -197,7 +197,7 @@ class GifPickerCell: UICollectionViewCell {
|
||||
clearViewState()
|
||||
return
|
||||
}
|
||||
guard let image = YYImage(contentsOfFile:asset.filePath) else {
|
||||
guard let image = YYImage(contentsOfFile: asset.filePath) else {
|
||||
owsFail("\(TAG) could not load asset.")
|
||||
clearViewState()
|
||||
return
|
||||
@ -267,7 +267,7 @@ class GifPickerCell: UICollectionViewCell {
|
||||
|
||||
private func clearViewState() {
|
||||
imageView?.image = nil
|
||||
self.backgroundColor = UIColor(white:0.95, alpha:1.0)
|
||||
self.backgroundColor = UIColor(white: 0.95, alpha: 1.0)
|
||||
}
|
||||
|
||||
private func pickBestAsset() -> GiphyAsset? {
|
||||
|
||||
@ -80,7 +80,7 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
||||
}
|
||||
|
||||
func didBecomeActive() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
@ -89,7 +89,7 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect
|
||||
}
|
||||
|
||||
func reachabilityChanged() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
|
||||
@ -747,7 +747,7 @@ class MediaGalleryViewController: UINavigationController, MediaGalleryDataSource
|
||||
var deletedGalleryItems: Set<MediaGalleryItem> = Set()
|
||||
|
||||
func delete(items: [MediaGalleryItem], initiatedBy: MediaGalleryDataSourceDelegate) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.info("\(logTag) in \(#function) with items: \(items.map { ($0.attachmentStream, $0.message.timestamp) })")
|
||||
|
||||
|
||||
@ -499,7 +499,7 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele
|
||||
// This method should be called after self.databaseConnection.beginLongLivedReadTransaction().
|
||||
private func updateDBConnectionAndMessageToLatest() {
|
||||
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
self.uiDatabaseConnection.read { transaction in
|
||||
guard let uniqueId = self.message.uniqueId else {
|
||||
@ -516,7 +516,7 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele
|
||||
}
|
||||
|
||||
internal func yapDatabaseModified(notification: NSNotification) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard !wasDeleted else {
|
||||
// Item was deleted. Don't bother re-rendering, it will fail and we'll soon be dismissed.
|
||||
@ -606,7 +606,7 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele
|
||||
var audioAttachmentPlayer: OWSAudioPlayer?
|
||||
|
||||
func didTapAudioViewItem(_ viewItem: ConversationViewItem, attachmentStream: TSAttachmentStream) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let mediaURL = attachmentStream.mediaURL() else {
|
||||
owsFail("\(logTag) in \(#function) mediaURL was unexpectedly nil for attachment: \(attachmentStream)")
|
||||
|
||||
@ -141,24 +141,24 @@ protocol CallAudioServiceDelegate: class {
|
||||
// MARK: - CallObserver
|
||||
|
||||
internal func stateDidChange(call: SignalCall, state: CallState) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
self.handleState(call: call)
|
||||
}
|
||||
|
||||
internal func muteDidChange(call: SignalCall, isMuted: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
ensureProperAudioSession(call: call)
|
||||
}
|
||||
|
||||
internal func holdDidChange(call: SignalCall, isOnHold: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
ensureProperAudioSession(call: call)
|
||||
}
|
||||
|
||||
internal func audioSourceDidChange(call: SignalCall, audioSource: AudioSource?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
ensureProperAudioSession(call: call)
|
||||
|
||||
@ -170,7 +170,7 @@ protocol CallAudioServiceDelegate: class {
|
||||
}
|
||||
|
||||
internal func hasLocalVideoDidChange(call: SignalCall, hasLocalVideo: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
ensureProperAudioSession(call: call)
|
||||
}
|
||||
@ -208,7 +208,7 @@ protocol CallAudioServiceDelegate: class {
|
||||
}
|
||||
|
||||
private func ensureProperAudioSession(call: SignalCall?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = call, !call.isTerminated else {
|
||||
// Revert to default audio
|
||||
@ -302,7 +302,7 @@ protocol CallAudioServiceDelegate: class {
|
||||
|
||||
private func handleDialing(call: SignalCall) {
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
// HACK: Without this async, dialing sound only plays once. I don't really understand why. Does the audioSession
|
||||
// need some time to settle? Is somethign else interrupting our session?
|
||||
@ -313,31 +313,31 @@ protocol CallAudioServiceDelegate: class {
|
||||
|
||||
private func handleAnswering(call: SignalCall) {
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
}
|
||||
|
||||
private func handleRemoteRinging(call: SignalCall) {
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
self.play(sound: OWSSound.callOutboundRinging)
|
||||
}
|
||||
|
||||
private func handleLocalRinging(call: SignalCall) {
|
||||
Logger.debug("\(self.logTag) in \(#function)")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
startRinging(call: call)
|
||||
}
|
||||
|
||||
private func handleConnected(call: SignalCall) {
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
}
|
||||
|
||||
private func handleLocalFailure(call: SignalCall) {
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
play(sound: OWSSound.callFailure)
|
||||
handleCallEnded(call: call)
|
||||
@ -345,14 +345,14 @@ protocol CallAudioServiceDelegate: class {
|
||||
|
||||
private func handleLocalHangup(call: SignalCall) {
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
handleCallEnded(call: call)
|
||||
}
|
||||
|
||||
private func handleRemoteHangup(call: SignalCall) {
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
vibrate()
|
||||
|
||||
@ -361,7 +361,7 @@ protocol CallAudioServiceDelegate: class {
|
||||
|
||||
private func handleBusy(call: SignalCall) {
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
play(sound: OWSSound.callBusy)
|
||||
|
||||
@ -373,7 +373,7 @@ protocol CallAudioServiceDelegate: class {
|
||||
|
||||
private func handleCallEnded(call: SignalCall) {
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
// Stop solo audio, revert to default.
|
||||
isSpeakerphoneEnabled = false
|
||||
@ -485,7 +485,7 @@ protocol CallAudioServiceDelegate: class {
|
||||
mode: String? = nil,
|
||||
options: AVAudioSessionCategoryOptions = AVAudioSessionCategoryOptions(rawValue: 0)) {
|
||||
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
var audioSessionChanged = false
|
||||
do {
|
||||
|
||||
@ -124,7 +124,7 @@ protocol CallServiceObserver: class {
|
||||
|
||||
var peerConnectionClient: PeerConnectionClient? {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(self.logTag) .peerConnectionClient setter: \(oldValue != nil) -> \(peerConnectionClient != nil) \(String(describing: peerConnectionClient))")
|
||||
}
|
||||
@ -132,7 +132,7 @@ protocol CallServiceObserver: class {
|
||||
|
||||
var call: SignalCall? {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
oldValue?.removeObserver(self)
|
||||
call?.addObserverAndSyncState(observer: self)
|
||||
@ -177,7 +177,7 @@ protocol CallServiceObserver: class {
|
||||
|
||||
weak var localVideoTrack: RTCVideoTrack? {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.info("\(self.logTag) \(#function)")
|
||||
|
||||
@ -187,7 +187,7 @@ protocol CallServiceObserver: class {
|
||||
|
||||
weak var remoteVideoTrack: RTCVideoTrack? {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.info("\(self.logTag) \(#function)")
|
||||
|
||||
@ -196,7 +196,7 @@ protocol CallServiceObserver: class {
|
||||
}
|
||||
var isRemoteVideoEnabled = false {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.info("\(self.logTag) \(#function): \(isRemoteVideoEnabled)")
|
||||
|
||||
@ -232,12 +232,12 @@ protocol CallServiceObserver: class {
|
||||
}
|
||||
|
||||
func didEnterBackground() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
self.updateIsVideoEnabled()
|
||||
}
|
||||
|
||||
func didBecomeActive() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
self.updateIsVideoEnabled()
|
||||
}
|
||||
|
||||
@ -245,7 +245,7 @@ protocol CallServiceObserver: class {
|
||||
* Choose whether to use CallKit or a Notification backed interface for calling.
|
||||
*/
|
||||
public func createCallUIAdapter() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
if self.call != nil {
|
||||
Logger.warn("\(self.logTag) ending current call in \(#function). Did user toggle callkit preference while in a call?")
|
||||
@ -260,7 +260,7 @@ protocol CallServiceObserver: class {
|
||||
* Initiate an outgoing call.
|
||||
*/
|
||||
public func handleOutgoingCall(_ call: SignalCall) -> Promise<Void> {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard self.call == nil else {
|
||||
let errorDescription = "\(self.logTag) call was unexpectedly already set."
|
||||
@ -354,7 +354,7 @@ protocol CallServiceObserver: class {
|
||||
}
|
||||
|
||||
func readyToSendIceUpdates(call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard self.call == call else {
|
||||
self.handleFailedCall(failedCall: call, error: .obsoleteCall(description:"obsolete call in \(#function)"))
|
||||
@ -379,7 +379,7 @@ protocol CallServiceObserver: class {
|
||||
*/
|
||||
public func handleReceivedAnswer(thread: TSContactThread, callId: UInt64, sessionDescription: String) {
|
||||
Logger.info("\(self.logTag) received call answer for call: \(callId) thread: \(thread.contactIdentifier())")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.call else {
|
||||
Logger.warn("\(self.logTag) ignoring obsolete call: \(callId) in \(#function)")
|
||||
@ -417,7 +417,7 @@ protocol CallServiceObserver: class {
|
||||
* User didn't answer incoming call
|
||||
*/
|
||||
public func handleMissedCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
// Insert missed call record
|
||||
if let callRecord = call.callRecord {
|
||||
@ -442,7 +442,7 @@ protocol CallServiceObserver: class {
|
||||
*/
|
||||
private func handleLocalBusyCall(_ call: SignalCall) {
|
||||
Logger.info("\(self.logTag) \(#function) for call: \(call.identifiersForLogs) thread: \(call.thread.contactIdentifier())")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let busyMessage = OWSCallBusyMessage(callId: call.signalingId)
|
||||
let callMessage = OWSOutgoingCallMessage(thread: call.thread, busyMessage: busyMessage)
|
||||
@ -457,7 +457,7 @@ protocol CallServiceObserver: class {
|
||||
*/
|
||||
public func handleRemoteBusy(thread: TSContactThread, callId: UInt64) {
|
||||
Logger.info("\(self.logTag) \(#function) for thread: \(thread.contactIdentifier())")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.call else {
|
||||
Logger.warn("\(self.logTag) ignoring obsolete call: \(callId) in \(#function)")
|
||||
@ -484,7 +484,7 @@ protocol CallServiceObserver: class {
|
||||
* the user of an incoming call.
|
||||
*/
|
||||
public func handleReceivedOffer(thread: TSContactThread, callId: UInt64, sessionDescription callerSessionDescription: String) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let newCall = SignalCall.incomingCall(localId: UUID(), remotePhoneNumber: thread.contactIdentifier(), signalingId: callId)
|
||||
|
||||
@ -558,7 +558,7 @@ protocol CallServiceObserver: class {
|
||||
self.call = newCall
|
||||
|
||||
var backgroundTask: OWSBackgroundTask? = OWSBackgroundTask(label: "\(#function)", completionBlock: { [weak self] status in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard status == .expired else {
|
||||
return
|
||||
@ -666,7 +666,7 @@ protocol CallServiceObserver: class {
|
||||
*/
|
||||
public func handleRemoteAddedIceCandidate(thread: TSContactThread, callId: UInt64, sdp: String, lineIndex: Int32, mid: String) {
|
||||
waitForPeerConnectionClient().then { () -> Void in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.call else {
|
||||
Logger.warn("ignoring remote ice update for thread: \(String(describing: thread.uniqueId)) since there is no current call. Call already ended?")
|
||||
@ -700,7 +700,7 @@ protocol CallServiceObserver: class {
|
||||
* remote client.
|
||||
*/
|
||||
private func handleLocalAddedIceCandidate(_ iceCandidate: RTCIceCandidate) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.call else {
|
||||
OWSProdError(OWSAnalyticsEvents.callServiceCallMissing(), file: #file, function: #function, line: #line)
|
||||
@ -743,7 +743,7 @@ protocol CallServiceObserver: class {
|
||||
* client.
|
||||
*/
|
||||
private func handleIceConnected() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.call else {
|
||||
// This will only be called for the current peerConnectionClient, so
|
||||
@ -775,7 +775,7 @@ protocol CallServiceObserver: class {
|
||||
*/
|
||||
public func handleRemoteHangup(thread: TSContactThread, callId: UInt64) {
|
||||
Logger.debug("\(self.logTag) in \(#function)")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.call else {
|
||||
// This may happen if we hang up slightly before they hang up.
|
||||
@ -818,7 +818,7 @@ protocol CallServiceObserver: class {
|
||||
* Used by notification actions which can't serialize a call object.
|
||||
*/
|
||||
public func handleAnswerCall(localId: UUID) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.call else {
|
||||
// This should never happen; return to a known good state.
|
||||
@ -843,7 +843,7 @@ protocol CallServiceObserver: class {
|
||||
* User chose to answer call referred to by call `localId`. Used by the Callee only.
|
||||
*/
|
||||
public func handleAnswerCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(self.logTag) in \(#function)")
|
||||
|
||||
@ -884,7 +884,7 @@ protocol CallServiceObserver: class {
|
||||
*/
|
||||
func handleConnectedCall(_ call: SignalCall) {
|
||||
Logger.info("\(self.logTag) in \(#function)")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let peerConnectionClient = self.peerConnectionClient else {
|
||||
OWSProdError(OWSAnalyticsEvents.callServicePeerConnectionMissing(), file: #file, function: #function, line: #line)
|
||||
@ -913,7 +913,7 @@ protocol CallServiceObserver: class {
|
||||
* Incoming call only.
|
||||
*/
|
||||
public func handleDeclineCall(localId: UUID) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.call else {
|
||||
// This should never happen; return to a known good state.
|
||||
@ -940,7 +940,7 @@ protocol CallServiceObserver: class {
|
||||
* Incoming call only.
|
||||
*/
|
||||
public func handleDeclineCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.info("\(self.logTag) in \(#function): \(call.identifiersForLogs).")
|
||||
|
||||
@ -963,7 +963,7 @@ protocol CallServiceObserver: class {
|
||||
* Can be used for Incoming and Outgoing calls.
|
||||
*/
|
||||
func handleLocalHungupCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let currentCall = self.call else {
|
||||
Logger.info("\(self.logTag) in \(#function), but no current call. Other party hung up just before us.")
|
||||
@ -1018,7 +1018,7 @@ protocol CallServiceObserver: class {
|
||||
* Can be used for Incoming and Outgoing calls.
|
||||
*/
|
||||
func setIsMuted(call: SignalCall, isMuted: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard call == self.call else {
|
||||
// This can happen after a call has ended. Reproducible on iOS11, when the other party ends the call.
|
||||
@ -1041,7 +1041,7 @@ protocol CallServiceObserver: class {
|
||||
* e.g. when another Call comes in.
|
||||
*/
|
||||
func setIsOnHold(call: SignalCall, isOnHold: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard call == self.call else {
|
||||
Logger.info("\(self.logTag) ignoring held request for obsolete call")
|
||||
@ -1081,7 +1081,7 @@ protocol CallServiceObserver: class {
|
||||
* Can be used for Incoming and Outgoing calls.
|
||||
*/
|
||||
func setHasLocalVideo(hasLocalVideo: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let frontmostViewController = UIApplication.shared.frontmostViewController else {
|
||||
owsFail("\(self.logTag) could not identify frontmostViewController in \(#function)")
|
||||
@ -1109,7 +1109,7 @@ protocol CallServiceObserver: class {
|
||||
}
|
||||
|
||||
private func setHasLocalVideoWithCameraPermissions(hasLocalVideo: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.call else {
|
||||
// This should never happen; return to a known good state.
|
||||
@ -1132,7 +1132,7 @@ protocol CallServiceObserver: class {
|
||||
}
|
||||
|
||||
func handleCallKitStartVideo() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
self.setHasLocalVideo(hasLocalVideo: true)
|
||||
}
|
||||
@ -1148,7 +1148,7 @@ protocol CallServiceObserver: class {
|
||||
* Used by both Incoming and Outgoing calls.
|
||||
*/
|
||||
private func handleDataChannelMessage(_ message: OWSWebRTCProtosData) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.call else {
|
||||
// This should never happen; return to a known good state.
|
||||
@ -1203,7 +1203,7 @@ protocol CallServiceObserver: class {
|
||||
* The connection has been established. The clients can now communicate.
|
||||
*/
|
||||
internal func peerConnectionClientIceConnected(_ peerConnectionClient: PeerConnectionClient) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard peerConnectionClient == self.peerConnectionClient else {
|
||||
Logger.debug("\(self.logTag) \(#function) Ignoring event from obsolete peerConnectionClient")
|
||||
@ -1217,7 +1217,7 @@ protocol CallServiceObserver: class {
|
||||
* The connection failed to establish. The clients will not be able to communicate.
|
||||
*/
|
||||
internal func peerConnectionClientIceFailed(_ peerConnectionClient: PeerConnectionClient) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard peerConnectionClient == self.peerConnectionClient else {
|
||||
Logger.debug("\(self.logTag) \(#function) Ignoring event from obsolete peerConnectionClient")
|
||||
@ -1234,7 +1234,7 @@ protocol CallServiceObserver: class {
|
||||
* out of band, as part of establishing a connection over WebRTC.
|
||||
*/
|
||||
internal func peerConnectionClient(_ peerConnectionClient: PeerConnectionClient, addedLocalIceCandidate iceCandidate: RTCIceCandidate) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard peerConnectionClient == self.peerConnectionClient else {
|
||||
Logger.debug("\(self.logTag) \(#function) Ignoring event from obsolete peerConnectionClient")
|
||||
@ -1248,7 +1248,7 @@ protocol CallServiceObserver: class {
|
||||
* Once the peerconnection is established, we can receive messages via the data channel, and notify the delegate.
|
||||
*/
|
||||
internal func peerConnectionClient(_ peerConnectionClient: PeerConnectionClient, received dataChannelMessage: OWSWebRTCProtosData) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard peerConnectionClient == self.peerConnectionClient else {
|
||||
Logger.debug("\(self.logTag) \(#function) Ignoring event from obsolete peerConnectionClient")
|
||||
@ -1259,7 +1259,7 @@ protocol CallServiceObserver: class {
|
||||
}
|
||||
|
||||
internal func peerConnectionClient(_ peerConnectionClient: PeerConnectionClient, didUpdateLocal videoTrack: RTCVideoTrack?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard peerConnectionClient == self.peerConnectionClient else {
|
||||
Logger.debug("\(self.logTag) \(#function) Ignoring event from obsolete peerConnectionClient")
|
||||
@ -1270,7 +1270,7 @@ protocol CallServiceObserver: class {
|
||||
}
|
||||
|
||||
internal func peerConnectionClient(_ peerConnectionClient: PeerConnectionClient, didUpdateRemote videoTrack: RTCVideoTrack?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard peerConnectionClient == self.peerConnectionClient else {
|
||||
Logger.debug("\(self.logTag) \(#function) Ignoring event from obsolete peerConnectionClient")
|
||||
@ -1283,7 +1283,7 @@ protocol CallServiceObserver: class {
|
||||
// MARK: Helpers
|
||||
|
||||
private func waitUntilReadyToSendIceUpdates() -> Promise<Void> {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
if self.readyToSendIceUpdatesPromise == nil {
|
||||
createReadyToSendIceUpdatesPromise()
|
||||
@ -1298,7 +1298,7 @@ protocol CallServiceObserver: class {
|
||||
}
|
||||
|
||||
private func createReadyToSendIceUpdatesPromise() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard self.readyToSendIceUpdatesPromise == nil else {
|
||||
owsFail("expected readyToSendIceUpdatesPromise to be nil")
|
||||
@ -1322,7 +1322,7 @@ protocol CallServiceObserver: class {
|
||||
}
|
||||
|
||||
private func waitForPeerConnectionClient() -> Promise<Void> {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard self.peerConnectionClient == nil else {
|
||||
// peerConnectionClient already set
|
||||
@ -1342,7 +1342,7 @@ protocol CallServiceObserver: class {
|
||||
}
|
||||
|
||||
private func createPeerConnectionClientPromise() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard self.peerConnectionClientPromise == nil else {
|
||||
owsFail("expected peerConnectionClientPromise to be nil")
|
||||
@ -1370,7 +1370,7 @@ protocol CallServiceObserver: class {
|
||||
* a list of servers, plus we have fallback servers hardcoded in the app.
|
||||
*/
|
||||
private func getIceServers() -> Promise<[RTCIceServer]> {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
return firstly {
|
||||
return accountManager.getTurnServerInfo()
|
||||
@ -1412,7 +1412,7 @@ protocol CallServiceObserver: class {
|
||||
// to reflect the error.
|
||||
// * IFF that call is the current call, we want to terminate it.
|
||||
public func handleFailedCall(failedCall: SignalCall?, error: CallError) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
if case CallError.assertionError(description: let description) = error {
|
||||
owsFail(description)
|
||||
@ -1451,7 +1451,7 @@ protocol CallServiceObserver: class {
|
||||
* Clean up any existing call state and get ready to receive a new call.
|
||||
*/
|
||||
private func terminateCall() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(self.logTag) in \(#function)")
|
||||
|
||||
@ -1498,36 +1498,36 @@ protocol CallServiceObserver: class {
|
||||
// MARK: - CallObserver
|
||||
|
||||
internal func stateDidChange(call: SignalCall, state: CallState) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.logTag) \(#function): \(state)")
|
||||
updateIsVideoEnabled()
|
||||
}
|
||||
|
||||
internal func hasLocalVideoDidChange(call: SignalCall, hasLocalVideo: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.logTag) \(#function): \(hasLocalVideo)")
|
||||
self.updateIsVideoEnabled()
|
||||
}
|
||||
|
||||
internal func muteDidChange(call: SignalCall, isMuted: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
internal func holdDidChange(call: SignalCall, isOnHold: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
internal func audioSourceDidChange(call: SignalCall, audioSource: AudioSource?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
// MARK: - Video
|
||||
|
||||
private func shouldHaveLocalVideoTrack() -> Bool {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.call else {
|
||||
return false
|
||||
@ -1544,7 +1544,7 @@ protocol CallServiceObserver: class {
|
||||
|
||||
//TODO only fire this when it's changed? as of right now it gets called whenever you e.g. lock the phone while it's incoming ringing.
|
||||
private func updateIsVideoEnabled() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.call else {
|
||||
return
|
||||
@ -1567,7 +1567,7 @@ protocol CallServiceObserver: class {
|
||||
|
||||
// The observer-related methods should be invoked on the main thread.
|
||||
func addObserverAndSyncState(observer: CallServiceObserver) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
observers.append(Weak(value: observer))
|
||||
|
||||
@ -1582,7 +1582,7 @@ protocol CallServiceObserver: class {
|
||||
|
||||
// The observer-related methods should be invoked on the main thread.
|
||||
func removeObserver(_ observer: CallServiceObserver) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
while let index = observers.index(where: { $0.value === observer }) {
|
||||
observers.remove(at: index)
|
||||
@ -1591,13 +1591,13 @@ protocol CallServiceObserver: class {
|
||||
|
||||
// The observer-related methods should be invoked on the main thread.
|
||||
func removeAllObservers() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
observers = []
|
||||
}
|
||||
|
||||
private func fireDidUpdateVideoTracks() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let call = self.call
|
||||
let localVideoTrack = self.localVideoTrack
|
||||
@ -1614,7 +1614,7 @@ protocol CallServiceObserver: class {
|
||||
|
||||
var activeCallTimer: Timer?
|
||||
func startCallTimer() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
if self.activeCallTimer != nil {
|
||||
owsFail("\(self.logTag) activeCallTimer should only be set once per call")
|
||||
@ -1660,7 +1660,7 @@ protocol CallServiceObserver: class {
|
||||
}
|
||||
|
||||
func stopAnyCallTimer() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
self.activeCallTimer?.invalidate()
|
||||
self.activeCallTimer = nil
|
||||
|
||||
@ -20,7 +20,7 @@ class NonCallKitCallUIAdaptee: NSObject, CallUIAdaptee {
|
||||
let hasManualRinger = true
|
||||
|
||||
required init(callService: CallService, notificationsAdapter: CallNotificationsAdapter) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
self.callService = callService
|
||||
self.notificationsAdapter = notificationsAdapter
|
||||
@ -29,7 +29,7 @@ class NonCallKitCallUIAdaptee: NSObject, CallUIAdaptee {
|
||||
}
|
||||
|
||||
func startOutgoingCall(handle: String) -> SignalCall {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let call = SignalCall.outgoingCall(localId: UUID(), remotePhoneNumber: handle)
|
||||
|
||||
@ -46,7 +46,7 @@ class NonCallKitCallUIAdaptee: NSObject, CallUIAdaptee {
|
||||
}
|
||||
|
||||
func reportIncomingCall(_ call: SignalCall, callerName: String) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(TAG) \(#function)")
|
||||
|
||||
@ -61,13 +61,13 @@ class NonCallKitCallUIAdaptee: NSObject, CallUIAdaptee {
|
||||
}
|
||||
|
||||
func reportMissedCall(_ call: SignalCall, callerName: String) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
notificationsAdapter.presentMissedCall(call, callerName: callerName)
|
||||
}
|
||||
|
||||
func answerCall(localId: UUID) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.callService.call else {
|
||||
owsFail("\(self.TAG) in \(#function) No current call.")
|
||||
@ -83,7 +83,7 @@ class NonCallKitCallUIAdaptee: NSObject, CallUIAdaptee {
|
||||
}
|
||||
|
||||
func answerCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard call.localId == self.callService.call?.localId else {
|
||||
owsFail("\(self.TAG) in \(#function) localId does not match current call")
|
||||
@ -95,7 +95,7 @@ class NonCallKitCallUIAdaptee: NSObject, CallUIAdaptee {
|
||||
}
|
||||
|
||||
func declineCall(localId: UUID) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let call = self.callService.call else {
|
||||
owsFail("\(self.TAG) in \(#function) No current call.")
|
||||
@ -111,7 +111,7 @@ class NonCallKitCallUIAdaptee: NSObject, CallUIAdaptee {
|
||||
}
|
||||
|
||||
func declineCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard call.localId == self.callService.call?.localId else {
|
||||
owsFail("\(self.TAG) in \(#function) localId does not match current call")
|
||||
@ -122,13 +122,13 @@ class NonCallKitCallUIAdaptee: NSObject, CallUIAdaptee {
|
||||
}
|
||||
|
||||
func recipientAcceptedCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
OWSAudioSession.shared.isRTCAudioEnabled = true
|
||||
}
|
||||
|
||||
func localHangupCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
// If both parties hang up at the same moment,
|
||||
// call might already be nil.
|
||||
@ -141,25 +141,25 @@ class NonCallKitCallUIAdaptee: NSObject, CallUIAdaptee {
|
||||
}
|
||||
|
||||
internal func remoteDidHangupCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(TAG) in \(#function) is no-op")
|
||||
}
|
||||
|
||||
internal func remoteBusy(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(TAG) in \(#function) is no-op")
|
||||
}
|
||||
|
||||
internal func failCall(_ call: SignalCall, error: CallError) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(TAG) in \(#function) is no-op")
|
||||
}
|
||||
|
||||
func setIsMuted(call: SignalCall, isMuted: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard call.localId == self.callService.call?.localId else {
|
||||
owsFail("\(self.TAG) in \(#function) localId does not match current call")
|
||||
@ -170,7 +170,7 @@ class NonCallKitCallUIAdaptee: NSObject, CallUIAdaptee {
|
||||
}
|
||||
|
||||
func setHasLocalVideo(call: SignalCall, hasLocalVideo: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard call.localId == self.callService.call?.localId else {
|
||||
owsFail("\(self.TAG) in \(#function) localId does not match current call")
|
||||
|
||||
@ -123,7 +123,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
private var cameraConstraints: RTCMediaConstraints
|
||||
|
||||
init(iceServers: [RTCIceServer], delegate: PeerConnectionClientDelegate, callDirection: CallDirection, useTurnOnly: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
self.iceServers = iceServers
|
||||
self.delegate = delegate
|
||||
@ -142,7 +142,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
let connectionConstraintsDict = ["DtlsSrtpKeyAgreement": "true"]
|
||||
connectionConstraints = RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints: connectionConstraintsDict)
|
||||
|
||||
audioConstraints = RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints:nil)
|
||||
audioConstraints = RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints: nil)
|
||||
cameraConstraints = RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints: nil)
|
||||
|
||||
super.init()
|
||||
@ -163,7 +163,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
// MARK: - Media Streams
|
||||
|
||||
private func createSignalingDataChannel() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let configuration = RTCDataChannelConfiguration()
|
||||
// Insist upon an "ordered" TCP data channel for delivery reliability.
|
||||
@ -179,7 +179,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
// MARK: Video
|
||||
|
||||
fileprivate func createVideoSender() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(TAG) in \(#function)")
|
||||
assert(self.videoSender == nil, "\(#function) should only be called once.")
|
||||
@ -190,8 +190,8 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
}
|
||||
|
||||
// TODO: We could cap the maximum video size.
|
||||
let cameraConstraints = RTCMediaConstraints(mandatoryConstraints:nil,
|
||||
optionalConstraints:nil)
|
||||
let cameraConstraints = RTCMediaConstraints(mandatoryConstraints: nil,
|
||||
optionalConstraints: nil)
|
||||
|
||||
// TODO: Revisit the cameraConstraints.
|
||||
let videoSource = factory.avFoundationVideoSource(with: cameraConstraints)
|
||||
@ -213,7 +213,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
}
|
||||
|
||||
public func setLocalVideoEnabled(enabled: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
PeerConnectionClient.signalingQueue.async {
|
||||
guard self.peerConnection != nil else {
|
||||
@ -253,7 +253,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
// MARK: Audio
|
||||
|
||||
fileprivate func createAudioSender() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(TAG) in \(#function)")
|
||||
assert(self.audioSender == nil, "\(#function) should only be called once.")
|
||||
@ -275,7 +275,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
}
|
||||
|
||||
public func setAudioEnabled(enabled: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
PeerConnectionClient.signalingQueue.async {
|
||||
guard self.peerConnection != nil else {
|
||||
@ -299,19 +299,19 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
"OfferToReceiveAudio": "true",
|
||||
"OfferToReceiveVideo": "true"
|
||||
]
|
||||
return RTCMediaConstraints(mandatoryConstraints:mandatoryConstraints, optionalConstraints:nil)
|
||||
return RTCMediaConstraints(mandatoryConstraints: mandatoryConstraints, optionalConstraints: nil)
|
||||
}
|
||||
|
||||
public func createOffer() -> Promise<HardenedRTCSessionDescription> {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
return Promise { fulfill, reject in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
PeerConnectionClient.signalingQueue.async {
|
||||
guard self.peerConnection != nil else {
|
||||
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
||||
reject(NSError(domain:"Obsolete client", code:0, userInfo:nil))
|
||||
reject(NSError(domain: "Obsolete client", code: 0, userInfo: nil))
|
||||
return
|
||||
}
|
||||
|
||||
@ -319,7 +319,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
PeerConnectionClient.signalingQueue.async {
|
||||
guard self.peerConnection != nil else {
|
||||
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
||||
reject(NSError(domain:"Obsolete client", code:0, userInfo:nil))
|
||||
reject(NSError(domain: "Obsolete client", code: 0, userInfo: nil))
|
||||
return
|
||||
}
|
||||
guard error == nil else {
|
||||
@ -345,18 +345,18 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
return PromiseKit.wrap { resolve in
|
||||
self.assertOnSignalingQueue()
|
||||
Logger.verbose("\(self.TAG) setting local session description: \(sessionDescription)")
|
||||
self.peerConnection.setLocalDescription(sessionDescription.rtcSessionDescription, completionHandler:resolve)
|
||||
self.peerConnection.setLocalDescription(sessionDescription.rtcSessionDescription, completionHandler: resolve)
|
||||
}
|
||||
}
|
||||
|
||||
public func setLocalSessionDescription(_ sessionDescription: HardenedRTCSessionDescription) -> Promise<Void> {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
return Promise { fulfill, reject in
|
||||
PeerConnectionClient.signalingQueue.async {
|
||||
guard self.peerConnection != nil else {
|
||||
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
||||
reject(NSError(domain:"Obsolete client", code:0, userInfo:nil))
|
||||
reject(NSError(domain: "Obsolete client", code: 0, userInfo: nil))
|
||||
return
|
||||
}
|
||||
Logger.verbose("\(self.TAG) setting local session description: \(sessionDescription)")
|
||||
@ -373,7 +373,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
}
|
||||
|
||||
public func negotiateSessionDescription(remoteDescription: RTCSessionDescription, constraints: RTCMediaConstraints) -> Promise<HardenedRTCSessionDescription> {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
return setRemoteSessionDescription(remoteDescription)
|
||||
.then(on: PeerConnectionClient.signalingQueue) {
|
||||
@ -382,13 +382,13 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
}
|
||||
|
||||
public func setRemoteSessionDescription(_ sessionDescription: RTCSessionDescription) -> Promise<Void> {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
return Promise { fulfill, reject in
|
||||
PeerConnectionClient.signalingQueue.async {
|
||||
guard self.peerConnection != nil else {
|
||||
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
||||
reject(NSError(domain:"Obsolete client", code:0, userInfo:nil))
|
||||
reject(NSError(domain: "Obsolete client", code: 0, userInfo: nil))
|
||||
return
|
||||
}
|
||||
Logger.verbose("\(self.TAG) setting remote description: \(sessionDescription)")
|
||||
@ -412,7 +412,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
|
||||
guard self.peerConnection != nil else {
|
||||
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
||||
reject(NSError(domain:"Obsolete client", code:0, userInfo:nil))
|
||||
reject(NSError(domain: "Obsolete client", code: 0, userInfo: nil))
|
||||
return
|
||||
}
|
||||
|
||||
@ -422,7 +422,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
PeerConnectionClient.signalingQueue.async {
|
||||
guard self.peerConnection != nil else {
|
||||
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
||||
reject(NSError(domain:"Obsolete client", code:0, userInfo:nil))
|
||||
reject(NSError(domain: "Obsolete client", code: 0, userInfo: nil))
|
||||
return
|
||||
}
|
||||
guard error == nil else {
|
||||
@ -462,7 +462,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
}
|
||||
|
||||
public func terminate() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.debug("\(TAG) in \(#function)")
|
||||
|
||||
PeerConnectionClient.signalingQueue.async {
|
||||
@ -520,7 +520,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
}
|
||||
|
||||
public func sendDataChannelMessage(data: Data, description: String, isCritical: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
PeerConnectionClient.signalingQueue.async {
|
||||
guard self.peerConnection != nil else {
|
||||
@ -548,7 +548,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
} else {
|
||||
Logger.warn("\(self.TAG) sendDataChannelMessage failed: \(description)")
|
||||
if isCritical {
|
||||
OWSProdError(OWSAnalyticsEvents.peerConnectionClientErrorSendDataChannelMessageFailed(), file:#file, function:#function, line:#line)
|
||||
OWSProdError(OWSAnalyticsEvents.peerConnectionClientErrorSendDataChannelMessageFailed(), file: #file, function: #function, line: #line)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -570,7 +570,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
}
|
||||
Logger.debug("\(self.TAG) dataChannel didReceiveMessageWith buffer:\(buffer)")
|
||||
|
||||
guard let dataChannelMessage = OWSWebRTCProtosData.parse(from:buffer.data) else {
|
||||
guard let dataChannelMessage = OWSWebRTCProtosData.parse(from: buffer.data) else {
|
||||
// TODO can't proto parsings throw an exception? Is it just being lost in the Objc->Swift?
|
||||
Logger.error("\(self.TAG) failed to parse dataProto")
|
||||
return
|
||||
@ -745,7 +745,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
// MARK: Test-only accessors
|
||||
|
||||
internal func peerConnectionForTests() -> RTCPeerConnection {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
var result: RTCPeerConnection? = nil
|
||||
PeerConnectionClient.signalingQueue.sync {
|
||||
@ -756,7 +756,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
}
|
||||
|
||||
internal func dataChannelForTests() -> RTCDataChannel {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
var result: RTCDataChannel? = nil
|
||||
PeerConnectionClient.signalingQueue.sync {
|
||||
@ -767,7 +767,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
||||
}
|
||||
|
||||
internal func flushSignalingQueueForTests() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
PeerConnectionClient.signalingQueue.sync {
|
||||
// Noop.
|
||||
@ -793,12 +793,12 @@ class HardenedRTCSessionDescription {
|
||||
var description = rtcSessionDescription.sdp
|
||||
|
||||
// Enforce Constant bit rate.
|
||||
let cbrRegex = try! NSRegularExpression(pattern:"(a=fmtp:111 ((?!cbr=).)*)\r?\n", options:.caseInsensitive)
|
||||
let cbrRegex = try! NSRegularExpression(pattern: "(a=fmtp:111 ((?!cbr=).)*)\r?\n", options: .caseInsensitive)
|
||||
description = cbrRegex.stringByReplacingMatches(in: description, options: [], range: NSMakeRange(0, description.count), withTemplate: "$1;cbr=1\r\n")
|
||||
|
||||
// Strip plaintext audio-level details
|
||||
// https://tools.ietf.org/html/rfc6464
|
||||
let audioLevelRegex = try! NSRegularExpression(pattern:".+urn:ietf:params:rtp-hdrext:ssrc-audio-level.*\r?\n", options:.caseInsensitive)
|
||||
let audioLevelRegex = try! NSRegularExpression(pattern: ".+urn:ietf:params:rtp-hdrext:ssrc-audio-level.*\r?\n", options: .caseInsensitive)
|
||||
description = audioLevelRegex.stringByReplacingMatches(in: description, options: [], range: NSMakeRange(0, description.count), withTemplate: "")
|
||||
|
||||
return RTCSessionDescription.init(type: rtcSessionDescription.type, sdp: description)
|
||||
|
||||
@ -64,7 +64,7 @@ protocol CallObserver: class {
|
||||
|
||||
var callRecord: TSCall? {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
assert(oldValue == nil)
|
||||
|
||||
updateCallRecordType()
|
||||
@ -73,7 +73,7 @@ protocol CallObserver: class {
|
||||
|
||||
var hasLocalVideo = false {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
for observer in observers {
|
||||
observer.value?.hasLocalVideoDidChange(call: self, hasLocalVideo: hasLocalVideo)
|
||||
@ -83,7 +83,7 @@ protocol CallObserver: class {
|
||||
|
||||
var state: CallState {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.debug("\(TAG) state changed: \(oldValue) -> \(self.state) for call: \(self.identifiersForLogs)")
|
||||
|
||||
// Update connectedDate
|
||||
@ -105,7 +105,7 @@ protocol CallObserver: class {
|
||||
|
||||
var isMuted = false {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(TAG) muted changed: \(oldValue) -> \(self.isMuted)")
|
||||
|
||||
@ -119,8 +119,8 @@ protocol CallObserver: class {
|
||||
|
||||
var audioSource: AudioSource? = nil {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
Logger.debug("\(TAG) audioSource changed: \(String(describing:oldValue)) -> \(String(describing: audioSource))")
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.debug("\(TAG) audioSource changed: \(String(describing: oldValue)) -> \(String(describing: audioSource))")
|
||||
|
||||
for observer in observers {
|
||||
observer.value?.audioSourceDidChange(call: self, audioSource: audioSource)
|
||||
@ -138,7 +138,7 @@ protocol CallObserver: class {
|
||||
|
||||
var isOnHold = false {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.debug("\(TAG) isOnHold changed: \(oldValue) -> \(self.isOnHold)")
|
||||
|
||||
for observer in observers {
|
||||
@ -179,7 +179,7 @@ protocol CallObserver: class {
|
||||
// -
|
||||
|
||||
func addObserverAndSyncState(observer: CallObserver) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
observers.append(Weak(value: observer))
|
||||
|
||||
@ -188,7 +188,7 @@ protocol CallObserver: class {
|
||||
}
|
||||
|
||||
func removeObserver(_ observer: CallObserver) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
while let index = observers.index(where: { $0.value === observer }) {
|
||||
observers.remove(at: index)
|
||||
@ -196,13 +196,13 @@ protocol CallObserver: class {
|
||||
}
|
||||
|
||||
func removeAllObservers() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
observers = []
|
||||
}
|
||||
|
||||
private func updateCallRecordType() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let callRecord = self.callRecord else {
|
||||
return
|
||||
|
||||
@ -22,7 +22,7 @@ final class CallKitCallManager: NSObject {
|
||||
static let kAnonymousCallHandlePrefix = "Signal:"
|
||||
|
||||
required init(showNamesOnCallScreen: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
self.showNamesOnCallScreen = showNamesOnCallScreen
|
||||
super.init()
|
||||
|
||||
@ -36,7 +36,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
private static var _sharedProvider: CXProvider?
|
||||
class func sharedProvider(useSystemCallLog: Bool) -> CXProvider {
|
||||
let configuration = buildProviderConfiguration(useSystemCallLog: useSystemCallLog)
|
||||
|
||||
|
||||
if let sharedProvider = self._sharedProvider {
|
||||
sharedProvider.configuration = configuration
|
||||
return sharedProvider
|
||||
@ -47,7 +47,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
return provider
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// The app's provider configuration, representing its CallKit capabilities
|
||||
class func buildProviderConfiguration(useSystemCallLog: Bool) -> CXProviderConfiguration {
|
||||
let localizedName = NSLocalizedString("APPLICATION_NAME", comment: "Name of application")
|
||||
@ -79,7 +79,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
}
|
||||
|
||||
init(callService: CallService, contactsManager: OWSContactsManager, notificationsAdapter: CallNotificationsAdapter, showNamesOnCallScreen: Bool, useSystemCallLog: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(self.TAG) \(#function)")
|
||||
|
||||
@ -103,7 +103,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
// MARK: CallUIAdaptee
|
||||
|
||||
func startOutgoingCall(handle: String) -> SignalCall {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
let call = SignalCall.outgoingCall(localId: UUID(), remotePhoneNumber: handle)
|
||||
@ -121,7 +121,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
|
||||
// Called from CallService after call has ended to clean up any remaining CallKit call state.
|
||||
func failCall(_ call: SignalCall, error: CallError) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
switch error {
|
||||
@ -135,7 +135,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
}
|
||||
|
||||
func reportIncomingCall(_ call: SignalCall, callerName: String) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
// Construct a CXCallUpdate describing the incoming call, including the caller.
|
||||
@ -171,34 +171,34 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
}
|
||||
|
||||
func answerCall(localId: UUID) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
owsFail("\(self.TAG) \(#function) CallKit should answer calls via system call screen, not via notifications.")
|
||||
}
|
||||
|
||||
func answerCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
callManager.answer(call: call)
|
||||
}
|
||||
|
||||
func declineCall(localId: UUID) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
owsFail("\(self.TAG) \(#function) CallKit should decline calls via system call screen, not via notifications.")
|
||||
}
|
||||
|
||||
func declineCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
callManager.localHangup(call: call)
|
||||
}
|
||||
|
||||
func recipientAcceptedCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
self.provider.reportOutgoingCall(with: call.localId, connectedAt: nil)
|
||||
@ -210,35 +210,35 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
}
|
||||
|
||||
func localHangupCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
callManager.localHangup(call: call)
|
||||
}
|
||||
|
||||
func remoteDidHangupCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
provider.reportCall(with: call.localId, endedAt: nil, reason: CXCallEndedReason.remoteEnded)
|
||||
}
|
||||
|
||||
func remoteBusy(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
provider.reportCall(with: call.localId, endedAt: nil, reason: CXCallEndedReason.unanswered)
|
||||
}
|
||||
|
||||
func setIsMuted(call: SignalCall, isMuted: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
callManager.setIsMuted(call: call, isMuted: isMuted)
|
||||
}
|
||||
|
||||
func setHasLocalVideo(call: SignalCall, hasLocalVideo: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.debug("\(self.TAG) \(#function)")
|
||||
|
||||
let update = CXCallUpdate()
|
||||
@ -253,7 +253,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
// MARK: CXProviderDelegate
|
||||
|
||||
func providerDidReset(_ provider: CXProvider) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.TAG) \(#function)")
|
||||
|
||||
// End any ongoing calls if the provider resets, and remove them from the app's list of calls,
|
||||
@ -265,7 +265,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
}
|
||||
|
||||
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.info("\(TAG) in \(#function) CXStartCallAction")
|
||||
|
||||
@ -294,7 +294,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
}
|
||||
|
||||
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.info("\(TAG) Received \(#function) CXAnswerCallAction")
|
||||
// Retrieve the instance corresponding to the action's call UUID
|
||||
@ -309,7 +309,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
}
|
||||
|
||||
public func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.info("\(TAG) Received \(#function) CXEndCallAction")
|
||||
guard let call = callManager.callWithLocalId(action.callUUID) else {
|
||||
@ -328,7 +328,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
}
|
||||
|
||||
public func provider(_ provider: CXProvider, perform action: CXSetHeldCallAction) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.info("\(TAG) Received \(#function) CXSetHeldCallAction")
|
||||
guard let call = callManager.callWithLocalId(action.callUUID) else {
|
||||
@ -344,7 +344,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
}
|
||||
|
||||
public func provider(_ provider: CXProvider, perform action: CXSetMutedCallAction) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.info("\(TAG) Received \(#function) CXSetMutedCallAction")
|
||||
guard let call = callManager.callWithLocalId(action.callUUID) else {
|
||||
@ -358,19 +358,19 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
}
|
||||
|
||||
public func provider(_ provider: CXProvider, perform action: CXSetGroupCallAction) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.warn("\(TAG) unimplemented \(#function) for CXSetGroupCallAction")
|
||||
}
|
||||
|
||||
public func provider(_ provider: CXProvider, perform action: CXPlayDTMFCallAction) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.warn("\(TAG) unimplemented \(#function) for CXPlayDTMFCallAction")
|
||||
}
|
||||
|
||||
func provider(_ provider: CXProvider, timedOutPerforming action: CXAction) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
owsFail("\(TAG) Timed out \(#function) while performing \(action)")
|
||||
|
||||
@ -378,7 +378,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
}
|
||||
|
||||
func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(TAG) Received \(#function)")
|
||||
|
||||
@ -387,7 +387,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
|
||||
}
|
||||
|
||||
func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(TAG) Received \(#function)")
|
||||
OWSAudioSession.shared.isRTCAudioEnabled = false
|
||||
|
||||
@ -34,7 +34,7 @@ protocol CallUIAdaptee {
|
||||
// Shared default implementations
|
||||
extension CallUIAdaptee {
|
||||
internal func showCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let callViewController = CallViewController(call: call)
|
||||
callViewController.modalTransitionStyle = .crossDissolve
|
||||
@ -51,13 +51,13 @@ extension CallUIAdaptee {
|
||||
}
|
||||
|
||||
internal func reportMissedCall(_ call: SignalCall, callerName: String) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
notificationsAdapter.presentMissedCall(call, callerName: callerName)
|
||||
}
|
||||
|
||||
internal func startAndShowOutgoingCall(recipientId: String) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard self.callService.call == nil else {
|
||||
Logger.info("unexpectedly found an existing call when trying to start outgoing call: \(recipientId)")
|
||||
@ -82,7 +82,7 @@ extension CallUIAdaptee {
|
||||
internal let audioService: CallAudioService
|
||||
|
||||
required init(callService: CallService, contactsManager: OWSContactsManager, notificationsAdapter: CallNotificationsAdapter) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
self.contactsManager = contactsManager
|
||||
if Platform.isSimulator {
|
||||
@ -121,7 +121,7 @@ extension CallUIAdaptee {
|
||||
}
|
||||
|
||||
internal func reportIncomingCall(_ call: SignalCall, thread: TSContactThread) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
// make sure we don't terminate audio session during call
|
||||
OWSAudioSession.shared.startAudioActivity(call.audioActivity)
|
||||
@ -131,45 +131,45 @@ extension CallUIAdaptee {
|
||||
}
|
||||
|
||||
internal func reportMissedCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let callerName = self.contactsManager.displayName(forPhoneIdentifier: call.remotePhoneNumber)
|
||||
adaptee.reportMissedCall(call, callerName: callerName)
|
||||
}
|
||||
|
||||
internal func startOutgoingCall(handle: String) -> SignalCall {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let call = adaptee.startOutgoingCall(handle: handle)
|
||||
return call
|
||||
}
|
||||
|
||||
internal func answerCall(localId: UUID) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
adaptee.answerCall(localId: localId)
|
||||
}
|
||||
|
||||
internal func answerCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
adaptee.answerCall(call)
|
||||
}
|
||||
|
||||
internal func declineCall(localId: UUID) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
adaptee.declineCall(localId: localId)
|
||||
}
|
||||
|
||||
internal func declineCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
adaptee.declineCall(call)
|
||||
}
|
||||
|
||||
internal func didTerminateCall(_ call: SignalCall?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
if let call = call {
|
||||
OWSAudioSession.shared.endAudioActivity(call.audioActivity)
|
||||
@ -177,62 +177,62 @@ extension CallUIAdaptee {
|
||||
}
|
||||
|
||||
internal func startAndShowOutgoingCall(recipientId: String) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
adaptee.startAndShowOutgoingCall(recipientId: recipientId)
|
||||
}
|
||||
|
||||
internal func recipientAcceptedCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
adaptee.recipientAcceptedCall(call)
|
||||
}
|
||||
|
||||
internal func remoteDidHangupCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
adaptee.remoteDidHangupCall(call)
|
||||
}
|
||||
|
||||
internal func remoteBusy(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
adaptee.remoteBusy(call)
|
||||
}
|
||||
|
||||
internal func localHangupCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
adaptee.localHangupCall(call)
|
||||
}
|
||||
|
||||
internal func failCall(_ call: SignalCall, error: CallError) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
adaptee.failCall(call, error: error)
|
||||
}
|
||||
|
||||
internal func showCall(_ call: SignalCall) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
adaptee.showCall(call)
|
||||
}
|
||||
|
||||
internal func setIsMuted(call: SignalCall, isMuted: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
// With CallKit, muting is handled by a CXAction, so it must go through the adaptee
|
||||
adaptee.setIsMuted(call: call, isMuted: isMuted)
|
||||
}
|
||||
|
||||
internal func setHasLocalVideo(call: SignalCall, hasLocalVideo: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
adaptee.setHasLocalVideo(call: call, hasLocalVideo: hasLocalVideo)
|
||||
}
|
||||
|
||||
internal func setAudioSource(call: SignalCall, audioSource: AudioSource?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
// AudioSource is not handled by CallKit (e.g. there is no CXAction), so we handle it w/o going through the
|
||||
// adaptee, relying on the AudioService CallObserver to put the system in a state consistent with the call's
|
||||
@ -242,7 +242,7 @@ extension CallUIAdaptee {
|
||||
|
||||
// CallKit handles ringing state on it's own. But for non-call kit we trigger ringing start/stop manually.
|
||||
internal var hasManualRinger: Bool {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
return adaptee.hasManualRinger
|
||||
}
|
||||
@ -250,7 +250,7 @@ extension CallUIAdaptee {
|
||||
// MARK: - CallServiceObserver
|
||||
|
||||
internal func didUpdateCall(call: SignalCall?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
call?.addObserverAndSyncState(observer: audioService)
|
||||
}
|
||||
@ -258,8 +258,8 @@ extension CallUIAdaptee {
|
||||
internal func didUpdateVideoTracks(call: SignalCall?,
|
||||
localVideoTrack: RTCVideoTrack?,
|
||||
remoteVideoTrack: RTCVideoTrack?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
audioService.didUpdateVideoTracks(call:call)
|
||||
audioService.didUpdateVideoTracks(call: call)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@ -34,7 +34,7 @@ class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
|
||||
// MARK: - Call Handlers
|
||||
|
||||
public func receivedOffer(_ offer: OWSSignalServiceProtosCallMessageOffer, from callerId: String) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard offer.hasId() else {
|
||||
owsFail("no callId in \(#function)")
|
||||
return
|
||||
@ -45,7 +45,7 @@ class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
|
||||
}
|
||||
|
||||
public func receivedAnswer(_ answer: OWSSignalServiceProtosCallMessageAnswer, from callerId: String) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard answer.hasId() else {
|
||||
owsFail("no callId in \(#function)")
|
||||
return
|
||||
@ -56,7 +56,7 @@ class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
|
||||
}
|
||||
|
||||
public func receivedIceUpdate(_ iceUpdate: OWSSignalServiceProtosCallMessageIceUpdate, from callerId: String) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard iceUpdate.hasId() else {
|
||||
owsFail("no callId in \(#function)")
|
||||
return
|
||||
@ -72,7 +72,7 @@ class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
|
||||
}
|
||||
|
||||
public func receivedHangup(_ hangup: OWSSignalServiceProtosCallMessageHangup, from callerId: String) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard hangup.hasId() else {
|
||||
owsFail("no callId in \(#function)")
|
||||
return
|
||||
@ -83,7 +83,7 @@ class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
|
||||
}
|
||||
|
||||
public func receivedBusy(_ busy: OWSSignalServiceProtosCallMessageBusy, from callerId: String) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard busy.hasId() else {
|
||||
owsFail("no callId in \(#function)")
|
||||
return
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
@ -53,7 +53,7 @@ public enum PushRegistrationError: Error {
|
||||
|
||||
return self.registerUserNotificationSettings().then {
|
||||
guard !Platform.isSimulator else {
|
||||
throw PushRegistrationError.pushNotSupported(description:"Push not supported on simulators")
|
||||
throw PushRegistrationError.pushNotSupported(description: "Push not supported on simulators")
|
||||
}
|
||||
|
||||
return self.registerForVanillaPushToken().then { vanillaPushToken in
|
||||
@ -135,7 +135,7 @@ public enum PushRegistrationError: Error {
|
||||
// return any requested push tokens. We don't consider the notifications settings registration
|
||||
// *complete* until AppDelegate#didRegisterUserNotificationSettings is called.
|
||||
private func registerUserNotificationSettings() -> Promise<Void> {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard self.userNotificationSettingsPromise == nil else {
|
||||
let promise = self.userNotificationSettingsPromise!
|
||||
@ -181,7 +181,7 @@ public enum PushRegistrationError: Error {
|
||||
|
||||
private func registerForVanillaPushToken() -> Promise<String> {
|
||||
Logger.info("\(self.logTag) in \(#function)")
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard self.vanillaTokenPromise == nil else {
|
||||
let promise = vanillaTokenPromise!
|
||||
@ -231,7 +231,7 @@ public enum PushRegistrationError: Error {
|
||||
}
|
||||
|
||||
private func registerForVoipPushToken() -> Promise<String> {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
Logger.info("\(self.logTag) in \(#function)")
|
||||
|
||||
guard self.voipTokenPromise == nil else {
|
||||
|
||||
@ -32,7 +32,7 @@ class GiphyAssetSegment {
|
||||
// This state should only be accessed on the main thread.
|
||||
public var state: GiphyAssetSegmentState = .waiting {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ enum GiphyAssetRequestState: UInt {
|
||||
public var state: GiphyAssetRequestState = .waiting
|
||||
public var contentLength: Int = 0 {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
assert(oldValue == 0)
|
||||
assert(contentLength > 0)
|
||||
|
||||
@ -151,7 +151,7 @@ enum GiphyAssetRequestState: UInt {
|
||||
}
|
||||
|
||||
private func segmentSize() -> UInt {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let contentLength = UInt(self.contentLength)
|
||||
guard contentLength > 0 else {
|
||||
@ -175,7 +175,7 @@ enum GiphyAssetRequestState: UInt {
|
||||
}
|
||||
|
||||
private func createSegments() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let segmentLength = segmentSize()
|
||||
guard segmentLength > 0 else {
|
||||
@ -205,7 +205,7 @@ enum GiphyAssetRequestState: UInt {
|
||||
}
|
||||
|
||||
private func firstSegmentWithState(state: GiphyAssetSegmentState) -> GiphyAssetSegment? {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
for segment in segments {
|
||||
guard segment.state != .failed else {
|
||||
@ -220,13 +220,13 @@ enum GiphyAssetRequestState: UInt {
|
||||
}
|
||||
|
||||
public func firstWaitingSegment() -> GiphyAssetSegment? {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
return firstSegmentWithState(state: .waiting)
|
||||
}
|
||||
|
||||
public func downloadingSegmentsCount() -> UInt {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
var result: UInt = 0
|
||||
for segment in segments {
|
||||
@ -242,7 +242,7 @@ enum GiphyAssetRequestState: UInt {
|
||||
}
|
||||
|
||||
public func areAllSegmentsComplete() -> Bool {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
for segment in segments {
|
||||
guard segment.state == .complete else {
|
||||
@ -297,7 +297,7 @@ enum GiphyAssetRequestState: UInt {
|
||||
}
|
||||
|
||||
public func cancel() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
wasCancelled = true
|
||||
contentLengthTask?.cancel()
|
||||
@ -312,14 +312,14 @@ enum GiphyAssetRequestState: UInt {
|
||||
}
|
||||
|
||||
private func clearCallbacks() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
success = nil
|
||||
failure = nil
|
||||
}
|
||||
|
||||
public func requestDidSucceed(asset: GiphyAsset) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
success?(self, asset)
|
||||
|
||||
@ -328,7 +328,7 @@ enum GiphyAssetRequestState: UInt {
|
||||
}
|
||||
|
||||
public func requestDidFail() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
failure?(self)
|
||||
|
||||
@ -403,7 +403,7 @@ extension URLSessionTask {
|
||||
|
||||
// Force usage as a singleton
|
||||
override private init() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
super.init()
|
||||
|
||||
@ -419,7 +419,7 @@ extension URLSessionTask {
|
||||
private let kGiphyBaseURL = "https://api.giphy.com/"
|
||||
|
||||
private lazy var giphyDownloadSession: URLSession = {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let configuration = GiphyAPI.giphySessionConfiguration()
|
||||
configuration.urlCache = nil
|
||||
@ -451,7 +451,7 @@ extension URLSessionTask {
|
||||
priority: GiphyRequestPriority,
|
||||
success:@escaping ((GiphyAssetRequest?, GiphyAsset) -> Void),
|
||||
failure:@escaping ((GiphyAssetRequest) -> Void)) -> GiphyAssetRequest? {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
if let asset = assetMap.get(key: rendition.url) {
|
||||
// Synchronous cache hit.
|
||||
@ -478,7 +478,7 @@ extension URLSessionTask {
|
||||
}
|
||||
|
||||
public func cancelAllRequests() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.verbose("\(self.TAG) cancelAllRequests")
|
||||
|
||||
@ -537,7 +537,7 @@ extension URLSessionTask {
|
||||
}
|
||||
|
||||
private func removeAssetRequestFromQueue(assetRequest: GiphyAssetRequest) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard assetRequestQueue.contains(assetRequest) else {
|
||||
Logger.warn("\(TAG) could not remove asset request from queue: \(assetRequest.rendition.url)")
|
||||
@ -560,7 +560,7 @@ extension URLSessionTask {
|
||||
// * Complete/cancel asset requests if possible.
|
||||
//
|
||||
private func processRequestQueueSync() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let assetRequest = popNextAssetRequest() else {
|
||||
return
|
||||
@ -671,7 +671,7 @@ extension URLSessionTask {
|
||||
// * Need to download the content length.
|
||||
// * Need to download at least one of its segments.
|
||||
private func popNextAssetRequest() -> GiphyAssetRequest? {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let kMaxAssetRequestCount: UInt = 3
|
||||
let kMaxAssetRequestsPerAssetCount: UInt = kMaxAssetRequestCount - 1
|
||||
|
||||
@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)applicationWillEnterForeground:(NSNotification *)notification
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
|
||||
|
||||
@ -63,7 +63,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)applicationDidEnterBackground:(NSNotification *)notification
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
|
||||
[DDLog flushLog];
|
||||
@ -73,7 +73,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)applicationWillResignActive:(NSNotification *)notification
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
|
||||
[DDLog flushLog];
|
||||
@ -83,7 +83,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)notification
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
|
||||
|
||||
@ -92,7 +92,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification *)notification
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
DDLogInfo(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
|
||||
[DDLog flushLog];
|
||||
|
||||
@ -31,7 +31,7 @@ public class OWSBackupLazyRestoreJob: NSObject {
|
||||
}
|
||||
|
||||
private func runAsync() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
DispatchQueue.global().async {
|
||||
self.restoreAttachments()
|
||||
|
||||
@ -65,7 +65,7 @@ import LocalAuthentication
|
||||
}
|
||||
|
||||
func didBecomeActive() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
ignoreUnlockUntilActive = false
|
||||
}
|
||||
@ -73,7 +73,7 @@ import LocalAuthentication
|
||||
// MARK: - Properties
|
||||
|
||||
@objc public func isScreenLockEnabled() -> Bool {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
if !OWSStorage.isStorageReady() {
|
||||
owsFail("\(logTag) accessed screen lock state before storage is ready.")
|
||||
@ -84,7 +84,7 @@ import LocalAuthentication
|
||||
}
|
||||
|
||||
private func setIsScreenLockEnabled(value: Bool) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
assert(OWSStorage.isStorageReady())
|
||||
|
||||
let isEnabling = value && !isScreenLockEnabled()
|
||||
@ -98,7 +98,7 @@ import LocalAuthentication
|
||||
}
|
||||
|
||||
@objc public func screenLockTimeout() -> TimeInterval {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
if !OWSStorage.isStorageReady() {
|
||||
owsFail("\(logTag) accessed screen lock state before storage is ready.")
|
||||
@ -109,7 +109,7 @@ import LocalAuthentication
|
||||
}
|
||||
|
||||
@objc public func setScreenLockTimeout(_ value: TimeInterval) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
assert(OWSStorage.isStorageReady())
|
||||
|
||||
self.dbConnection.setDouble(value, forKey: OWSScreenLock_Key_ScreenLockTimeoutSeconds, inCollection: OWSScreenLock_Collection)
|
||||
@ -127,7 +127,7 @@ import LocalAuthentication
|
||||
tryToVerifyLocalAuthentication(localizedReason: NSLocalizedString("SCREEN_LOCK_REASON_ENABLE_SCREEN_LOCK",
|
||||
comment: "Description of how and why Signal iOS uses Touch ID/Face ID/Phone Passcode to enable 'screen lock'."),
|
||||
completion: { (outcome: OWSScreenLockOutcome) in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
switch outcome {
|
||||
case .failure(let error):
|
||||
@ -151,7 +151,7 @@ import LocalAuthentication
|
||||
tryToVerifyLocalAuthentication(localizedReason: NSLocalizedString("SCREEN_LOCK_REASON_DISABLE_SCREEN_LOCK",
|
||||
comment: "Description of how and why Signal iOS uses Touch ID/Face ID/Phone Passcode to disable 'screen lock'."),
|
||||
completion: { (outcome: OWSScreenLockOutcome) in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
switch outcome {
|
||||
case .failure(let error):
|
||||
@ -188,7 +188,7 @@ import LocalAuthentication
|
||||
tryToVerifyLocalAuthentication(localizedReason: NSLocalizedString("SCREEN_LOCK_REASON_UNLOCK_SCREEN_LOCK",
|
||||
comment: "Description of how and why Signal iOS uses Touch ID/Face ID/Phone Passcode to unlock 'screen lock'."),
|
||||
completion: { (outcome: OWSScreenLockOutcome) in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
switch outcome {
|
||||
case .failure(let error):
|
||||
@ -219,7 +219,7 @@ import LocalAuthentication
|
||||
// isScreenLockEnabled.
|
||||
private func tryToVerifyLocalAuthentication(localizedReason: String,
|
||||
completion completionParam: @escaping ((OWSScreenLockOutcome) -> Void)) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
// Ensure completion is always called on the main thread.
|
||||
let completion = { (outcome: OWSScreenLockOutcome) in
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
@ -55,14 +55,14 @@ import SignalServiceKit
|
||||
self.horizontalBarLayer = CAShapeLayer()
|
||||
self.progressLayer = CAShapeLayer()
|
||||
|
||||
super.init(frame:CGRect.zero)
|
||||
super.init(frame: CGRect.zero)
|
||||
|
||||
self.layer.addSublayer(self.horizontalBarLayer)
|
||||
self.layer.addSublayer(self.progressLayer)
|
||||
}
|
||||
|
||||
internal func updateSubviews() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
self.horizontalBarLayer.frame = self.bounds
|
||||
self.progressLayer.frame = self.bounds
|
||||
@ -71,19 +71,19 @@ import SignalServiceKit
|
||||
}
|
||||
|
||||
internal func updateContent() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let horizontalBarPath = UIBezierPath()
|
||||
let horizontalBarHeightFraction = CGFloat(0.25)
|
||||
let horizontalBarHeight = bounds.size.height * horizontalBarHeightFraction
|
||||
horizontalBarPath.append(UIBezierPath(rect: CGRect(x: 0, y:(bounds.size.height - horizontalBarHeight) * 0.5, width:bounds.size.width, height:horizontalBarHeight)))
|
||||
horizontalBarPath.append(UIBezierPath(rect: CGRect(x: 0, y: (bounds.size.height - horizontalBarHeight) * 0.5, width: bounds.size.width, height: horizontalBarHeight)))
|
||||
horizontalBarLayer.path = horizontalBarPath.cgPath
|
||||
horizontalBarLayer.fillColor = horizontalBarColor.cgColor
|
||||
|
||||
let progressHeight = bounds.self.height
|
||||
let progressWidth = progressHeight * 0.15
|
||||
let progressX = (bounds.self.width - progressWidth) * max(0.0, min(1.0, progress))
|
||||
let progressBounds = CGRect(x:progressX, y:0, width:progressWidth, height:progressHeight)
|
||||
let progressBounds = CGRect(x: progressX, y: 0, width: progressWidth, height: progressHeight)
|
||||
let progressCornerRadius = progressWidth * 0.5
|
||||
let progressPath = UIBezierPath()
|
||||
progressPath.append(UIBezierPath(roundedRect: progressBounds, cornerRadius: progressCornerRadius))
|
||||
|
||||
@ -24,11 +24,11 @@ public class OWSFlatButton: UIView {
|
||||
|
||||
@objc
|
||||
public init() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
button = UIButton(type:.custom)
|
||||
button = UIButton(type: .custom)
|
||||
|
||||
super.init(frame:CGRect.zero)
|
||||
super.init(frame: CGRect.zero)
|
||||
|
||||
createContent()
|
||||
}
|
||||
@ -40,7 +40,7 @@ public class OWSFlatButton: UIView {
|
||||
|
||||
private func createContent() {
|
||||
self.addSubview(button)
|
||||
button.addTarget(self, action:#selector(buttonPressed), for:.touchUpInside)
|
||||
button.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside)
|
||||
button.autoPinToSuperviewEdges()
|
||||
}
|
||||
|
||||
@ -54,13 +54,13 @@ public class OWSFlatButton: UIView {
|
||||
target: Any,
|
||||
selector: Selector) -> OWSFlatButton {
|
||||
let button = OWSFlatButton()
|
||||
button.setTitle(title:title,
|
||||
button.setTitle(title: title,
|
||||
font: font,
|
||||
titleColor: titleColor )
|
||||
button.setBackgroundColors(upColor:backgroundColor)
|
||||
button.setBackgroundColors(upColor: backgroundColor)
|
||||
button.useDefaultCornerRadius()
|
||||
button.setSize(width:width, height:height)
|
||||
button.addTarget(target:target, selector:selector)
|
||||
button.setSize(width: width, height: height)
|
||||
button.addTarget(target: target, selector: selector)
|
||||
return button
|
||||
}
|
||||
|
||||
@ -72,14 +72,14 @@ public class OWSFlatButton: UIView {
|
||||
height: CGFloat,
|
||||
target: Any,
|
||||
selector: Selector) -> OWSFlatButton {
|
||||
return OWSFlatButton.button(title:title,
|
||||
font:fontForHeight(height),
|
||||
titleColor:titleColor,
|
||||
backgroundColor:backgroundColor,
|
||||
width:width,
|
||||
height:height,
|
||||
target:target,
|
||||
selector:selector)
|
||||
return OWSFlatButton.button(title: title,
|
||||
font: fontForHeight(height),
|
||||
titleColor: titleColor,
|
||||
backgroundColor: backgroundColor,
|
||||
width: width,
|
||||
height: height,
|
||||
target: target,
|
||||
selector: selector)
|
||||
}
|
||||
|
||||
@objc
|
||||
@ -90,12 +90,12 @@ public class OWSFlatButton: UIView {
|
||||
target: Any,
|
||||
selector: Selector) -> OWSFlatButton {
|
||||
let button = OWSFlatButton()
|
||||
button.setTitle(title:title,
|
||||
button.setTitle(title: title,
|
||||
font: font,
|
||||
titleColor: titleColor )
|
||||
button.setBackgroundColors(upColor:backgroundColor)
|
||||
button.setBackgroundColors(upColor: backgroundColor)
|
||||
button.useDefaultCornerRadius()
|
||||
button.addTarget(target:target, selector:selector)
|
||||
button.addTarget(target: target, selector: selector)
|
||||
return button
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ public class OWSFlatButton: UIView {
|
||||
// Cap the "button height" at 40pt or button text can look
|
||||
// excessively large.
|
||||
let fontPointSize = round(min(40, height) * 0.45)
|
||||
return UIFont.ows_mediumFont(withSize:fontPointSize)
|
||||
return UIFont.ows_mediumFont(withSize: fontPointSize)
|
||||
}
|
||||
|
||||
// MARK: Methods
|
||||
@ -120,8 +120,8 @@ public class OWSFlatButton: UIView {
|
||||
@objc
|
||||
public func setBackgroundColors(upColor: UIColor,
|
||||
downColor: UIColor ) {
|
||||
button.setBackgroundImage(UIImage(color:upColor), for: .normal)
|
||||
button.setBackgroundImage(UIImage(color:downColor), for: .highlighted)
|
||||
button.setBackgroundImage(UIImage(color: upColor), for: .normal)
|
||||
button.setBackgroundImage(UIImage(color: downColor), for: .highlighted)
|
||||
}
|
||||
|
||||
@objc
|
||||
@ -132,8 +132,8 @@ public class OWSFlatButton: UIView {
|
||||
|
||||
@objc
|
||||
public func setSize(width: CGFloat, height: CGFloat) {
|
||||
button.autoSetDimension(.width, toSize:width)
|
||||
button.autoSetDimension(.height, toSize:height)
|
||||
button.autoSetDimension(.width, toSize: width)
|
||||
button.autoSetDimension(.height, toSize: height)
|
||||
}
|
||||
|
||||
@objc
|
||||
@ -152,7 +152,7 @@ public class OWSFlatButton: UIView {
|
||||
@objc
|
||||
public func addTarget(target: Any,
|
||||
selector: Selector) {
|
||||
button.addTarget(target, action:selector, for:.touchUpInside)
|
||||
button.addTarget(target, action: selector, for: .touchUpInside)
|
||||
}
|
||||
|
||||
@objc
|
||||
|
||||
@ -39,7 +39,7 @@ public class MediaMessageView: UIView, OWSAudioPlayerDelegate {
|
||||
@objc
|
||||
public var playbackState = AudioPlaybackState.stopped {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
ensureButtonState()
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion);
|
||||
message:(TSOutgoingMessage *)message
|
||||
fromViewController:(UIViewController *)fromViewController
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
OWSAssertIsOnMainThread();
|
||||
OWSAssert(error);
|
||||
OWSAssert(message);
|
||||
OWSAssert(fromViewController);
|
||||
@ -393,7 +393,7 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion);
|
||||
recipientId:(NSString *)recipientId
|
||||
fromViewController:(UIViewController *)fromViewController
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
OWSAssertIsOnMainThread();
|
||||
OWSAssert(message);
|
||||
OWSAssert(recipientId.length > 0);
|
||||
OWSAssert(fromViewController);
|
||||
@ -440,7 +440,7 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion);
|
||||
|
||||
- (void)resendMessage:(TSOutgoingMessage *)message fromViewController:(UIViewController *)fromViewController
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
OWSAssertIsOnMainThread();
|
||||
OWSAssert(message);
|
||||
OWSAssert(fromViewController);
|
||||
|
||||
@ -487,7 +487,7 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion);
|
||||
- (void)attachmentUploadProgress:(NSNotification *)notification
|
||||
{
|
||||
DDLogDebug(@"%@ upload progress.", self.logTag);
|
||||
AssertIsOnMainThread();
|
||||
OWSAssertIsOnMainThread();
|
||||
OWSAssert(self.progressView);
|
||||
|
||||
if (!self.outgoingMessage) {
|
||||
|
||||
@ -150,7 +150,7 @@ public class SignalAttachment: NSObject {
|
||||
|
||||
var error: SignalAttachmentError? {
|
||||
didSet {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
assert(oldValue == nil)
|
||||
Logger.verbose("\(logTag) Attachment has error: \(String(describing: error))")
|
||||
|
||||
@ -37,9 +37,9 @@ public class ModalActivityIndicatorViewController: OWSViewController {
|
||||
|
||||
public class func present(fromViewController: UIViewController,
|
||||
canCancel: Bool, backgroundBlock : @escaping (ModalActivityIndicatorViewController) -> Void) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let view = ModalActivityIndicatorViewController(canCancel:canCancel)
|
||||
let view = ModalActivityIndicatorViewController(canCancel: canCancel)
|
||||
// Present this modal _over_ the current view contents.
|
||||
view.modalPresentationStyle = .overFullScreen
|
||||
fromViewController.present(view,
|
||||
@ -51,11 +51,11 @@ public class ModalActivityIndicatorViewController: OWSViewController {
|
||||
}
|
||||
|
||||
public func dismiss(completion : @escaping () -> Void) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
if !wasDimissed {
|
||||
// Only dismiss once.
|
||||
self.dismiss(animated:false, completion: completion)
|
||||
self.dismiss(animated: false, completion: completion)
|
||||
wasDimissed = true
|
||||
} else {
|
||||
// If already dismissed, wait a beat then call completion.
|
||||
@ -71,27 +71,27 @@ public class ModalActivityIndicatorViewController: OWSViewController {
|
||||
self.view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.25)
|
||||
self.view.isOpaque = false
|
||||
|
||||
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle:.whiteLarge)
|
||||
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge)
|
||||
self.activityIndicator = activityIndicator
|
||||
self.view.addSubview(activityIndicator)
|
||||
activityIndicator.autoCenterInSuperview()
|
||||
|
||||
if canCancel {
|
||||
let cancelButton = UIButton(type:.custom)
|
||||
let cancelButton = UIButton(type: .custom)
|
||||
cancelButton.setTitle(CommonStrings.cancelButton, for: .normal)
|
||||
cancelButton.setTitleColor(UIColor.white, for: .normal)
|
||||
cancelButton.backgroundColor = UIColor.ows_darkGray
|
||||
cancelButton.titleLabel?.font = UIFont.ows_mediumFont(withSize:ScaleFromIPhone5To7Plus(18, 22))
|
||||
cancelButton.titleLabel?.font = UIFont.ows_mediumFont(withSize: ScaleFromIPhone5To7Plus(18, 22))
|
||||
cancelButton.layer.cornerRadius = ScaleFromIPhone5To7Plus(4, 5)
|
||||
cancelButton.clipsToBounds = true
|
||||
cancelButton.addTarget(self, action:#selector(cancelPressed), for:.touchUpInside)
|
||||
cancelButton.addTarget(self, action: #selector(cancelPressed), for: .touchUpInside)
|
||||
let buttonWidth = ScaleFromIPhone5To7Plus(140, 160)
|
||||
let buttonHeight = ScaleFromIPhone5To7Plus(40, 50)
|
||||
self.view.addSubview(cancelButton)
|
||||
cancelButton.autoHCenterInSuperview()
|
||||
cancelButton.autoPinEdge(toSuperviewEdge: .bottom, withInset:50)
|
||||
cancelButton.autoSetDimension(.width, toSize:buttonWidth)
|
||||
cancelButton.autoSetDimension(.height, toSize:buttonHeight)
|
||||
cancelButton.autoPinEdge(toSuperviewEdge: .bottom, withInset: 50)
|
||||
cancelButton.autoSetDimension(.width, toSize: buttonWidth)
|
||||
cancelButton.autoSetDimension(.height, toSize: buttonHeight)
|
||||
}
|
||||
|
||||
// Hide the modal until the presentation animation completes.
|
||||
@ -133,7 +133,7 @@ public class ModalActivityIndicatorViewController: OWSViewController {
|
||||
}
|
||||
|
||||
func presentTimerFired() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
clearTimer()
|
||||
|
||||
@ -144,7 +144,7 @@ public class ModalActivityIndicatorViewController: OWSViewController {
|
||||
}
|
||||
|
||||
func cancelPressed() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
wasCancelled = true
|
||||
|
||||
|
||||
@ -189,7 +189,7 @@ public class SystemContactsFetcher: NSObject {
|
||||
}
|
||||
|
||||
private func setupObservationIfNecessary() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard !hasSetupObservation else {
|
||||
return
|
||||
}
|
||||
@ -210,7 +210,7 @@ public class SystemContactsFetcher: NSObject {
|
||||
*/
|
||||
@objc
|
||||
public func requestOnce(completion completionParam: ((Error?) -> Void)?) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
// Ensure completion is invoked on main thread.
|
||||
let completion = { error in
|
||||
@ -260,7 +260,7 @@ public class SystemContactsFetcher: NSObject {
|
||||
|
||||
@objc
|
||||
public func fetchOnceIfAlreadyAuthorized() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard authorizationStatus == .authorized else {
|
||||
return
|
||||
}
|
||||
@ -273,7 +273,7 @@ public class SystemContactsFetcher: NSObject {
|
||||
|
||||
@objc
|
||||
public func userRequestedRefresh(completion: @escaping (Error?) -> Void) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard authorizationStatus == .authorized else {
|
||||
owsFail("should have already requested contact access")
|
||||
return
|
||||
@ -283,10 +283,10 @@ public class SystemContactsFetcher: NSObject {
|
||||
}
|
||||
|
||||
private func updateContacts(completion completionParam: ((Error?) -> Void)?, isUserRequested: Bool = false) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
var backgroundTask: OWSBackgroundTask? = OWSBackgroundTask(label: "\(#function)", completionBlock: { [weak self] status in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard status == .expired else {
|
||||
return
|
||||
|
||||
@ -38,10 +38,10 @@ public class ProfileFetcherJob: NSObject {
|
||||
}
|
||||
|
||||
public func run(recipientIds: [String]) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
backgroundTask = OWSBackgroundTask(label: "\(#function)", completionBlock: { [weak self] status in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard status == .expired else {
|
||||
return
|
||||
@ -91,7 +91,7 @@ public class ProfileFetcherJob: NSObject {
|
||||
}
|
||||
|
||||
public func getProfile(recipientId: String) -> Promise<SignalServiceProfile> {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
if !ignoreThrottling {
|
||||
if let lastDate = ProfileFetcherJob.fetchDateMap[recipientId] {
|
||||
let lastTimeInterval = fabs(lastDate.timeIntervalSinceNow)
|
||||
|
||||
@ -41,9 +41,9 @@ public class DeviceSleepManager: NSObject {
|
||||
SwiftSingletons.register(self)
|
||||
|
||||
NotificationCenter.default.addObserver(self,
|
||||
selector:#selector(didEnterBackground),
|
||||
name:NSNotification.Name.OWSApplicationDidEnterBackground,
|
||||
object:nil)
|
||||
selector: #selector(didEnterBackground),
|
||||
name: NSNotification.Name.OWSApplicationDidEnterBackground,
|
||||
object: nil)
|
||||
}
|
||||
|
||||
deinit {
|
||||
@ -52,13 +52,13 @@ public class DeviceSleepManager: NSObject {
|
||||
|
||||
@objc
|
||||
private func didEnterBackground() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
ensureSleepBlocking()
|
||||
}
|
||||
|
||||
public func addBlock(blockObject: NSObject) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
blocks.append(SleepBlock(blockObject: blockObject))
|
||||
|
||||
@ -66,7 +66,7 @@ public class DeviceSleepManager: NSObject {
|
||||
}
|
||||
|
||||
public func removeBlock(blockObject: NSObject) {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
blocks = blocks.filter {
|
||||
$0.blockObject != nil && $0.blockObject != blockObject
|
||||
@ -76,7 +76,7 @@ public class DeviceSleepManager: NSObject {
|
||||
}
|
||||
|
||||
private func ensureSleepBlocking() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
// Cull expired blocks.
|
||||
blocks = blocks.filter {
|
||||
|
||||
@ -129,7 +129,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
}
|
||||
|
||||
// This function is intended for use in Swift.
|
||||
void AssertIsOnMainThread(void);
|
||||
void SwiftAssertIsOnMainThread(NSString *functionName);
|
||||
|
||||
#define OWSRaiseException(name, formatParam, ...) \
|
||||
{ \
|
||||
|
||||
@ -1,14 +1,16 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSAsserts.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
void AssertIsOnMainThread()
|
||||
void SwiftAssertIsOnMainThread(NSString *functionName)
|
||||
{
|
||||
OWSCAssert([NSThread isMainThread]);
|
||||
if (![NSThread isMainThread]) {
|
||||
OWSCFail(@"%@ not on main thread", functionName);
|
||||
}
|
||||
}
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@ -75,6 +75,8 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
|
||||
// Don't display load screen immediately, in hopes that we can avoid it altogether.
|
||||
after(seconds: 0.5).then { [weak self] () -> Void in
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let strongSelf = self else { return }
|
||||
guard strongSelf.presentedViewController == nil else {
|
||||
Logger.debug("\(strongSelf.logTag) setup completed quickly, no need to present load view controller.")
|
||||
@ -95,7 +97,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
// performUpdateCheck must be invoked after Environment has been initialized because
|
||||
// upgrade process may depend on Environment.
|
||||
VersionMigrations.performUpdateCheck(completion: { [weak self] in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
guard let strongSelf = self else { return }
|
||||
|
||||
@ -136,6 +138,8 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
}
|
||||
|
||||
private func activate() {
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
|
||||
// We don't need to use "screen protection" in the SAE.
|
||||
@ -186,7 +190,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
|
||||
@objc
|
||||
func versionMigrationsDidComplete() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
|
||||
@ -197,7 +201,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
|
||||
@objc
|
||||
func storageIsReady() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
|
||||
@ -206,7 +210,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
|
||||
@objc
|
||||
func checkIsAppReady() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
// App isn't ready until storage is ready AND all version migrations are complete.
|
||||
guard areVersionMigrationsComplete else {
|
||||
@ -259,7 +263,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
|
||||
@objc
|
||||
func registrationStateDidChange() {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
|
||||
@ -275,6 +279,8 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
}
|
||||
|
||||
private func ensureRootViewController() {
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
|
||||
guard AppReadiness.isAppReady() else {
|
||||
@ -330,6 +336,8 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
// MARK: Error Views
|
||||
|
||||
private func showNotReadyView() {
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let failureTitle = NSLocalizedString("SHARE_EXTENSION_NOT_YET_MIGRATED_TITLE",
|
||||
comment: "Title indicating that the share extension cannot be used until the main app has been launched at least once.")
|
||||
let failureMessage = NSLocalizedString("SHARE_EXTENSION_NOT_YET_MIGRATED_MESSAGE",
|
||||
@ -338,6 +346,8 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
}
|
||||
|
||||
private func showNotRegisteredView() {
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let failureTitle = NSLocalizedString("SHARE_EXTENSION_NOT_REGISTERED_TITLE",
|
||||
comment: "Title indicating that the share extension cannot be used until the user has registered in the main app.")
|
||||
let failureMessage = NSLocalizedString("SHARE_EXTENSION_NOT_REGISTERED_MESSAGE",
|
||||
@ -346,6 +356,8 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
}
|
||||
|
||||
private func showErrorView(title: String, message: String) {
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let viewController = SAEFailedViewController(delegate: self, title: title, message: message)
|
||||
self.showPrimaryViewController(viewController)
|
||||
}
|
||||
@ -359,7 +371,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
|
||||
if isReadyForAppExtensions {
|
||||
AppReadiness.runNowOrWhenAppIsReady { [weak self] in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard let strongSelf = self else { return }
|
||||
strongSelf.activate()
|
||||
}
|
||||
@ -401,7 +413,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
|
||||
@objc
|
||||
func owsApplicationWillEnterForeground() throws {
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
Logger.debug("\(self.logTag) \(#function)")
|
||||
|
||||
@ -428,7 +440,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
Logger.info("\(self.logTag) \(#function)")
|
||||
|
||||
self.dismiss(animated: true) { [weak self] in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard let strongSelf = self else { return }
|
||||
strongSelf.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
|
||||
}
|
||||
@ -438,7 +450,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
Logger.info("\(self.logTag) \(#function)")
|
||||
|
||||
self.dismiss(animated: true) { [weak self] in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard let strongSelf = self else { return }
|
||||
strongSelf.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
|
||||
}
|
||||
@ -448,7 +460,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
Logger.info("\(self.logTag) \(#function)")
|
||||
|
||||
self.dismiss(animated: true) { [weak self] in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard let strongSelf = self else { return }
|
||||
strongSelf.extensionContext!.cancelRequest(withError: error)
|
||||
}
|
||||
@ -464,6 +476,8 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
// animation. Next, when loading completes, the load view will be switched out for the contact
|
||||
// picker view.
|
||||
private func showPrimaryViewController(_ viewController: UIViewController) {
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
shareViewNavigationController.setViewControllers([viewController], animated: false)
|
||||
if self.presentedViewController == nil {
|
||||
Logger.debug("\(self.logTag) presenting modally: \(viewController)")
|
||||
@ -475,8 +489,10 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
}
|
||||
|
||||
private func presentConversationPicker() {
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
self.buildAttachment().then { [weak self] attachment -> Void in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard let strongSelf = self else { return }
|
||||
|
||||
let conversationPicker = SharingThreadPickerViewController(shareViewDelegate: strongSelf)
|
||||
@ -487,7 +503,7 @@ public class ShareViewController: UIViewController, ShareViewDelegate, SAEFailed
|
||||
strongSelf.showPrimaryViewController(conversationPicker)
|
||||
Logger.info("showing picker with attachment: \(attachment)")
|
||||
}.catch {[weak self] error in
|
||||
AssertIsOnMainThread()
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
guard let strongSelf = self else { return }
|
||||
|
||||
let alertTitle = NSLocalizedString("SHARE_EXTENSION_UNABLE_TO_BUILD_ATTACHMENT_ALERT_TITLE",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user