Commit ec094c0f authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

contact request: handle requests without vCard

Contact requests without vCard were not shown to user. This patch adds
them to list of pending requests.

Change-Id: Ie146a9eece296ea7160679175fcc2043d5f5df40
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 34ceed01
...@@ -25,7 +25,7 @@ class ContactRequestModel { ...@@ -25,7 +25,7 @@ class ContactRequestModel {
let ringId: String let ringId: String
let accountId: String let accountId: String
var vCard: CNContact? var vCard: CNContact? = nil
var receivedDate: Date var receivedDate: Date
enum ContactRequestKey: String { enum ContactRequestKey: String {
...@@ -52,14 +52,17 @@ class ContactRequestModel { ...@@ -52,14 +52,17 @@ class ContactRequestModel {
} }
if let vCardString = dictionary[ContactRequestKey.payload.rawValue] { if let vCardString = dictionary[ContactRequestKey.payload.rawValue] {
do { if let data = vCardString.data(using: String.Encoding.utf8), !data.isEmpty {
self.vCard = try CNContactVCardSerialization.contacts(with: vCardString.data(using: String.Encoding.utf8)!).first! do {
} catch { let vCards = try CNContactVCardSerialization.contacts(with: data)
log.error("Unable to serialize the vCard : \(error)") if let contactVCard = vCards.first {
self.vCard = CNContact() self.vCard = contactVCard
}
} catch {
log.error("Unable to serialize the vCard : \(error)")
self.vCard = CNContact()
}
} }
} else {
self.vCard = nil
} }
if let receivedDateString = dictionary[ContactRequestKey.received.rawValue] { if let receivedDateString = dictionary[ContactRequestKey.received.rawValue] {
......
...@@ -187,28 +187,32 @@ class ContactsService { ...@@ -187,28 +187,32 @@ class ContactsService {
extension ContactsService: ContactsAdapterDelegate { extension ContactsService: ContactsAdapterDelegate {
func incomingTrustRequestReceived(from senderAccount: String, to accountId: String, withPayload payload: Data, receivedDate: Date) { func incomingTrustRequestReceived(from senderAccount: String, to accountId: String, withPayload payload: Data, receivedDate: Date) {
do {
//Update trust request list
if self.contactRequest(withRingId: senderAccount) == nil {
let vCards = try CNContactVCardSerialization.contacts(with: payload)
let contactRequest = ContactRequestModel(withRingId: senderAccount,
vCard: vCards.first,
receivedDate: receivedDate,
accountId: accountId)
self.contactRequests.value.append(contactRequest)
} else {
// If the contact request already exists, update it's relevant data
if let contactRequest = self.contactRequest(withRingId: senderAccount) {
let vCards = try CNContactVCardSerialization.contacts(with: payload)
contactRequest.vCard = vCards.first
contactRequest.receivedDate = receivedDate
}
}
log.debug("Incoming trust request received from :\(senderAccount)") var vCard: CNContact?
do {
let vCards = try CNContactVCardSerialization.contacts(with: payload)
vCard = vCards.first
} catch { } catch {
vCard = nil
log.error("Unable to parse the vCard :\(error)") log.error("Unable to parse the vCard :\(error)")
} }
//Update trust request list
if self.contactRequest(withRingId: senderAccount) == nil {
let contactRequest = ContactRequestModel(withRingId: senderAccount,
vCard: vCard,
receivedDate: receivedDate,
accountId: accountId)
self.contactRequests.value.append(contactRequest)
} else {
// If the contact request already exists, update it's relevant data
if let contactRequest = self.contactRequest(withRingId: senderAccount) {
contactRequest.vCard = vCard
contactRequest.receivedDate = receivedDate
}
log.debug("Incoming trust request received from :\(senderAccount)")
}
} }
func contactAdded(contact uri: String, withAccountId accountId: String, confirmed: Bool) { func contactAdded(contact uri: String, withAccountId accountId: String, confirmed: Bool) {
......
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