diff --git a/api/resolvers/item.js b/api/resolvers/item.js index a45c032c..afa40c03 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -17,17 +17,17 @@ async function comments (me, models, id, sort) { let orderBy switch (sort) { case 'top': - orderBy = `ORDER BY ${await orderByNumerator(me, models)} DESC, "Item".msats DESC, "Item".id DESC` + orderBy = `ORDER BY ${await orderByNumerator(me, models)} DESC, "Item".msats DESC, ("Item".freebie IS FALSE) DESC, "Item".id DESC` break case 'recent': - orderBy = 'ORDER BY "Item".created_at DESC, "Item".msats DESC, "Item".id DESC' + orderBy = 'ORDER BY "Item".created_at DESC, "Item".msats DESC, ("Item".freebie IS FALSE) DESC, "Item".id DESC' break default: - orderBy = `ORDER BY ${await orderByNumerator(me, models)}/POWER(GREATEST(3, EXTRACT(EPOCH FROM (now_utc() - "Item".created_at))/3600), 1.3) DESC NULLS LAST, "Item".msats DESC, "Item".id DESC` + orderBy = `ORDER BY ${await orderByNumerator(me, models)}/POWER(GREATEST(3, EXTRACT(EPOCH FROM (now_utc() - "Item".created_at))/3600), 1.3) DESC NULLS LAST, "Item".msats DESC, ("Item".freebie IS FALSE) DESC, "Item".id DESC` break } - const filter = await filterClause(me, models) + const filter = await commentFilterClause(me, models) if (me) { const [{ item_comments_with_me: comments }] = await models.$queryRaw( 'SELECT item_comments_with_me($1, $2, $3, $4, $5)', Number(id), Number(me.id), COMMENT_DEPTH_LIMIT, filter, orderBy) @@ -110,6 +110,25 @@ export async function joinSatRankView (me, models) { return 'JOIN sat_rank_tender_view ON "Item".id = sat_rank_tender_view.id' } +export async function commentFilterClause (me, models) { + let clause = ` AND ("Item"."weightedVotes" - "Item"."weightedDownVotes" > -${ITEM_FILTER_THRESHOLD}` + if (me) { + const user = await models.user.findUnique({ where: { id: me.id } }) + // wild west mode has everything + if (user.wildWestMode) { + return '' + } + + // always include if it's mine + clause += ` OR "Item"."userId" = ${me.id}` + } + + // close the clause + clause += ')' + + return clause +} + export async function filterClause (me, models) { // by default don't include freebies unless they have upvotes let clause = ' AND (NOT "Item".freebie OR "Item"."weightedVotes" - "Item"."weightedDownVotes" > 0' diff --git a/components/comment.js b/components/comment.js index 4f48f416..6704a288 100644 --- a/components/comment.js +++ b/components/comment.js @@ -20,6 +20,7 @@ import Share from './share' import ItemInfo from './item-info' import { Badge } from 'react-bootstrap' import { RootProvider, useRoot } from './root' +import { useMe } from './me' function Parent ({ item, rootText }) { const root = useRoot() @@ -87,7 +88,12 @@ export default function Comment ({ rootText, noComments, noReply, truncate, depth }) { const [edit, setEdit] = useState() - const [collapse, setCollapse] = useState(false) + const me = useMe() + const [collapse, setCollapse] = useState( + !me?.wildWestMode && !me?.greeterMode && + !item.mine && item.freebie && item.wvotes <= 0 + ? 'yep' + : 'nope') const ref = useRef(null) const router = useRouter() const root = useRoot() @@ -101,7 +107,7 @@ export default function Comment ({ query: { id: router.query.id } }, undefined, { scroll: false }) } - setCollapse(localStorage.getItem(`commentCollapse:${item.id}`)) + setCollapse(localStorage.getItem(`commentCollapse:${item.id}`) || collapse) }, [item]) const bottomedOut = depth === COMMENT_DEPTH_LIMIT @@ -110,7 +116,7 @@ export default function Comment ({ return (