Group older bets by 7-days
This commit is contained in:
parent
7ca0b3662f
commit
a82b3577d4
|
@ -77,14 +77,14 @@ export type ResolveItem = BaseActivityItem & {
|
||||||
const DAY_IN_MS = 24 * 60 * 60 * 1000
|
const DAY_IN_MS = 24 * 60 * 60 * 1000
|
||||||
|
|
||||||
// Group together bets that are:
|
// Group together bets that are:
|
||||||
// - Within `windowMs` of the first in the group
|
// - Within a day of the first in the group
|
||||||
|
// (Unless the bets are older: then are grouped by 7-days.)
|
||||||
// - Do not have a comment
|
// - Do not have a comment
|
||||||
// - Were not created by this user or the contract creator
|
// - Were not created by this user or the contract creator
|
||||||
// Return a list of ActivityItems
|
// Return a list of ActivityItems
|
||||||
function groupBets(
|
function groupBets(
|
||||||
bets: Bet[],
|
bets: Bet[],
|
||||||
comments: Comment[],
|
comments: Comment[],
|
||||||
windowMs: number,
|
|
||||||
contract: Contract,
|
contract: Contract,
|
||||||
userId: string | undefined,
|
userId: string | undefined,
|
||||||
options: {
|
options: {
|
||||||
|
@ -141,6 +141,12 @@ function groupBets(
|
||||||
for (const bet of bets) {
|
for (const bet of bets) {
|
||||||
const isCreator = userId === bet.userId
|
const isCreator = userId === bet.userId
|
||||||
|
|
||||||
|
// If first bet in group is older than 3 days, group by 7 days. Otherwise, group by 1 day.
|
||||||
|
const windowMs =
|
||||||
|
Date.now() - (group[0]?.createdTime ?? bet.createdTime) > DAY_IN_MS * 3
|
||||||
|
? DAY_IN_MS * 7
|
||||||
|
: DAY_IN_MS
|
||||||
|
|
||||||
if (commentsMap[bet.id] || isCreator) {
|
if (commentsMap[bet.id] || isCreator) {
|
||||||
pushGroup()
|
pushGroup()
|
||||||
// Create a single item for this
|
// Create a single item for this
|
||||||
|
@ -212,14 +218,11 @@ function getAnswerGroups(
|
||||||
(answer) => answer.id === outcome
|
(answer) => answer.id === outcome
|
||||||
) as Answer
|
) as Answer
|
||||||
|
|
||||||
let items = groupBets(
|
let items = groupBets(answerBets, answerComments, contract, user?.id, {
|
||||||
answerBets,
|
hideOutcome: true,
|
||||||
answerComments,
|
abbreviated,
|
||||||
DAY_IN_MS,
|
smallAvatar: true,
|
||||||
contract,
|
})
|
||||||
user?.id,
|
|
||||||
{ hideOutcome: true, abbreviated, smallAvatar: true }
|
|
||||||
)
|
|
||||||
|
|
||||||
if (abbreviated) items = items.slice(-2)
|
if (abbreviated) items = items.slice(-2)
|
||||||
|
|
||||||
|
@ -274,7 +277,7 @@ export function getAllContractActivityItems(
|
||||||
sortByProb: true,
|
sortByProb: true,
|
||||||
abbreviated,
|
abbreviated,
|
||||||
})
|
})
|
||||||
: groupBets(bets, comments, DAY_IN_MS, contract, user?.id, {
|
: groupBets(bets, comments, contract, user?.id, {
|
||||||
hideOutcome: !!filterToOutcome,
|
hideOutcome: !!filterToOutcome,
|
||||||
abbreviated,
|
abbreviated,
|
||||||
smallAvatar: !!filterToOutcome,
|
smallAvatar: !!filterToOutcome,
|
||||||
|
@ -313,7 +316,7 @@ export function getRecentContractActivityItems(
|
||||||
sortByProb: false,
|
sortByProb: false,
|
||||||
abbreviated: true,
|
abbreviated: true,
|
||||||
})
|
})
|
||||||
: groupBets(bets, comments, DAY_IN_MS, contract, user?.id, {
|
: groupBets(bets, comments, contract, user?.id, {
|
||||||
hideOutcome: false,
|
hideOutcome: false,
|
||||||
abbreviated: true,
|
abbreviated: true,
|
||||||
smallAvatar: false,
|
smallAvatar: false,
|
||||||
|
|
|
@ -658,7 +658,7 @@ function FeedBetGroup(props: {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="min-w-0 flex-1">
|
<div className={clsx('min-w-0 flex-1', outcomes.length === 1 && 'mt-1')}>
|
||||||
<div className="text-sm text-gray-500">
|
<div className="text-sm text-gray-500">
|
||||||
{outcomes.map((outcome, index) => (
|
{outcomes.map((outcome, index) => (
|
||||||
<Fragment key={outcome}>
|
<Fragment key={outcome}>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user