2022-07-07 20:41:50 +00:00
|
|
|
import { collection, limit, orderBy, query, where } from 'firebase/firestore'
|
2022-06-01 13:11:25 +00:00
|
|
|
import { db } from 'web/lib/firebase/init'
|
2022-07-07 20:41:50 +00:00
|
|
|
import { NOTIFICATIONS_PER_PAGE } from 'web/pages/notifications'
|
2022-06-01 13:11:25 +00:00
|
|
|
|
2022-07-07 20:41:50 +00:00
|
|
|
export function getNotificationsQuery(
|
|
|
|
userId: string,
|
|
|
|
unseenOnlyOptions?: { unseenOnly: boolean; limit: number }
|
|
|
|
) {
|
2022-06-01 13:11:25 +00:00
|
|
|
const notifsCollection = collection(db, `/users/${userId}/notifications`)
|
2022-07-07 20:41:50 +00:00
|
|
|
if (unseenOnlyOptions?.unseenOnly)
|
|
|
|
return query(
|
|
|
|
notifsCollection,
|
|
|
|
where('isSeen', '==', false),
|
|
|
|
orderBy('createdTime', 'desc'),
|
|
|
|
limit(unseenOnlyOptions.limit)
|
|
|
|
)
|
|
|
|
return query(
|
|
|
|
notifsCollection,
|
|
|
|
orderBy('createdTime', 'desc'),
|
|
|
|
// Nobody's going through 10 pages of notifications, right?
|
|
|
|
limit(NOTIFICATIONS_PER_PAGE * 10)
|
|
|
|
)
|
2022-06-01 13:11:25 +00:00
|
|
|
}
|