Skip to content

Commit 72e8503

Browse files
caldriangithub-actions[bot]
authored andcommitted
fix: skip notification when away or busy - WPB-8946 (#2438)
1 parent 78e4689 commit 72e8503

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

wire-ios-request-strategy/Sources/Notifications/Push Notifications/Notification Types/Content/ZMLocalNotification+Events.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// along with this program. If not, see http://www.gnu.org/licenses/.
1717
//
1818

19+
import Foundation
1920
import WireDataModel
2021

2122
public extension ZMLocalNotification {
@@ -191,6 +192,17 @@ private class ConversationCreateEventNotificationBuilder: EventNotificationBuild
191192
LocalNotificationType.event(.conversationCreated)
192193
}
193194

195+
override func shouldCreateNotification() -> Bool {
196+
if conversation == nil {
197+
// WPB-8946: fixes bug: notifications shown even though availability is busy or away
198+
let availability = moc.performAndWait { ZMUser.selfUser(in: moc).availability }
199+
return [.none, .available].contains(availability)
200+
}
201+
202+
// default behavior
203+
return super.shouldCreateNotification()
204+
}
205+
194206
}
195207

196208
// MARK: - Conversation Delete Event
@@ -322,7 +334,12 @@ private class NewMessageNotificationBuilder: EventNotificationBuilder {
322334
"Not creating local notification for message with nonce = \(event.messageNonce) because conversation is silenced"
323335
)
324336
return false
337+
} else if conversation == nil {
338+
// WPB-8946: fixes bug: notifications shown even though availability is busy or away
339+
let availability = moc.performAndWait { ZMUser.selfUser(in: moc).availability }
340+
return [.none, .available].contains(availability)
325341
}
342+
326343
if ZMUser.selfUser(in: moc).remoteIdentifier == event.senderUUID {
327344
return false
328345
}

0 commit comments

Comments
 (0)