@@ -128,7 +128,8 @@ final class PushNotificationService {
128128 let items = snapshot. documents. compactMap { makeResponse ( from: $0) }
129129
130130 let nextCursor : PushNotificationCursorDTO ? = snapshot. documents. last. map { document in
131- guard let receivedAt = document. data ( ) [ Key . receivedAt. rawValue] as? Timestamp else {
131+ guard let receivedAt = document. data ( ) [ PushNotificationFieldKey . receivedAt. rawValue] as? Timestamp
132+ else {
132133 return nil
133134 }
134135
@@ -184,6 +185,7 @@ final class PushNotificationService {
184185 let subject = PassthroughSubject < Int , Error > ( )
185186 let listener = store. collection ( FirestorePath . notifications ( uid) )
186187 . whereField ( " isRead " , isEqualTo: false )
188+ . whereField ( PushNotificationFieldKey . isDeleted. rawValue, isEqualTo: false )
187189 . addSnapshotListener { snapshot, error in
188190 if let error {
189191 subject. send ( completion: . failure( error) )
@@ -192,7 +194,7 @@ final class PushNotificationService {
192194
193195 guard let snapshot else { return }
194196 let unreadPushCount = snapshot. documents. filter { document in
195- !( document. data ( ) [ Key . deletingAt. rawValue] is Timestamp )
197+ !( document. data ( ) [ PushNotificationFieldKey . deletingAt. rawValue] is Timestamp )
196198 } . count
197199 subject. send ( unreadPushCount)
198200 }
@@ -238,7 +240,10 @@ final class PushNotificationService {
238240 }
239241
240242 let collection = store. collection ( FirestorePath . notifications ( uid) )
241- let snapshot = try await collection. whereField ( " todoId " , isEqualTo: todoId) . getDocuments ( )
243+ let snapshot = try await collection
244+ . whereField ( " todoId " , isEqualTo: todoId)
245+ . whereField ( PushNotificationFieldKey . isDeleted. rawValue, isEqualTo: false )
246+ . getDocuments ( )
242247
243248 guard let document = snapshot. documents. first else {
244249 logger. error ( " Notification not found for todoId: \( todoId) " )
@@ -265,6 +270,7 @@ private extension PushNotificationService {
265270 query: PushNotificationQuery
266271 ) -> Query {
267272 var firestoreQuery : Query = store. collection ( FirestorePath . notifications ( uid) )
273+ . whereField ( PushNotificationFieldKey . isDeleted. rawValue, isEqualTo: false )
268274
269275 if let thresholdDate = query. timeFilter. thresholdDate {
270276 firestoreQuery = firestoreQuery. whereField (
@@ -286,7 +292,7 @@ private extension PushNotificationService {
286292 func makeNextCursor( from document: QueryDocumentSnapshot ? ) -> PushNotificationCursorDTO ? {
287293 guard
288294 let document,
289- let receivedAt = document. data ( ) [ Key . receivedAt. rawValue] as? Timestamp else {
295+ let receivedAt = document. data ( ) [ PushNotificationFieldKey . receivedAt. rawValue] as? Timestamp else {
290296 return nil
291297 }
292298
@@ -298,16 +304,17 @@ private extension PushNotificationService {
298304
299305 func makeResponse( from snapshot: QueryDocumentSnapshot ) -> PushNotificationResponse ? {
300306 let data = snapshot. data ( )
301- if data [ Key . deletingAt. rawValue] is Timestamp {
307+ if data [ PushNotificationFieldKey . deletingAt. rawValue] is Timestamp ||
308+ ( data [ PushNotificationFieldKey . isDeleted. rawValue] as? Bool ) == true {
302309 return nil
303310 }
304311 guard
305- let title = data [ Key . title. rawValue] as? String ,
306- let body = data [ Key . body. rawValue] as? String ,
307- let receivedAt = data [ Key . receivedAt. rawValue] as? Timestamp ,
308- let isRead = data [ Key . isRead. rawValue] as? Bool ,
309- let todoId = data [ Key . todoId. rawValue] as? String ,
310- let todoCategory = data [ Key . todoCategory. rawValue] as? String else {
312+ let title = data [ PushNotificationFieldKey . title. rawValue] as? String ,
313+ let body = data [ PushNotificationFieldKey . body. rawValue] as? String ,
314+ let receivedAt = data [ PushNotificationFieldKey . receivedAt. rawValue] as? Timestamp ,
315+ let isRead = data [ PushNotificationFieldKey . isRead. rawValue] as? Bool ,
316+ let todoId = data [ PushNotificationFieldKey . todoId. rawValue] as? String ,
317+ let todoCategory = data [ PushNotificationFieldKey . todoCategory. rawValue] as? String else {
311318 return nil
312319 }
313320
@@ -322,13 +329,14 @@ private extension PushNotificationService {
322329 )
323330 }
324331
325- enum Key : String {
332+ enum PushNotificationFieldKey : String {
326333 case title
327334 case body
328335 case receivedAt
329336 case isRead
330337 case todoId
331338 case todoCategory
332- case deletingAt // 삭제 요청은 되었지만, 5초 유예 후 최종 삭제되기 전 상태
339+ case deletingAt // 삭제 요청으로 앱의 로컬 데이터에서 deletion이 된 상태
340+ case isDeleted // 삭제 요청으로 서버에서 soft deletion이 된 상태
333341 }
334342}
0 commit comments