Commit 49dcbdcd authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

fix: contact search

support search by uri.

Change-Id: I08257c54e1ba6a7fdd0179057af463d23023719a
Gitlab: #26
parent f00be3c6
...@@ -35,13 +35,11 @@ extension String { ...@@ -35,13 +35,11 @@ extension String {
} }
func isSHA1() -> Bool { func isSHA1() -> Bool {
do { let sha1Regex = try? NSRegularExpression(pattern: "(ring:)?([0-9a-f]{40})", options: [])
let sha1Regex = try NSRegularExpression(pattern: "[0-9a-f]", options: .caseInsensitive) if sha1Regex?.firstMatch(in: self,
if !sha1Regex.matches(in: self, range: NSRange(location: 0, length: self.count)).isEmpty && self.count == 40 { options: NSRegularExpression.MatchingOptions.reportCompletion,
return true range: NSRange(location: 0, length: self.count)) != nil {
} return true
} catch {
print("Bad regex")
} }
return false return false
} }
......
...@@ -206,10 +206,7 @@ class SmartlistViewModel: Stateable, ViewModel { ...@@ -206,10 +206,7 @@ class SmartlistViewModel: Stateable, ViewModel {
self.filteredResults.value = filteredConversations self.filteredResults.value = filteredConversations
} }
let regexId = try? NSRegularExpression(pattern: "[0-9a-f]{40}", options: []) if !text.isSHA1() {
if ((regexId?.firstMatch(in: text, options: NSRegularExpression.MatchingOptions.reportCompletion,
range: NSRange(location: 0, length: text.count))) == nil) {
self.nameService.lookupName(withAccount: "", nameserver: "", name: text) self.nameService.lookupName(withAccount: "", nameserver: "", name: text)
self.searchStatus.onNext(L10n.Smartlist.searching) self.searchStatus.onNext(L10n.Smartlist.searching)
return return
...@@ -219,7 +216,7 @@ class SmartlistViewModel: Stateable, ViewModel { ...@@ -219,7 +216,7 @@ class SmartlistViewModel: Stateable, ViewModel {
let accountId = self.accountsService.currentAccount?.id ?? "" let accountId = self.accountsService.currentAccount?.id ?? ""
let jamiId = AccountModelHelper(withAccount: currentAccount).ringId ?? "" let jamiId = AccountModelHelper(withAccount: currentAccount).ringId ?? ""
//Create new converation //Create new converation
let conversation = ConversationModel(withRecipientRingId: text, accountId: accountId, accountUri: jamiId) let conversation = ConversationModel(withRecipientRingId: text.replacingOccurrences(of: "ring:", with: ""), accountId: accountId, accountUri: jamiId)
let newConversation = ConversationViewModel(with: self.injectionBag) let newConversation = ConversationViewModel(with: self.injectionBag)
newConversation.conversation = Variable<ConversationModel>(conversation) newConversation.conversation = Variable<ConversationModel>(conversation)
self.contactFoundConversation.value = newConversation self.contactFoundConversation.value = newConversation
......
...@@ -141,7 +141,7 @@ class ScanViewController: UIViewController, StoryboardBased, AVCaptureMetadataOu ...@@ -141,7 +141,7 @@ class ScanViewController: UIViewController, StoryboardBased, AVCaptureMetadataOu
AudioServicesPlayAlertSound(systemSoundId) AudioServicesPlayAlertSound(systemSoundId)
print("RingId : " + ringId) print("RingId : " + ringId)
self.dismiss(animated: true, completion: nil) self.dismiss(animated: true, completion: nil)
self.viewModel.createNewConversation(recipientRingId: ringId) self.viewModel.createNewConversation(recipientRingId: ringId.replacingOccurrences(of: "ring:", with: ""))
self.scannedQrCode = true self.scannedQrCode = true
} else { } else {
let alert = UIAlertController(title: L10n.Scan.badQrCode, message: "", preferredStyle: .alert) let alert = UIAlertController(title: L10n.Scan.badQrCode, message: "", preferredStyle: .alert)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment