Commit 1f84ff8f authored by mgabdev's avatar mgabdev

Added isUnread to grouped follows, likes, reposts notifications

• Added:
- isUnread to grouped follows, likes, reposts notifications
parent 3a09bc21
......@@ -18,25 +18,31 @@ const makeMapStateToProps = () => {
if (isFollows) {
let lastUpdated
let isUnread
const list = props.notification.get('follow')
let accounts = ImmutableList()
list.forEach((item) => {
const account = getAccountFromState(state, item.get('account'))
accounts = accounts.set(accounts.size, account)
if (!lastUpdated) lastUpdated = item.get('created_at')
if (!lastUpdated) {
isUnread = parseInt(item.get('id')) > parseInt(lastReadId)
lastUpdated = item.get('created_at')
}
})
return {
type: 'follow',
accounts: accounts,
createdAt: lastUpdated,
isUnread: false,
isUnread: isUnread,
statusId: undefined,
}
} else if (isLikes || isReposts) {
const theType = isLikes ? 'like' : 'repost'
const list = props.notification.get(theType)
let lastUpdated = list.get('lastUpdated')
let isUnread = list.get('isUnread')
let accounts = ImmutableList()
const accountIdArr = list.get('accounts')
......@@ -51,7 +57,7 @@ const makeMapStateToProps = () => {
type: theType,
accounts: accounts,
createdAt: lastUpdated,
isUnread: false,
isUnread: isUnread,
statusId: list.get('status'),
}
} else if (!isGrouped) {
......
......@@ -52,6 +52,7 @@ const notificationToMap = (notification) => ImmutableMap({
const makeSortedNotifications = (state) => {
let finalSortedItems = ImmutableList()
const items = state.get('items')
const lastReadId = state.get('lastReadId')
const chunks = Range(0, items.count(), DEFAULT_NOTIFICATIONS_LIMIT)
.map((chunkStart) => items.slice(chunkStart, chunkStart + DEFAULT_NOTIFICATIONS_LIMIT))
......@@ -88,6 +89,7 @@ const makeSortedNotifications = (state) => {
likes[statusId].push({
account: notification.get('account'),
created_at: notification.get('created_at'),
id: notification.get('id'),
})
break
}
......@@ -101,6 +103,7 @@ const makeSortedNotifications = (state) => {
reposts[statusId].push({
account: notification.get('account'),
created_at: notification.get('created_at'),
id: notification.get('id'),
})
break
}
......@@ -121,10 +124,13 @@ const makeSortedNotifications = (state) => {
const likeArr = likes[statusId]
const accounts = likeArr.map((l) => l.account)
const lastUpdated = likeArr[0]['created_at']
const isUnread = parseInt(likeArr[0]['id']) > lastReadId
sortedItems = sortedItems.set(indexesForStatusesForFavorites[statusId], ImmutableMap({
like: ImmutableMap({
accounts,
lastUpdated,
isUnread,
status: statusId,
})
}))
......@@ -137,10 +143,13 @@ const makeSortedNotifications = (state) => {
const repostArr = reposts[statusId]
const accounts = repostArr.map((l) => l.account)
const lastUpdated = repostArr[0]['created_at']
const isUnread = parseInt(repostArr[0]['id']) > lastReadId
sortedItems = sortedItems.set(indexesForStatusesForReposts[statusId], ImmutableMap({
repost: ImmutableMap({
accounts,
lastUpdated,
isUnread,
status: statusId,
})
}))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment