Commit 198f7b23 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

contact request: display name

-display profile name if exists
-display correctly special characters

Change-Id: I61bff698721654527616080eb5afaba8f4b0cfcc
parent e48a0f55
......@@ -75,7 +75,7 @@ class ContactRequestCell: UITableViewCell, NibReusable {
.disposed(by: self.disposeBag)
// name
item.userName
item.bestName
.asObservable()
.observeOn(MainScheduler.instance)
.bind(to: self.nameLabel.rx.text)
......
......@@ -29,6 +29,17 @@ class ContactRequestItem {
let userName = Variable("")
let profileName = Variable("")
let profileImageData = Variable<Data?>(nil)
lazy var bestName: Observable<String> = {
return Observable
.combineLatest(userName.asObservable(),
profileName.asObservable()) {(userName, displayname) in
if displayname.isEmpty {
return userName
}
return displayname
}
}()
let disposeBag = DisposeBag()
init(withContactRequest contactRequest: ContactRequestModel, profileService: ProfilesService,
......@@ -36,15 +47,16 @@ class ContactRequestItem {
self.contactRequest = contactRequest
self.userName.value = contactRequest.ringId
self.profileImageData.value = self.contactRequest.vCard?.imageData
self.profileName.value = VCardUtils.getName(from: self.contactRequest.vCard)
profileService.getProfile(ringId: contactRequest.ringId)
.subscribe(onNext: { [weak self] profile in
if let photo = profile.photo,
let data = NSData(base64Encoded: photo,
options: NSData.Base64DecodingOptions.ignoreUnknownCharacters) as Data? {
self?.profileImageData.value = data
if let name = profile.alias, !name.isEmpty {
self?.profileName.value = name
}
}
if let name = profile.alias, !name.isEmpty {
self?.profileName.value = name
}
}).disposed(by: self.disposeBag)
}
......
......@@ -51,18 +51,12 @@ class ContactRequestModel {
self.ringId = ""
}
if let vCardString = dictionary[ContactRequestKey.payload.rawValue] {
if let data = vCardString.data(using: String.Encoding.utf8), !data.isEmpty {
do {
let vCards = try CNContactVCardSerialization.contacts(with: data)
if let contactVCard = vCards.first {
self.vCard = contactVCard
}
} catch {
log.error("Unable to serialize the vCard : \(error)")
self.vCard = CNContact()
}
}
self.vCard = CNContact()
if let vCardString = dictionary[ContactRequestKey.payload.rawValue],
let data = vCardString.data(using: String.Encoding.utf8), !data.isEmpty,
let contactVCard = CNContactVCardSerialization.parseToVCard(data: data) {
self.vCard = contactVCard
}
if let receivedDateString = dictionary[ContactRequestKey.received.rawValue] {
......
......@@ -226,12 +226,8 @@ extension ContactsService: ContactsAdapterDelegate {
func incomingTrustRequestReceived(from senderAccount: String, to accountId: String, withPayload payload: Data, receivedDate: Date) {
var vCard: CNContact?
do {
let vCards = try CNContactVCardSerialization.contacts(with: payload)
vCard = vCards.first
} catch {
vCard = nil
log.error("Unable to parse the vCard :\(error)")
if let contactVCard = CNContactVCardSerialization.parseToVCard(data: payload) {
vCard = contactVCard
}
//Update trust request list
......
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