Commit 2d64729d authored by Andreas Traczyk's avatar Andreas Traczyk

vcards: make VCardUtils.loadVCard return vcards for invites

- Checks if the ringid parameter belongs to a contact request
  and loads the vcard from the ContactRequestModel object,
  otherwise, loads it from the contact's file.

Change-Id: I8c7f286f213d7bab1f50204b050e5d41f23b85e4
parent c2b11150
......@@ -50,9 +50,15 @@ class VCardUtils {
}
}
class func loadVCard(named name: String, inFolder folder: String) -> Single<CNContact> {
class func loadVCard(named name: String, inFolder folder: String, contactService: ContactsService? = nil) -> Single<CNContact> {
return Single.create(subscribe: { single in
if let directoryURL = VCardUtils.getFilePath(forFile: name, inFolder: folder, createIfNotExists: false) {
if let contactRequest = contactService?.contactRequest(withRingId: name) {
if let vCard = contactRequest.vCard {
single(.success(vCard))
} else {
single(.error(ContactServiceError.loadVCardFailed))
}
} else if let directoryURL = VCardUtils.getFilePath(forFile: name, inFolder: folder, createIfNotExists: false) {
do {
if let data = FileManager.default.contents(atPath: directoryURL.path) {
let vCard = try CNContactVCardSerialization.contacts(with: data)
......
......@@ -255,7 +255,7 @@ extension ContactsService: ContactsAdapterDelegate {
}
func loadVCard(forContactWithRingId ringID: String) -> Single<CNContact> {
let vCardSaved = VCardUtils.loadVCard(named:ringID, inFolder: VCardFolders.contacts.rawValue)
return vCardSaved
let vCard = VCardUtils.loadVCard(named: ringID, inFolder: VCardFolders.contacts.rawValue, contactService: self)
return vCard
}
}
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