Revision 8d76e2e3 ChatSecure/Classes/Controllers/OTROMEMOStorageManager.swift
| ChatSecure/Classes/Controllers/OTROMEMOStorageManager.swift | ||
|---|---|---|
| 157 | 157 |
open func storeBuddyDevices(_ devices:[NSNumber], buddyUsername:String, completion:(()->Void)?) {
|
| 158 | 158 |
self.databaseConnection.asyncReadWrite { (transaction) in
|
| 159 | 159 |
// Fetch the buddy from the database. |
| 160 |
var buddy: OTRXMPPBuddy? = nil |
|
| 161 |
if let jid = XMPPJID(string: buddyUsername) {
|
|
| 162 |
buddy = OTRXMPPBuddy.fetchBuddy(jid: jid, accountUniqueId: self.accountKey, transaction: transaction) |
|
| 160 |
guard let jid = XMPPJID(string: buddyUsername), let buddy = OTRXMPPBuddy.fetchBuddy(jid: jid, accountUniqueId: self.accountKey, transaction: transaction) else {
|
|
| 161 |
// If this is teh first launch the buddy will not be in the buddy list becuase the roster comes in after device list from PEP. |
|
| 162 |
DDLogWarn("Could not find buddy to store devices \(buddyUsername)")
|
|
| 163 |
return |
|
| 163 | 164 |
} |
| 164 |
// If this is teh first launch the buddy will not be in the buddy list becuase the roster comes in after device list from PEP. |
|
| 165 |
// So we create a buddy witht the minimial information we have in order to save the device list. |
|
| 166 |
if (buddy == nil) {
|
|
| 167 |
buddy = OTRXMPPBuddy() |
|
| 168 |
buddy?.username = buddyUsername |
|
| 169 |
buddy?.accountUniqueId = self.accountKey |
|
| 170 |
buddy?.save(with: transaction) |
|
| 171 |
} |
|
| 172 |
if let bud = buddy {
|
|
| 173 |
self.storeDevices(devices, parentYapKey: bud.uniqueId, parentYapCollection: type(of: bud).collection, transaction: transaction) |
|
| 174 |
if let completion = completion {
|
|
| 175 |
completion() |
|
| 176 |
} |
|
| 177 |
} |
|
| 178 |
|
|
| 165 |
self.storeDevices(devices, parentYapKey: buddy.uniqueId, parentYapCollection: buddy.threadCollection, transaction: transaction) |
|
| 166 |
completion?() |
|
| 179 | 167 |
} |
| 180 | 168 |
} |
| 181 | 169 |
} |
Also available in: Unified diff