Skip to content

Commit

Permalink
Merge pull request #53 from VirgilSecurity/develop
Browse files Browse the repository at this point in the history
v3.3.2
  • Loading branch information
Ogerets committed May 21, 2020
2 parents 0c069c7 + fe07f24 commit 97cb459
Show file tree
Hide file tree
Showing 25 changed files with 138 additions and 94 deletions.
4 changes: 2 additions & 2 deletions Notification Extension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>3.3.1</string>
<string>3.3.2</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<string>3</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
Expand Down
2 changes: 1 addition & 1 deletion Source/ChatsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum ChatsManager {
public static func startSingle(with identity: String,
startProgressBar: @escaping (() -> Void),
completion: @escaping (Error?) -> Void) {
DispatchQueue(label: "ChatsManager").async {
DispatchQueue.global(qos: .userInitiated).async {
do {
let identity = identity.lowercased()

Expand Down
14 changes: 6 additions & 8 deletions Source/Controllers/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ import AVFoundation
import PKHUD

class ChatViewController: BaseChatViewController {
@IBOutlet weak var avatarView: GradientView!
@IBOutlet weak var avatarLetterLabel: UILabel!

private let indicator = UIActivityIndicatorView()
private let indicatorLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))

Expand Down Expand Up @@ -69,9 +66,6 @@ class ChatViewController: BaseChatViewController {
super.bottomSpaceView.backgroundColor = .appThemeBackgroundColor
super.collectionView?.backgroundColor = .appThemeForegroundColor

self.avatarLetterLabel.text = self.channel.letter
self.avatarView.draw(with: self.channel.colors)

self.setupIndicator()
self.updateTitle()

Expand Down Expand Up @@ -140,7 +134,7 @@ class ChatViewController: BaseChatViewController {
titleButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16.0)
titleButton.setTitle(self.channel.name, for: .normal)

let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(showChatInfo(_:)))
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.showChatInfo(_:)))
titleButton.addGestureRecognizer(tapRecognizer)

self.navigationItem.titleView = titleButton
Expand All @@ -158,8 +152,12 @@ class ChatViewController: BaseChatViewController {
self.navigationItem.titleView = progressView
}
}

@IBAction func callTapped(_ sender: Any) {
CallManager.shared.startOutgoingCall(to: self.channel.name)
}

@IBAction func showChatInfo(_ sender: Any) {
@objc func showChatInfo(_ sender: Any) {
self.perform(segue: .toChatInfo)
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Delegates/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
RTCInitializeSSL()

// Defining start controller
let startStoryboard = UIStoryboard(name: StartViewController.name, bundle: Bundle.main)
let startStoryboard = UIStoryboard(name: Constants.launchScreenName, bundle: Bundle.main)
let startController = startStoryboard.instantiateInitialViewController()!

let logger = DDOSLogger.sharedInstance
Expand Down
2 changes: 1 addition & 1 deletion Source/Delegates/PushRegistryDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PushRegistryDelegate: NSObject, PKPushRegistryDelegate {
CallManager.shared.startIncomingCall(from: callOffer, pushKitCompletion: completion)
}
catch {
Log.error(error, message: "Incomming call processing failed")
Log.error(error, message: "Incoming call processing failed")

CallManager.shared.startDummyIncomingCall(pushKitCompletion: completion)
}
Expand Down
10 changes: 4 additions & 6 deletions Source/Networking/Call/CallManager+CallKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ extension CallManager {
}()

static func createCallKitProvider() -> CXProvider {
let provider = CXProvider(configuration: Self.providerConfiguration)

return provider
CXProvider(configuration: Self.providerConfiguration)
}
}

Expand Down Expand Up @@ -135,18 +133,18 @@ extension CallManager: CXProviderDelegate {

let callUUID = action.callUUID

Log.debug("Answering for incomming call with id \(callUUID.uuidString)")
Log.debug("Answering for incoming call with id \(callUUID.uuidString)")

guard
let call = self.findCall(with: callUUID),
let incommingCall = call as? IncomingCall
let incomingCall = call as? IncomingCall
else {
Log.error(CallManagerError.noActiveCall, message: "Can not answer to the call with id \(callUUID.uuidString)")
action.fail()
return
}

incommingCall.answer()
incomingCall.answer()
action.fulfill()
}

Expand Down
22 changes: 10 additions & 12 deletions Source/Networking/Call/CallManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public class CallManager: NSObject {
let audioSession = RTCAudioSession.sharedInstance()
let messageSender: MessageSender = MessageSender()

private let callProviderQueue = DispatchQueue(label: "CallManager.CallProviderQueue")
private let audioControlQueue = DispatchQueue(label: "CallManager.AudioControlQueue")
private let queue = DispatchQueue(label: "CallManager.CallProviderQueue", qos: .userInitiated)

// MARK: Playback properties
private var beepAudioPlayer: AVAudioPlayer?
Expand All @@ -75,7 +74,7 @@ public class CallManager: NSObject {
public override init() {
super.init()

self.callProvider.setDelegate(self, queue: callProviderQueue)
self.callProvider.setDelegate(self, queue: self.queue)
self.configureAudioResources()
}

Expand All @@ -99,7 +98,6 @@ public class CallManager: NSObject {

player = try AVAudioPlayer(data: dataAsset.data, fileTypeHint: AVFileType.wav.rawValue)
player?.delegate = self
player?.prepareToPlay()
}
catch {
Log.error(error, message: "Setting up player for \(assetName) call sound failed")
Expand Down Expand Up @@ -141,7 +139,7 @@ public class CallManager: NSObject {
let callUUID = callOffer.callUUID
let caller = callOffer.caller

if self.findCall(with: callUUID) != nil {
guard self.findCall(with: callUUID) == nil else {
Log.debug("Call with id \(callUUID.uuidString) was already added.")
self.requestSystemDummyIncomingCall(pushKitCompletion: pushKitCompletion)
return
Expand All @@ -153,11 +151,11 @@ public class CallManager: NSObject {
}

if let error = error {
Log.debug("Incomming call with id \(callUUID.uuidString) was not started.")
Log.debug("Incoming call with id \(callUUID.uuidString) was not started.")
self.didFail(error)
}

self.callProviderQueue.async {
self.queue.async {
do {
guard let account = self.account else {
throw CallManagerContractError.noAccount
Expand Down Expand Up @@ -199,7 +197,7 @@ public class CallManager: NSObject {

// Wait until "Secure Call Ended" playback will finish.
// TODO: Make it more clear.
self.audioControlQueue.asyncAfter(deadline: .now() + 1.4) {
self.queue.asyncAfter(deadline: .now() + 1.4) {
self.requestSystemEndCall(call) { error in
if let error = error {
self.didFailCall(call, error)
Expand Down Expand Up @@ -253,7 +251,7 @@ public class CallManager: NSObject {

// Wait until "Secure Call Ended" playback will finish.
// TODO: Make it more clear.
self.audioControlQueue.asyncAfter(deadline: .now() + 1.4) {
self.queue.asyncAfter(deadline: .now() + 1.4) {
self.requestSystemEndCall(call) { error in
if let error = error {
self.didFailCall(call, error)
Expand Down Expand Up @@ -364,7 +362,7 @@ public class CallManager: NSObject {

// MARK: Playback control
private func requestCallStatusPlayback(_ status: CallStatusPlayback) {
self.audioControlQueue.async {
self.queue.async {
if (self.currentCallStatusPlayback == status) ||
(self.currentCallStatusPlayback == .connecting && status == .calling) ||
(self.currentCallStatusPlayback == .connected && status == .calling) ||
Expand All @@ -380,7 +378,7 @@ public class CallManager: NSObject {
}

private func processRequestedCallStatusPlayback() {
self.audioControlQueue.async {
self.queue.async {
guard self.audioSession.isAudioEnabled else {
Log.debug("CallManager: Delay starting playback \(self.requestedCallStatusPlayback) - audio module is didable.")
return
Expand Down Expand Up @@ -431,7 +429,7 @@ public class CallManager: NSObject {
}

private func stopBeepCallStatusPlayback() {
self.audioControlQueue.async {
self.queue.async {
self.beepAudioPlayer?.stop()

self.isCallStatusPlaybackPlaying = false
Expand Down
2 changes: 1 addition & 1 deletion Source/Networking/Ejabberd/Ejabberd+Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ extension Ejabberd {
}

private func initialize(after: TimeInterval = RetryConfig.ReconnectDelay.noDelay.rawValue) {
self.initQueue.asyncAfter(deadline: .now() + after) {
self.queue.asyncAfter(deadline: .now() + after) {
do {
guard self.state != .connecting else {
return
Expand Down
3 changes: 2 additions & 1 deletion Source/Networking/Ejabberd/Ejabberd+Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ extension Ejabberd {
}

internal func send(message: XMPPMessage) throws {
let messageOperation = EjabberdOperation(message: message, stream: self.stream)
let messageOperation = EjabberdOperation(message: message, stream: self.stream, delegateQueue: self.queue)

self.messageQueue.addOperation(messageOperation)
}
}
Expand Down
11 changes: 5 additions & 6 deletions Source/Networking/Ejabberd/Ejabberd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import XMPPFrameworkSwift
class Ejabberd: NSObject, XMPPStreamDelegate {
private(set) static var shared: Ejabberd = Ejabberd()

internal let initQueue = DispatchQueue(label: "Ejabberd")
private let delegateQueue = DispatchQueue(label: "EjabberdDelegate")
internal let queue = DispatchQueue(label: "EjabberdDelegate")

internal var retryConfig: RetryConfig = RetryConfig()

Expand Down Expand Up @@ -44,26 +43,26 @@ class Ejabberd: NSObject, XMPPStreamDelegate {
self.stream.hostName = URLConstants.ejabberdHost
self.stream.hostPort = URLConstants.ejabberdHostPort
self.stream.startTLSPolicy = .allowed
self.stream.addDelegate(self, delegateQueue: self.delegateQueue)
self.stream.addDelegate(self, delegateQueue: self.queue)

// Upload
self.upload.activate(self.stream)

// Delivery Receipts
self.deliveryReceipts.activate(self.stream)
self.deliveryReceipts.autoSendMessageDeliveryRequests = true
self.deliveryReceipts.addDelegate(self, delegateQueue: self.delegateQueue)
self.deliveryReceipts.addDelegate(self, delegateQueue: self.queue)

// Read Receipts
self.readReceipts.activate(self.stream)
self.readReceipts.autoSendMessageReadRequests = true
self.readReceipts.addDelegate(self, delegateQueue: self.delegateQueue)
self.readReceipts.addDelegate(self, delegateQueue: self.queue)

// Blacklist
self.blocking.activate(self.stream)
self.blocking.autoRetrieveBlockingListItems = true
self.blocking.autoClearBlockingListInfo = true
self.blocking.addDelegate(self, delegateQueue: self.delegateQueue)
self.blocking.addDelegate(self, delegateQueue: self.queue)
}

public static func setupJid(with username: String) throws -> XMPPJID {
Expand Down
5 changes: 3 additions & 2 deletions Source/Networking/Ejabberd/EjabberdOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ enum EjabberdOperationState {
class EjabberdOperation: Operation {
let message: XMPPMessage
let stream: XMPPStream
let delegateQueue = DispatchQueue(label: "EjabberdOperation")
let delegateQueue: DispatchQueue
var state: EjabberdOperationState = .new

init(message: XMPPMessage, stream: XMPPStream) {
init(message: XMPPMessage, stream: XMPPStream, delegateQueue: DispatchQueue) {
self.message = message
self.stream = stream
self.delegateQueue = delegateQueue
}

override func main() {
Expand Down
12 changes: 7 additions & 5 deletions Source/Networking/MessageProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,18 @@ class MessageProcessor {
CallManager.shared.processIceCandidate(iceCandidate)
}

guard let channel = Storage.shared.currentChannel,
channel.name == author else {
return Notifications.post(.chatListUpdated)
self.postLocalPushNotification(message: message, author: author)

guard
let channel = Storage.shared.currentChannel,
channel.name == author
else {
return Notifications.post(.chatListUpdated)
}

if let storageMessage = storageMessage {
self.postNotification(about: storageMessage, unread: unread)
}

self.postLocalPushNotification(message: message, author: author)
}

private static func migrationSafeContentImport(from data: Data,
Expand Down
3 changes: 2 additions & 1 deletion Source/Networking/MessageSender.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import ChattoAdditions
import VirgilSDK

public class MessageSender {
private let queue = DispatchQueue(label: "MessageSender")
// TODO: Think of using global concurrent queue
private let queue = DispatchQueue(label: "MessageSender", qos: .userInitiated)

private func send(message: NetworkMessage,
pushType: PushType,
Expand Down
2 changes: 1 addition & 1 deletion Source/Storage/Models/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extension Storage {
return "Voice Message"

case let callMessage as CallMessage:
return callMessage.isIncoming ? "Incomming call" : "Outgoing call"
return callMessage.isIncoming ? "Incoming call" : "Outgoing call"

default:
return ""
Expand Down
2 changes: 1 addition & 1 deletion Source/Storage/Storage+MessageUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ extension Storage {

public static func exportAsUIModel(message: CallMessage) -> UIMessageModelProtocol {

let text = message.isIncoming ? "Incomming call" : "Outgoing call"
let text = message.isIncoming ? "Incoming call" : "Outgoing call"

let status = message.state.exportAsMessageStatus()

Expand Down
4 changes: 2 additions & 2 deletions Source/UserAuthorizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class UserAuthorizer {
}

public func signUp(identity: String, completion: @escaping (Error?) -> Void) {
DispatchQueue(label: "UserAuthorizer").async {
DispatchQueue.global(qos: .userInitiated).async {
do {
try self.virgilAuthorizer.signUp(identity: identity)

Expand All @@ -77,7 +77,7 @@ public class UserAuthorizer {
}

public func logOut(completion: @escaping (Error?) -> Void) {
DispatchQueue(label: "UserAuthorizer").async {
DispatchQueue.global(qos: .userInitiated).async {
do {
try Ejabberd.shared.deregisterFromNotifications()
try Ejabberd.shared.disconect()
Expand Down
5 changes: 0 additions & 5 deletions Source/Utils/Constants/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ enum Constants {
case prod = ""
}

static let KeychainGroup: String = "com.virgil.VirgilMessenger\(Constants.envPrefix.rawValue.replacingOccurrences(of: "-", with: "."))"
static let alertTopic: String = KeychainGroup
static let appGroup: String = "group.virgil.notification\(Constants.envPrefix.rawValue)"
static let pushesNode: String = "node"

#if DEBUG
Expand All @@ -30,13 +28,10 @@ enum Constants {

enum URLConstants {
// Ejabberd
static let ejabberdHost: String = "xmpp\(Constants.envPrefix.rawValue).virgilsecurity.com"
static let ejabberdHostPort: UInt16 = 5222
static let ejabberdPushHost: String = "push-notifications-proxy"

// Backend
static let serviceBaseURL: String = "https://messenger\(Constants.envPrefix.rawValue).virgilsecurity.com"

static let virgilJwtEndpoint = URL(string: "\(URLConstants.serviceBaseURL)/virgil-jwt/")!
static let ejabberdJwtEndpoint = URL(string: "\(URLConstants.serviceBaseURL)/ejabberd-jwt/")!
static let signUpEndpoint = URL(string: "\(URLConstants.serviceBaseURL)/signup/")!
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 97cb459

Please sign in to comment.