Commit b33a2167 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

remove force unwrap

Replace force unwrap to prevent possible crashes.

Change-Id: I98ca63608fe814242f1b473e84b652418696d568
parent baa2dba7
......@@ -52,9 +52,11 @@ struct AccountModelHelper {
*/
func isAccountSip() -> Bool {
let sipString = AccountType.sip.rawValue
let accountType = self.account.details?
.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .accountType))
return sipString.compare(accountType!) == ComparisonResult.orderedSame
guard let accountType = self.account.details?
.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .accountType)) else {
return false
}
return sipString.compare(accountType) == ComparisonResult.orderedSame
}
/**
......@@ -64,9 +66,11 @@ struct AccountModelHelper {
*/
func isAccountRing() -> Bool {
let ringString = AccountType.ring.rawValue
let accountType = self.account.details?
.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .accountType))
return ringString.compare(accountType!) == ComparisonResult.orderedSame
guard let accountType = self.account.details?
.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .accountType)) else {
return false
}
return ringString.compare(accountType) == ComparisonResult.orderedSame
}
/**
......@@ -75,7 +79,8 @@ struct AccountModelHelper {
- Returns: true if the account is enabled, false otherwise.
*/
func isEnabled() -> Bool {
return (self.account.details!
guard let details = self.account.details else {return false}
return (details
.getBool(forConfigKeyModel: ConfigKeyModel.init(withKey: .accountEnable)))
}
......@@ -85,7 +90,8 @@ struct AccountModelHelper {
- Returns: the registration state of the account as a String.
*/
func getRegistrationState() -> String {
return (self.account.volatileDetails!
guard let details = self.account.volatileDetails else {return ""}
return (details
.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .accountRegistrationStatus)))
}
......@@ -147,12 +153,13 @@ struct AccountModelHelper {
}
public var uri: String? {
guard let details = self.account.details else {return nil}
if self.account.type == AccountType.sip {
let name = self.account.details!
let name = details
.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .accountUsername))
let server = self.account.details!
let server = details
.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .accountHostname))
let port = self.account.details!
let port = details
.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .localPort))
var uri: String
if !name.isEmpty {
......
......@@ -69,8 +69,8 @@ class ButtonsContainerView: UIView, NibLoadable {
self.commonInit()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.commonInit()
}
......
......@@ -288,10 +288,12 @@ class CallViewController: UIViewController, StoryboardBased, ViewModelBased {
self.viewModel.callDuration.drive(self.durationLabel.rx.text)
.disposed(by: self.disposeBag)
self.viewModel.callDuration.asObservable().observeOn(MainScheduler.instance)
self.viewModel.callDuration
.asObservable()
.observeOn(MainScheduler.instance)
.subscribe(onNext: { [weak self] _ in
if self?.durationLabel.text != "" {
if (self?.viewModel.isAudioOnly)! {
if (self?.viewModel.isAudioOnly ?? true) {
self?.buttonContainerHeightConstraint.constant = 200
self?.buttonsContainer.containerHeightConstraint.constant = 200
self?.buttonsContainer.stackViewYConstraint.constant = 110
......@@ -446,7 +448,7 @@ class CallViewController: UIViewController, StoryboardBased, ViewModelBased {
self.viewModel.showCapturedFrame
.observeOn(MainScheduler.instance)
.subscribe(onNext: { [weak self] dontShow in
if dontShow && (!(self?.isCallStarted)!) {
if dontShow && (!(self?.isCallStarted ?? false)) {
self?.isCallStarted = true
self?.hideCancelButton()
let device = UIDevice.modelName
......@@ -544,7 +546,8 @@ class CallViewController: UIViewController, StoryboardBased, ViewModelBased {
let widthCapturedVideo = ((self.infoContainerHeightConstraint.constant - 20)/3)*4
self.capturedVideoHeightConstraint.constant = -UIScreen.main.bounds.height + self.infoContainerHeightConstraint.constant - 20
self.capturedVideoWidthConstraint.constant = -UIScreen.main.bounds.width + widthCapturedVideo
let leftPointInfoContainer = self.infoBlurEffect?.convert((self.infoBlurEffect?.frame.origin)!, to: nil).x ?? 0
let leftPointInfoContainer = self.infoBlurEffect?
.convert((self.infoBlurEffect?.frame.origin)!, to: nil).x ?? 0
self.capturedVideoTrailingConstraint.constant = leftPointInfoContainer + 10
self.capturedVideoTopConstraint.constant = -20
self.viewCapturedVideo.cornerRadius = 25
......@@ -569,7 +572,8 @@ class CallViewController: UIViewController, StoryboardBased, ViewModelBased {
let widthCapturedVideo = ((self.infoContainerHeightConstraint.constant - 20)/4)*3
self.capturedVideoHeightConstraint.constant = -UIScreen.main.bounds.height + self.infoContainerHeightConstraint.constant - 20
self.capturedVideoWidthConstraint.constant = -UIScreen.main.bounds.width + widthCapturedVideo
let leftPointInfoContainer = self.infoBlurEffect?.convert((self.infoBlurEffect?.frame.origin)!, to: nil).x ?? 0
let leftPointInfoContainer = self.infoBlurEffect?.convert((self.infoBlurEffect?
.frame.origin)!, to: nil).x ?? 0
self.capturedVideoTrailingConstraint.constant = leftPointInfoContainer + 10
self.capturedVideoTopConstraint.constant = -20
self.viewCapturedVideo.cornerRadius = 25
......
......@@ -77,14 +77,21 @@ class ContactViewController: UIViewController, StoryboardBased, ViewModelBased {
.observeOn(MainScheduler.instance)
.startWith((self.viewModel.profileImageData.value, self.viewModel.userName.value))
.subscribe({ [weak self] profileData -> Void in
self?.stretchyHeader.avatarView?.subviews.forEach({ $0.removeFromSuperview() })
self?.stretchyHeader.avatarView?.addSubview(AvatarView(profileImageData: profileData.element?.0,
username: (profileData.element?.1)!,
size: 100,
labelFontSize: 44))
self?.titleView.avatarImage = AvatarView(profileImageData: profileData.element?.0,
username: (profileData.element?.1)!,
size: 36)
guard let data = profileData.element?.1 else { return }
self?.stretchyHeader
.avatarView?.subviews
.forEach({ $0.removeFromSuperview() })
self?.stretchyHeader
.avatarView?.addSubview(
AvatarView(profileImageData:
profileData.element?.0,
username: data,
size: 100,
labelFontSize: 44))
self?.titleView.avatarImage =
AvatarView(profileImageData: profileData.element?.0,
username: data,
size: 36)
return
})
.disposed(by: self.disposeBag)
......@@ -98,8 +105,8 @@ class ContactViewController: UIViewController, StoryboardBased, ViewModelBased {
self.viewModel.titleName
.observeOn(MainScheduler.instance)
.subscribe(onNext: { [weak self] name in
self?.titleView.text = name
}).disposed(by: self.disposeBag)
self?.titleView.text = name
}).disposed(by: self.disposeBag)
}
private func setUpTableView() {
......
......@@ -32,21 +32,22 @@ final class DBContainer {
private var connections = [String: Connection?]()
private let log = SwiftyBeaver.self
private let jamiDBName = "ring.db"
private let path: String
private let path: String?
private let dbVersion = 1
init() {
path = NSSearchPathForDirectoriesInDomains(
.documentDirectory, .userDomainMask, true
).first!
).first
}
func getJamiDB() -> Connection? {
if jamiDB != nil {
return jamiDB
}
guard let dbPath = path else { return nil }
do {
jamiDB = try Connection("\(path)/" + jamiDBName)
jamiDB = try Connection("\(dbPath)/" + jamiDBName)
} catch {
jamiDB = nil
log.error("Unable to open database")
......@@ -66,8 +67,9 @@ final class DBContainer {
if connections[account] != nil {
return connections[account] ?? nil
}
guard let dbPath = path else { return nil }
do {
let accountDb = try Connection("\(path)/" + "\(account).db")
let accountDb = try Connection("\(dbPath)/" + "\(account).db")
accountDb.userVersion = dbVersion
connections[account] = accountDb
return accountDb
......@@ -78,7 +80,8 @@ final class DBContainer {
}
func isDBExistsFor(account: String) -> Bool {
let url = NSURL(fileURLWithPath: path)
guard let dbPath = path else { return false }
let url = NSURL(fileURLWithPath: dbPath)
if let pathComponent = url.appendingPathComponent("/" + "\(account).db") {
let filePath = pathComponent.path
let fileManager = FileManager.default
......@@ -93,7 +96,8 @@ final class DBContainer {
}
private func removeDBNamed(dbName: String) {
let url = NSURL(fileURLWithPath: path)
guard let dbPath = path else { return }
let url = NSURL(fileURLWithPath: dbPath)
guard let pathComponent = url
.appendingPathComponent("/" + dbName) else {
return
......
......@@ -625,10 +625,9 @@ class DBManager {
private func getConversationsFor(contactUri: String,
createIfNotExists: Bool, dataBase: Connection) throws -> Int64? {
if let contactConversations = try self.conversationHelper
.selectConversationsForProfile(profileUri: contactUri, dataBase: dataBase) {
if !contactConversations.isEmpty {
return contactConversations.first!.id
}
.selectConversationsForProfile(profileUri: contactUri, dataBase: dataBase),
let conv = contactConversations.first {
return conv.id
}
if !createIfNotExists {
return nil
......
......@@ -48,7 +48,10 @@ class EditProfileViewModel {
options: NSData.Base64DecodingOptions
.ignoreUnknownCharacters) as Data? {
self.image = UIImage(data: data)
return UIImage(data: data)!
guard let image = UIImage(data: data) else {
return UIImage(named: "add_avatar")!
}
return image
}
return UIImage(named: "add_avatar")!
})
......
......@@ -45,7 +45,7 @@ extension String {
}
func toMD5HexString() -> String {
let messageData = self.data(using: .utf8)!
guard let messageData = self.data(using: .utf8) else {return ""}
var digestData = Data(count: Int(CC_MD5_DIGEST_LENGTH))
_ = digestData.withUnsafeMutableBytes { digestBytes in
......
......@@ -74,10 +74,12 @@ extension UIImage {
let imgRect = CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: size)
UIGraphicsBeginImageContextWithOptions(size, false, scale)
self.draw(in: imgRect)
let copied = UIGraphicsGetImageFromCurrentImageContext()
guard let copied = UIGraphicsGetImageFromCurrentImageContext() else {
return self
}
UIGraphicsEndImageContext()
return copied!
return copied
}
func convertToData(ofMaxSize maxSize: Int) -> Data? {
......
......@@ -66,10 +66,15 @@ class ContactRequestCell: UITableViewCell, NibReusable {
.observeOn(MainScheduler.instance)
.startWith((item.profileImageData.value, item.userName.value))
.subscribe({ [weak self] profileData -> Void in
guard let data = profileData.element?.1 else {
return
}
self?.avatarView.subviews.forEach({ $0.removeFromSuperview() })
self?.avatarView.addSubview(AvatarView(profileImageData: profileData.element?.0,
username: (profileData.element?.1)!,
size: 40))
self?.avatarView
.addSubview(
AvatarView(profileImageData: profileData.element?.0,
username: data,
size: 40))
return
})
.disposed(by: self.disposeBag)
......
......@@ -122,8 +122,9 @@ class ContactRequestsViewModel: Stateable, ViewModel {
}
})
.disposed(by: self.disposeBag)
guard let currentAccount = accountsService.currentAccount else { return }
self.nameService.lookupAddress(withAccount: (accountsService.currentAccount?.id)!,
self.nameService.lookupAddress(withAccount: currentAccount.id,
nameserver: "",
address: item.contactRequest.ringId)
}
......
......@@ -153,10 +153,10 @@ class MessageCell: UITableViewCell, NibReusable {
// swiftlint:disable cyclomatic_complexity
func applyBubbleStyleToCell(_ items: [MessageViewModel]?, cellForRowAt indexPath: IndexPath) {
guard let item = items?[indexPath.row] else {
guard let items = items else {
return
}
let item = items[indexPath.row]
let type = item.bubblePosition()
var bubbleColor: UIColor
if item.isTransfer {
......@@ -205,13 +205,13 @@ class MessageCell: UITableViewCell, NibReusable {
if item.timeStringShown != nil {
self.bubbleTopConstraint.constant = 32
adjustedSequencing = indexPath.row == (items?.count)! - 1 ?
adjustedSequencing = indexPath.row == items.count - 1 ?
.singleMessage : adjustedSequencing != .singleMessage && adjustedSequencing != .lastOfSequence ?
.firstOfSequence : .singleMessage
}
if indexPath.row + 1 < (items?.count)! {
if items?[indexPath.row + 1].timeStringShown != nil {
if indexPath.row + 1 < items.count {
if items[indexPath.row + 1].timeStringShown != nil {
switch adjustedSequencing {
case .firstOfSequence:
adjustedSequencing = .singleMessage
......@@ -359,10 +359,14 @@ class MessageCell: UITableViewCell, NibReusable {
.observeOn(MainScheduler.instance)
.startWith((conversationViewModel.profileImageData.value, conversationViewModel.userName.value))
.subscribe({ [weak self] profileData -> Void in
self?.avatarView.subviews.forEach({ $0.removeFromSuperview() })
self?.avatarView.addSubview(AvatarView(profileImageData: profileData.element?.0,
username: (profileData.element?.1)!,
size: 32))
guard let data = profileData.element?.1 else { return }
self?.avatarView
.subviews.forEach({ $0.removeFromSuperview() })
self?.avatarView
.addSubview(
AvatarView(profileImageData: profileData.element?.0,
username: data,
size: 32))
self?.avatarView.isHidden = !(item.sequencing == .lastOfSequence || item.sequencing == .singleMessage)
return
})
......@@ -391,7 +395,7 @@ class MessageCell: UITableViewCell, NibReusable {
accountId: accountId) {
self.transferImageView.image = image
let newSize = self.transferImageView.image?.getNewSize(of: defaultSize)
let xOriginImageSend = screenWidth - 112 - (newSize?.width)!
let xOriginImageSend = screenWidth - 112 - (newSize?.width ?? 200)
if message.bubblePosition() == .sent {
self.transferImageView.frame = CGRect(x: xOriginImageSend, y: 0, width: ((newSize?.width ?? 200)), height: ((newSize?.height ?? 200)))
} else if message.bubblePosition() == .received {
......
......@@ -29,7 +29,7 @@ class MessageCellReceived: MessageCell {
override func applyBubbleStyleToCell(_ items: [MessageViewModel]?, cellForRowAt indexPath: IndexPath) {
super.applyBubbleStyleToCell(items, cellForRowAt: indexPath)
if (self.messageLabel.text?.containsOnlyEmoji)! {
if (self.messageLabel.text?.containsOnlyEmoji ?? false) {
self.messageLabelTrailingConstraint.constant = 0
self.messageLabelLeadingConstraint.constant = 0
} else {
......
......@@ -29,7 +29,7 @@ class MessageCellSent: MessageCell {
override func applyBubbleStyleToCell(_ items: [MessageViewModel]?, cellForRowAt indexPath: IndexPath) {
super.applyBubbleStyleToCell(items, cellForRowAt: indexPath)
if (self.messageLabel.text?.containsOnlyEmoji)! {
if (self.messageLabel.text?.containsOnlyEmoji) ?? false {
self.messageLabelTrailingConstraint.constant = 0
self.messageLabelLeadingConstraint.constant = 0
} else {
......
......@@ -182,7 +182,9 @@ class ConversationViewController: UIViewController,
imageFileName = (imageFileName as NSString).deletingPathExtension + ".png"
}
let localCachePath = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(imageFileName)
guard let localCachePath = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(imageFileName) else {
return
}
self.log.debug("localCachePath: \(String(describing: localCachePath))")
guard let phAsset = result.firstObject else { return }
......@@ -194,8 +196,8 @@ class ConversationViewController: UIViewController,
image = img
}
// copy image to tmp
copyImageToCache(image: image, imagePath: localCachePath!.path)
self.viewModel.sendFile(filePath: localCachePath!.path,
copyImageToCache(image: image, imagePath: localCachePath.path)
self.viewModel.sendFile(filePath: localCachePath.path,
displayName: imageFileName,
localIdentifier: result.firstObject?.localIdentifier)
} else if phAsset.mediaType == .video {
......@@ -211,8 +213,8 @@ class ConversationViewController: UIViewController,
return
}
self.log.debug("copying movie to: \(String(describing: localCachePath))")
videoData.write(toFile: (localCachePath?.path)!, atomically: true)
self.viewModel.sendFile(filePath: localCachePath!.path, displayName: imageFileName)
videoData.write(toFile: localCachePath.path, atomically: true)
self.viewModel.sendFile(filePath: localCachePath.path, displayName: imageFileName)
})
}
}
......@@ -225,7 +227,9 @@ class ConversationViewController: UIViewController,
}
@objc func keyboardWillShow(withNotification notification: Notification) {
let userInfo: Dictionary = notification.userInfo!
guard let userInfo: Dictionary = notification.userInfo else {
return
}
guard let keyboardFrame: NSValue = userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue else { return }
let keyboardRectangle = keyboardFrame.cgRectValue
......@@ -588,30 +592,31 @@ class ConversationViewController: UIViewController,
}
func getMessageSequencing(forIndex index: Int) -> MessageSequencing {
if let messageItem = self.messageViewModels?[index] {
if let models = self.messageViewModels {
let messageItem = models[index]
let msgOwner = messageItem.bubblePosition()
if self.messageViewModels?.count == 1 || index == 0 {
if self.messageViewModels?.count == index + 1 {
if models.count == 1 || index == 0 {
if models.count == index + 1 {
return MessageSequencing.singleMessage
}
let nextMessageItem = index + 1 <= (self.messageViewModels?.count)!
? self.messageViewModels?[index + 1] : nil
let nextMessageItem = index + 1 <= models.count
? models[index + 1] : nil
if nextMessageItem != nil {
return msgOwner != nextMessageItem?.bubblePosition()
? MessageSequencing.singleMessage : MessageSequencing.firstOfSequence
}
} else if self.messageViewModels?.count == index + 1 {
let lastMessageItem = index - 1 >= 0 && index - 1 < (self.messageViewModels?.count)!
? self.messageViewModels?[index - 1] : nil
} else if models.count == index + 1 {
let lastMessageItem = index - 1 >= 0 && index - 1 < models.count
? models[index - 1] : nil
if lastMessageItem != nil {
return msgOwner != lastMessageItem?.bubblePosition()
? MessageSequencing.singleMessage : MessageSequencing.lastOfSequence
}
}
let lastMessageItem = index - 1 >= 0 && index - 1 < (self.messageViewModels?.count)!
? self.messageViewModels?[index - 1] : nil
let nextMessageItem = index + 1 <= (self.messageViewModels?.count)!
? self.messageViewModels?[index + 1] : nil
let lastMessageItem = index - 1 >= 0 && index - 1 < models.count
? models[index - 1] : nil
let nextMessageItem = index + 1 <= models.count
? models[index + 1] : nil
var sequencing = MessageSequencing.singleMessage
if (lastMessageItem != nil) && (nextMessageItem != nil) {
if msgOwner != lastMessageItem?.bubblePosition() && msgOwner == nextMessageItem?.bubblePosition() {
......
......@@ -275,9 +275,11 @@ class ConversationViewModel: Stateable, ViewModel {
self.sendContactRequest()
}
guard let account = self.accountService.currentAccount else {return}
self.conversationsService
.sendMessage(withContent: content,
from: accountService.currentAccount!,
from: account,
recipientUri: self.conversation.value.participantUri)
.subscribe(onCompleted: { [unowned self] in
self.log.debug("Message sent")
......@@ -316,9 +318,13 @@ class ConversationViewModel: Stateable, ViewModel {
return
}
guard let currentAccount = self.accountService.currentAccount else {
return
}
self.contactsService
.sendContactRequest(toContactRingId: self.conversation.value.hash,
withAccount: self.accountService.currentAccount!)
withAccount: currentAccount)
.subscribe(onCompleted: { [unowned self] in
self.log.info("contact request sent")
}, onError: { [unowned self] (error) in
......
......@@ -68,10 +68,15 @@ class ConversationCell: UITableViewCell, NibReusable {
.observeOn(MainScheduler.instance)
.startWith((item.profileImageData.value, item.userName.value))
.subscribe({ [weak self] profileData -> Void in
guard let data = profileData.element?.1 else {
return
}
self?.avatarView.subviews.forEach({ $0.removeFromSuperview() })
self?.avatarView.addSubview(AvatarView(profileImageData: profileData.element?.0,
username: (profileData.element?.1)!,
size: 40))
self?.avatarView
.addSubview(
AvatarView(profileImageData: profileData.element?.0,
username: data,
size: 40))
return
})
.disposed(by: self.disposeBag)
......
......@@ -303,11 +303,13 @@ class SmartlistViewController: UIViewController, StoryboardBased, ViewModelBased
}
@objc func keyboardWillShow(withNotification notification: Notification) {
let userInfo: Dictionary = notification.userInfo!
guard let userInfo: Dictionary = notification.userInfo else {return}
guard let keyboardFrame: NSValue = userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue else { return }
let keyboardRectangle = keyboardFrame.cgRectValue
let keyboardHeight = keyboardRectangle.height
let tabBarHeight = (self.tabBarController?.tabBar.frame.size.height)!
guard let tabBarHeight = (self.tabBarController?.tabBar.frame.size.height) else {
return
}
self.conversationsTableView.contentInset.bottom = keyboardHeight - tabBarHeight
self.searchResultsTableView.contentInset.bottom = keyboardHeight - tabBarHeight
......
......@@ -117,7 +117,10 @@ class SmartlistViewModel: Stateable, ViewModel {
if let photo = profile.photo,
let data = NSData(base64Encoded: photo,
options: NSData.Base64DecodingOptions.ignoreUnknownCharacters) as Data? {
return UIImage(data: data)!
guard let image = UIImage(data: data) else {
return UIImage(asset: Asset.icContactPicture)
}
return image
}
guard let account = self.accountsService.currentAccount else {
return UIImage(asset: Asset.icContactPicture)
......@@ -164,7 +167,10 @@ class SmartlistViewModel: Stateable, ViewModel {
} else {
conversationViewModel = ConversationViewModel(with: self.injectionBag)
conversationViewModel?.conversation = Variable<ConversationModel>(conversationModel)
self.conversationViewModels.append(conversationViewModel!)
if let conversation = conversationViewModel {
self.conversationViewModels
.append(conversation)
}
}
return conversationViewModel
})
......
......@@ -71,8 +71,8 @@ class BlockListViewController: UIViewController, StoryboardBased, ViewModelBased
cell.configureFromItem(item)
cell.unblockButton.rx.tap
.subscribe(onNext: { [weak self, weak item] in
if item == nil {return}
self?.unbanContactTapped(withItem: item!)
guard let contact = item else { return }
self?.unbanContactTapped(withItem: contact)
}).disposed(by: cell.disposeBag)
}
.disposed(by: disposeBag)
......
......@@ -111,7 +111,9 @@ class LocalNotificationsHelper {
intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([callCategory])
} else {
let notificationTypes: UIUserNotificationType = (UIApplication.shared.currentUserNotificationSettings?.types)!
guard let notificationTypes: UIUserNotificationType = (UIApplication.shared.currentUserNotificationSettings?.types) else {
return
}
let acceptAction = UIMutableUserNotificationAction()
acceptAction.identifier = CallAcition.accept.rawValue
acceptAction.title = CallAcition.accept.title()
......@@ -136,7 +138,7 @@ class LocalNotificationsHelper {
}
}
@objc func cancelCall(timer: Timer!) {
@objc func cancelCall(timer: Timer) {
guard let info = timer.userInfo as? [String: String],
let callID = info[NotificationUserInfoKeys.callID.rawValue] else {
self.timer?.invalidate()
......
......@@ -108,7 +108,7 @@ class CallModel {
if let callType = dictionary[CallDetailKey.callTypeKey.rawValue] {
if let callTypeInt = Int(callType) {
self.callType = CallType(rawValue: callTypeInt)!
self.callType = CallType(rawValue: callTypeInt) ?? .missed
} else {
self.callType = .missed
}
......
......@@ -49,11 +49,11 @@ class ContactModel: Equatable {
}
if let confirmed = dictionary["confirmed"] {
self.confirmed = confirmed.toBool()!
self.confirmed = confirmed.toBool() ?? false
}
if let added = dictionary["added"] {
let addedDate = Date(timeIntervalSince1970: Double(added)!)
if let added = dictionary["added"], let dateAdded = Double(added) {
let addedDate = Date(timeIntervalSince1970: dateAdded)
self.added = addedDate
}
if let banned = dictionary["banned"],
......
......@@ -59,9 +59,9 @@ class ContactRequestModel {
self.vCard = contactVCard
}
if let receivedDateString = dictionary[ContactRequestKey.received.rawValue] {
let timestamp = Double(receivedDateString)
self.receivedDate = Date(timeIntervalSince1970: timestamp!)
if let receivedDateString = dictionary[ContactRequestKey.received.rawValue],
let timestamp = Double(receivedDateString) {
self.receivedDate = Date(timeIntervalSince1970: timestamp)
} else {
self.receivedDate = Date()
}
......
......@@ -135,7 +135,12 @@ class ScanViewController: UIViewController, StoryboardBased, AVCaptureMetadataOu
//Those coordinates are assigned to our codeFrame
codeFrame.frame = metaDataCoordinates.bounds
let ringId = stringCodeValue.components(separatedBy: "http://").last!
guard let ringId = stringCodeValue.components(separatedBy: "http://").last else {
let alert = UIAlertController(title: L10n.Scan.badQrCode, message: "", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: L10n.Global.ok, style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
return
}
if ringId.isSHA1() {
AudioServicesPlayAlertSound(systemSoundId)
......
......@@ -134,13 +134,15 @@ class AccountsService: AccountAdapterDelegate {
return account == newValue
}).first
guard let newAccount = newValue else { return }
//If current account already exists in the list, move it to the first index
if let currentAccount = currentAccount {
let index = self.accountList.index(of: currentAccount)
self.accountList.remove(at: index!)
if let currentAccount = currentAccount,