Revese,abbreviate,limit comments in feed
This commit is contained in:
parent
6134b45075
commit
0f8a370764
|
@ -80,6 +80,7 @@ export type ResolveItem = BaseActivityItem & {
|
||||||
}
|
}
|
||||||
|
|
||||||
const DAY_IN_MS = 24 * 60 * 60 * 1000
|
const DAY_IN_MS = 24 * 60 * 60 * 1000
|
||||||
|
const ABBREVIATED_NUM_COMMENTS_OR_BETS_TO_SHOW = 3
|
||||||
|
|
||||||
// Group together bets that are:
|
// Group together bets that are:
|
||||||
// - Within a day of the first in the group
|
// - Within a day of the first in the group
|
||||||
|
@ -171,7 +172,9 @@ function groupBets(
|
||||||
if (group.length > 0) {
|
if (group.length > 0) {
|
||||||
pushGroup()
|
pushGroup()
|
||||||
}
|
}
|
||||||
const abbrItems = abbreviated ? items.slice(-3) : items
|
const abbrItems = abbreviated
|
||||||
|
? items.slice(-ABBREVIATED_NUM_COMMENTS_OR_BETS_TO_SHOW)
|
||||||
|
: items
|
||||||
if (reversed) abbrItems.reverse()
|
if (reversed) abbrItems.reverse()
|
||||||
return abbrItems
|
return abbrItems
|
||||||
}
|
}
|
||||||
|
@ -238,7 +241,8 @@ function getAnswerGroups(
|
||||||
reversed,
|
reversed,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (abbreviated) items = items.slice(-2)
|
if (abbreviated)
|
||||||
|
items = items.slice(-ABBREVIATED_NUM_COMMENTS_OR_BETS_TO_SHOW)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: outcome,
|
id: outcome,
|
||||||
|
@ -251,6 +255,8 @@ function getAnswerGroups(
|
||||||
})
|
})
|
||||||
.filter((group) => group.answer)
|
.filter((group) => group.answer)
|
||||||
|
|
||||||
|
if (reversed) answerGroups.reverse()
|
||||||
|
|
||||||
return answerGroups
|
return answerGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +272,7 @@ function groupBetsAndComments(
|
||||||
reversed: boolean
|
reversed: boolean
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const { reversed, smallAvatar, abbreviated } = options
|
const { smallAvatar, abbreviated, reversed } = options
|
||||||
const commentsWithoutBets = comments
|
const commentsWithoutBets = comments
|
||||||
.filter((comment) => !comment.betId)
|
.filter((comment) => !comment.betId)
|
||||||
.map((comment) => ({
|
.map((comment) => ({
|
||||||
|
@ -284,7 +290,7 @@ function groupBetsAndComments(
|
||||||
|
|
||||||
// iterate through the bets and comment activity items and add them to the items in order of comment creation time:
|
// iterate through the bets and comment activity items and add them to the items in order of comment creation time:
|
||||||
const unorderedBetsAndComments = [...commentsWithoutBets, ...groupedBets]
|
const unorderedBetsAndComments = [...commentsWithoutBets, ...groupedBets]
|
||||||
const sortedBetsAndComments = _.sortBy(unorderedBetsAndComments, (item) => {
|
let sortedBetsAndComments = _.sortBy(unorderedBetsAndComments, (item) => {
|
||||||
if (item.type === 'comment') {
|
if (item.type === 'comment') {
|
||||||
return item.comment.createdTime
|
return item.comment.createdTime
|
||||||
} else if (item.type === 'bet') {
|
} else if (item.type === 'bet') {
|
||||||
|
@ -294,8 +300,12 @@ function groupBetsAndComments(
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (reversed) sortedBetsAndComments.reverse()
|
const abbrItems = abbreviated
|
||||||
return sortedBetsAndComments
|
? sortedBetsAndComments.slice(-ABBREVIATED_NUM_COMMENTS_OR_BETS_TO_SHOW)
|
||||||
|
: sortedBetsAndComments
|
||||||
|
|
||||||
|
if (reversed) abbrItems.reverse()
|
||||||
|
return abbrItems
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAllContractActivityItems(
|
export function getAllContractActivityItems(
|
||||||
|
@ -406,25 +416,42 @@ export function getRecentContractActivityItems(
|
||||||
contractPath,
|
contractPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
const items =
|
const items = []
|
||||||
contract.outcomeType === 'FREE_RESPONSE'
|
if (contract.outcomeType === 'FREE_RESPONSE') {
|
||||||
? getAnswerGroups(
|
items.push(
|
||||||
contract as FullContract<DPM, FreeResponse>,
|
...getAnswerGroups(
|
||||||
bets,
|
contract as FullContract<DPM, FreeResponse>,
|
||||||
comments,
|
bets,
|
||||||
user,
|
comments,
|
||||||
{
|
user,
|
||||||
sortByProb: false,
|
{
|
||||||
abbreviated: true,
|
sortByProb: false,
|
||||||
reversed: false,
|
abbreviated: true,
|
||||||
}
|
reversed: true,
|
||||||
)
|
}
|
||||||
: groupBetsAndComments(bets, comments, contract, user?.id, {
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
const onlyUsersBetsOrBetsWithComments = bets.filter((bet) =>
|
||||||
|
comments.some(
|
||||||
|
(comment) => comment.betId === bet.id || bet.userId === user?.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
items.push(
|
||||||
|
...groupBetsAndComments(
|
||||||
|
onlyUsersBetsOrBetsWithComments,
|
||||||
|
comments,
|
||||||
|
contract,
|
||||||
|
user?.id,
|
||||||
|
{
|
||||||
hideOutcome: false,
|
hideOutcome: false,
|
||||||
abbreviated: true,
|
abbreviated: true,
|
||||||
smallAvatar: false,
|
smallAvatar: false,
|
||||||
reversed: false,
|
reversed: true,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return [questionItem, ...items]
|
return [questionItem, ...items]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user