fix background fetch crash in getUserHexEncodedPublicKey

pull/247/head
Ryan ZHAO 4 years ago
parent 82f37b6342
commit f61e37222e

@ -199,7 +199,14 @@ public class MessageFetcherJob: NSObject {
}
private func fetchUndeliveredMessages() -> Promise<Set<Promise<[SSKProtoEnvelope]>>> {
return SnodeAPI.getMessages(for: getUserHexEncodedPublicKey())
// In some cases like deleting an account
// the backgroud fetch was not stopped
// so the identityKeyPair can be nil
let userPublickKey = getUserHexEncodedPublicKey()
if !userPublickKey.isEmpty {
return SnodeAPI.getMessages(for: userPublickKey)
}
return Promise.value(Set())
}
private func acknowledgeDelivery(envelope: SSKProtoEnvelope) {

@ -1,4 +1,10 @@
public func getUserHexEncodedPublicKey() -> String {
return OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
// In some cases like deleting an account
// the backgroud fetch was not stopped
// so the identityKeyPair can be nil
if let keyPair = OWSIdentityManager.shared().identityKeyPair() {
return keyPair.hexEncodedPublicKey
}
return ""
}

Loading…
Cancel
Save