Fixed a message request notification issue

• Fixed an issue where the message request notification may not show correctly
• Minor code tweaks for linting
pull/1018/head
Morgan Pretty 7 months ago
parent 6ad2f4e122
commit 7f5c544e06

@ -493,8 +493,24 @@ public extension SessionThread {
// If the thread is a message request then we only want to notify for the first message
if self.variant == .contact && isMessageRequest {
let numInteractions: Int = {
switch interaction.serverHash {
case .some(let serverHash):
return (try? self.interactions
.filter(Interaction.Columns.serverHash != serverHash)
.fetchCount(db))
.defaulting(to: 0)
case .none:
return (try? self.interactions
.filter(Interaction.Columns.timestampMs != interaction.timestampMs)
.fetchCount(db))
.defaulting(to: 0)
}
}()
// We only want to show a notification for the first interaction in the thread
guard ((try? self.interactions.fetchCount(db)) ?? 0) <= 1 else { return false }
guard numInteractions == 0 else { return false }
// Need to re-show the message requests section if it had been hidden
if db[.hasHiddenMessageRequests] {

@ -385,15 +385,12 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
}
let duration: CFTimeInterval = (CACurrentMediaTime() - startTime)
let logMessage: String = {
switch (isMainAppAndActive, handledNotification, noContent) {
case (true, _, _): return "Called while main app running, ignoring after \(.seconds(duration), unit: .ms)."
case (_, _, true): return "Called with no content, ignoring after \(.seconds(duration), unit: .ms)."
case (_, true, _): return "Completed after handling notification in \(.seconds(duration), unit: .ms)."
default: return "Completed silently after \(.seconds(duration), unit: .ms)."
}
}()
Log.info(logMessage)
switch (isMainAppAndActive, handledNotification, noContent) {
case (true, _, _): Log.info("Called while main app running, ignoring after \(.seconds(duration), unit: .ms).")
case (_, _, true): Log.info("Called with no content, ignoring after \(.seconds(duration), unit: .ms).")
case (_, true, _): Log.info("Completed after handling notification in \(.seconds(duration), unit: .ms).")
default: Log.info("Completed silently after \(.seconds(duration), unit: .ms).")
}
Log.flush()
self.contentHandler!(silentContent)

Loading…
Cancel
Save