CR: weak capture and clearer comments

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent debd556e09
commit 44678e3951

@ -36,11 +36,15 @@ class DebugUINotifications: DebugUIPage {
} }
var sectionItems = [ var sectionItems = [
OWSTableItem(title:"Last Incoming Message") { OWSTableItem(title:"Last Incoming Message") { [weak self] in
Logger.info("\(self.logTag) scheduling notification for incoming message.") guard let strongSelf = self else {
self.delayedNotificationDispatch { return
Logger.info("\(self.logTag) dispatching") }
TSStorageManager.shared().newDatabaseConnection().read({ (transaction) in
Logger.info("\(strongSelf.logTag) scheduling notification for incoming message.")
strongSelf.delayedNotificationDispatch {
Logger.info("\(strongSelf.logTag) dispatching")
TSStorageManager.shared().newDatabaseConnection().read { (transaction) in
guard let viewTransaction = transaction.ext(TSMessageDatabaseViewExtensionName) as? YapDatabaseViewTransaction else { guard let viewTransaction = transaction.ext(TSMessageDatabaseViewExtensionName) as? YapDatabaseViewTransaction else {
owsFail("unable to build view transaction") owsFail("unable to build view transaction")
return return
@ -55,28 +59,40 @@ class DebugUINotifications: DebugUIPage {
owsFail("last message was not an incoming message.") owsFail("last message was not an incoming message.")
return return
} }
Logger.info("\(self.logTag) notifying user of incoming message") Logger.info("\(strongSelf.logTag) notifying user of incoming message")
self.notificationsManager.notifyUser(for: incomingMessage, in: thread, contactsManager: self.contactsManager, transaction: transaction) strongSelf.notificationsManager.notifyUser(for: incomingMessage, in: thread, contactsManager: strongSelf.contactsManager, transaction: transaction)
}) }
} }
} }
] ]
if let contactThread = thread as? TSContactThread { if let contactThread = thread as? TSContactThread {
sectionItems += [ sectionItems += [
OWSTableItem(title:"Call Missed") { OWSTableItem(title:"Call Missed") { [weak self] in
self.delayedNotificationDispatchWithFakeCall(thread: contactThread) { call in guard let strongSelf = self else {
self.notificationsAdapter.presentMissedCall(call, callerName: thread.name()) return
}
strongSelf.delayedNotificationDispatchWithFakeCall(thread: contactThread) { call in
strongSelf.notificationsAdapter.presentMissedCall(call, callerName: thread.name())
} }
}, },
OWSTableItem(title:"Call Rejected: New Safety Number") { OWSTableItem(title:"Call Rejected: New Safety Number") { [weak self] in
self.delayedNotificationDispatchWithFakeCall(thread: contactThread) { call in guard let strongSelf = self else {
self.notificationsAdapter.presentMissedCallBecauseOfNewIdentity(call: call, callerName: thread.name()) return
}
strongSelf.delayedNotificationDispatchWithFakeCall(thread: contactThread) { call in
strongSelf.notificationsAdapter.presentMissedCallBecauseOfNewIdentity(call: call, callerName: thread.name())
} }
}, },
OWSTableItem(title:"Call Rejected: No Longer Verified") { OWSTableItem(title:"Call Rejected: No Longer Verified") { [weak self] in
self.delayedNotificationDispatchWithFakeCall(thread: contactThread) { call in guard let strongSelf = self else {
self.notificationsAdapter.presentMissedCallBecauseOfNoLongerVerifiedIdentity(call: call, callerName: thread.name()) return
}
strongSelf.delayedNotificationDispatchWithFakeCall(thread: contactThread) { call in
strongSelf.notificationsAdapter.presentMissedCallBecauseOfNoLongerVerifiedIdentity(call: call, callerName: thread.name())
} }
} }
] ]

@ -221,8 +221,11 @@ extension String {
return nil return nil
} }
// Notifications strip anything that looks lik a printf formatting character, // iOS strips anything that looks like a printf formatting character from
// so literal "%" must be escaped in order to appear in notification text. // the notification body, so if we want to dispay a literal "%" in a notification
// it must be escaped.
// see https://developer.apple.com/documentation/uikit/uilocalnotification/1616646-alertbody
// for more details.
return text.replacingOccurrences(of: "%", with: "%%") return text.replacingOccurrences(of: "%", with: "%%")
} }

Loading…
Cancel
Save