works araound crash opening a fake message in drafts and close compose after background deleted the message refactor
authorbuff <andreas@pep-project.org>
Tue, 28 May 2019 22:29:27 +0200
branchrefactor
changeset 88388f357b5dd77e
parent 8837 e28a2300dd26
child 8839 746a8ed96f6f
works araound crash opening a fake message in drafts and close compose after background deleted the message
pEpForiOS/UI/Compose/ViewModel/ComposeViewModel+InitData.swift
     1.1 --- a/pEpForiOS/UI/Compose/ViewModel/ComposeViewModel+InitData.swift	Tue May 28 18:22:21 2019 +0200
     1.2 +++ b/pEpForiOS/UI/Compose/ViewModel/ComposeViewModel+InitData.swift	Tue May 28 22:29:27 2019 +0200
     1.3 @@ -23,7 +23,20 @@
     1.4          public let prefilledFrom: Identity?
     1.5  
     1.6          /// Original message to compute content and recipients from (e.g. a message we reply to).
     1.7 -        public let originalMessage: Message?
     1.8 +        private var _originalMessage: Message? = nil
     1.9 +        public var originalMessage: Message? {
    1.10 +            get {
    1.11 +                guard !(_originalMessage?.isDeleted ?? true) else {
    1.12 +                    // Makes sure we do not access properties af a messages that has been deleted
    1.13 +                    // in the DB.
    1.14 +                    return nil
    1.15 +                }
    1.16 +                return _originalMessage
    1.17 +            }
    1.18 +            set {
    1.19 +                _originalMessage = newValue
    1.20 +            }
    1.21 +        }
    1.22  
    1.23          public let composeMode: ComposeUtil.ComposeMode
    1.24  
    1.25 @@ -102,9 +115,9 @@
    1.26               orForOriginalMessage om: Message? = nil,
    1.27               composeMode: ComposeUtil.ComposeMode? = nil) {
    1.28              self.composeMode = composeMode ?? ComposeUtil.ComposeMode.normal
    1.29 -            self.originalMessage = om
    1.30              self.prefilledTo = om == nil ? prefilledTo : nil
    1.31              self.prefilledFrom = prefilledFrom
    1.32 +            self.originalMessage = om
    1.33              setupInitialSubject()
    1.34              setupInitialBody()
    1.35          }