Show free comments in feed

This commit is contained in:
Ian Philips 2022-04-22 04:16:54 -06:00
parent a525ad82ec
commit 8109f3d9a9

View File

@ -256,6 +256,47 @@ function getAnswerGroups(
return answerGroups return answerGroups
} }
function groupBetsAndComments(
bets: Bet[],
comments: Comment[],
contract: Contract,
userId: string | undefined,
options: {
hideOutcome: boolean
abbreviated: boolean
smallAvatar: boolean
reversed: boolean
}
) {
const commentsWithoutBets = comments
.filter((comment) => !comment.betId)
.map((comment) => ({
type: 'comment' as const,
id: comment.id,
contract: contract,
comment,
bet: undefined,
truncate: false,
hideOutcome: true,
smallAvatar: false,
}))
const groupedBets = groupBets(bets, comments, contract, userId, options)
// 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 sortedBetsAndComments = _.sortBy(unorderedBetsAndComments, (item) => {
if (item.type === 'comment') {
return item.comment.createdTime
} else if (item.type === 'bet') {
return item.bet.createdTime
} else if (item.type === 'betgroup') {
return item.bets[0].createdTime
}
})
return sortedBetsAndComments
}
export function getAllContractActivityItems( export function getAllContractActivityItems(
contract: Contract, contract: Contract,
bets: Bet[], bets: Bet[],
@ -301,38 +342,14 @@ export function getAllContractActivityItems(
) )
) )
} else { } else {
const commentsWithoutBets = comments items.push(
.filter((comment) => !comment.betId) ...groupBetsAndComments(bets, comments, contract, user?.id, {
.map((comment) => ({ hideOutcome: false,
type: 'comment' as const, abbreviated,
id: comment.id,
contract: contract,
comment,
bet: undefined,
truncate: false,
hideOutcome: true,
smallAvatar: false, smallAvatar: false,
})) reversed,
})
const groupedBets = groupBets(bets, comments, contract, user?.id, { )
hideOutcome: false,
abbreviated,
smallAvatar: false,
reversed: false,
})
// 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 sortedBetsAndComments = _.sortBy(unorderedBetsAndComments, (item) => {
if (item.type === 'comment') {
return item.comment.createdTime
} else if (item.type === 'bet') {
return item.bet.createdTime
} else if (item.type === 'betgroup') {
return item.bets[0].createdTime
}
})
items.push(...sortedBetsAndComments)
} }
if (contract.closeTime && contract.closeTime <= Date.now()) { if (contract.closeTime && contract.closeTime <= Date.now()) {
@ -392,7 +409,7 @@ export function getRecentContractActivityItems(
reversed: false, reversed: false,
} }
) )
: groupBets(bets, comments, contract, user?.id, { : groupBetsAndComments(bets, comments, contract, user?.id, {
hideOutcome: false, hideOutcome: false,
abbreviated: true, abbreviated: true,
smallAvatar: false, smallAvatar: false,