2022-09-02 16:53:44 +00:00
|
|
|
const COMMENTS_VIEW_PREFIX = 'commentsViewedAt'
|
|
|
|
const COMMENTS_NUM_PREFIX = 'commentsViewNum'
|
|
|
|
|
|
|
|
export function commentsViewed (item) {
|
|
|
|
if (!item.parentId && item.lastCommentAt) {
|
2023-07-25 14:14:45 +00:00
|
|
|
window.localStorage.setItem(`${COMMENTS_VIEW_PREFIX}:${item.id}`, new Date(item.lastCommentAt).getTime())
|
|
|
|
window.localStorage.setItem(`${COMMENTS_NUM_PREFIX}:${item.id}`, item.ncomments)
|
2022-09-02 16:53:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function commentsViewedAfterComment (rootId, createdAt) {
|
2023-07-25 14:14:45 +00:00
|
|
|
window.localStorage.setItem(`${COMMENTS_VIEW_PREFIX}:${rootId}`, new Date(createdAt).getTime())
|
|
|
|
const existingRootComments = window.localStorage.getItem(`${COMMENTS_NUM_PREFIX}:${rootId}`) || 0
|
|
|
|
window.localStorage.setItem(`${COMMENTS_NUM_PREFIX}:${rootId}`, existingRootComments + 1)
|
2022-09-02 16:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function newComments (item) {
|
|
|
|
if (!item.parentId) {
|
2023-07-25 14:14:45 +00:00
|
|
|
const commentsViewedAt = window.localStorage.getItem(`${COMMENTS_VIEW_PREFIX}:${item.id}`)
|
|
|
|
const commentsViewNum = window.localStorage.getItem(`${COMMENTS_NUM_PREFIX}:${item.id}`)
|
2022-09-02 16:53:44 +00:00
|
|
|
|
|
|
|
if (commentsViewedAt && commentsViewNum) {
|
|
|
|
return commentsViewedAt < new Date(item.lastCommentAt).getTime() || commentsViewNum < item.ncomments
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|