TESTING - Notification logs - 3

TESTING - Notification logs - 3
This commit is contained in:
mgabdev 2020-05-22 02:48:48 -04:00
parent 087ad23bff
commit e1e6e07ea8

View File

@ -69,96 +69,98 @@ const makeSortedNotifications = (state) => {
let indexesForStatusesForFavorites = {} let indexesForStatusesForFavorites = {}
chunk.forEach((notification) => { chunk.forEach((notification) => {
const statusId = notification.get('status') if (!!notification) {
const type = notification.get('type') const statusId = notification.get('status')
const type = notification.get('type')
switch (type) { switch (type) {
case 'follow': { case 'follow': {
if (followIndex === -1) followIndex = sortedItems.size if (followIndex === -1) followIndex = sortedItems.size
sortedItems = sortedItems.set(followIndex, ImmutableMap()) sortedItems = sortedItems.set(followIndex, ImmutableMap())
follows = follows.set(follows.size, notification) follows = follows.set(follows.size, notification)
break break
}
case 'favourite': {
if (likes[statusId] === undefined) {
let size = sortedItems.size
sortedItems = sortedItems.set(size, ImmutableMap())
indexesForStatusesForFavorites[statusId] = size
likes[statusId] = []
} }
likes[statusId].push({ case 'favourite': {
account: notification.get('account'), if (likes[statusId] === undefined) {
created_at: notification.get('created_at'), let size = sortedItems.size
id: notification.get('id'), sortedItems = sortedItems.set(size, ImmutableMap())
}) indexesForStatusesForFavorites[statusId] = size
break likes[statusId] = []
} }
case 'reblog': { likes[statusId].push({
if (reposts[statusId] === undefined) { account: notification.get('account'),
let size = sortedItems.size created_at: notification.get('created_at'),
sortedItems = sortedItems.set(size, ImmutableMap()) id: notification.get('id'),
indexesForStatusesForReposts[statusId] = size })
reposts[statusId] = [] break
} }
reposts[statusId].push({ case 'reblog': {
account: notification.get('account'), if (reposts[statusId] === undefined) {
created_at: notification.get('created_at'), let size = sortedItems.size
id: notification.get('id'), sortedItems = sortedItems.set(size, ImmutableMap())
}) indexesForStatusesForReposts[statusId] = size
break reposts[statusId] = []
} }
default: { reposts[statusId].push({
sortedItems = sortedItems.set(sortedItems.size, notification) account: notification.get('account'),
break created_at: notification.get('created_at'),
} id: notification.get('id'),
} })
break
if (follows.size > 0) { }
sortedItems = sortedItems.set(followIndex, ImmutableMap({ default: {
follow: follows, sortedItems = sortedItems.set(sortedItems.size, notification)
})) break
}
if (Object.keys(likes).length > 0) {
for (const statusId in likes) {
if (likes.hasOwnProperty(statusId)) {
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,
})
}))
} }
} }
}
if (Object.keys(reposts).length > 0) {
for (const statusId in reposts) {
if (reposts.hasOwnProperty(statusId)) {
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({ if (follows.size > 0) {
repost: ImmutableMap({ sortedItems = sortedItems.set(followIndex, ImmutableMap({
accounts, follow: follows,
lastUpdated, }))
isUnread, }
status: statusId, if (Object.keys(likes).length > 0) {
}) for (const statusId in likes) {
})) if (likes.hasOwnProperty(statusId)) {
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,
})
}))
}
}
}
if (Object.keys(reposts).length > 0) {
for (const statusId in reposts) {
if (reposts.hasOwnProperty(statusId)) {
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,
})
}))
}
} }
} }
} }
}) })
finalSortedItems = finalSortedItems.concat(sortedItems) if (sortedItems.size > 0) finalSortedItems = finalSortedItems.concat(sortedItems)
}) })
return state.set('sortedItems', finalSortedItems) return state.set('sortedItems', finalSortedItems)