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 {
}
func isSHA1() -> Bool {
do {
let sha1Regex = try NSRegularExpression(pattern: "[0-9a-f]", options: .caseInsensitive)
if !sha1Regex.matches(in: self, range: NSRange(location: 0, length: self.count)).isEmpty && self.count == 40 {
return true
}
} catch {
print("Bad regex")
let sha1Regex = try? NSRegularExpression(pattern: "(ring:)?([0-9a-f]{40})", options: [])
if sha1Regex?.firstMatch(in: self,
options: NSRegularExpression.MatchingOptions.reportCompletion,
range: NSRange(location: 0, length: self.count)) != nil {
return true
}
return false
}
......
......@@ -206,10 +206,7 @@ class SmartlistViewModel: Stateable, ViewModel {
self.filteredResults.value = filteredConversations
}
let regexId = try? NSRegularExpression(pattern: "[0-9a-f]{40}", options: [])
if ((regexId?.firstMatch(in: text, options: NSRegularExpression.MatchingOptions.reportCompletion,
range: NSRange(location: 0, length: text.count))) == nil) {
if !text.isSHA1() {
self.nameService.lookupName(withAccount: "", nameserver: "", name: text)
self.searchStatus.onNext(L10n.Smartlist.searching)
return
......@@ -219,7 +216,7 @@ class SmartlistViewModel: Stateable, ViewModel {
let accountId = self.accountsService.currentAccount?.id ?? ""
let jamiId = AccountModelHelper(withAccount: currentAccount).ringId ?? ""
//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)
newConversation.conversation = Variable<ConversationModel>(conversation)
self.contactFoundConversation.value = newConversation
......
......@@ -141,7 +141,7 @@ class ScanViewController: UIViewController, StoryboardBased, AVCaptureMetadataOu
AudioServicesPlayAlertSound(systemSoundId)
print("RingId : " + ringId)
self.dismiss(animated: true, completion: nil)
self.viewModel.createNewConversation(recipientRingId: ringId)
self.viewModel.createNewConversation(recipientRingId: ringId.replacingOccurrences(of: "ring:", with: ""))
self.scannedQrCode = true
} else {
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