fix viewing stacker's bookmarks
This commit is contained in:
parent
738bd052f1
commit
9745b82d63
|
@ -105,7 +105,7 @@ const orderByClause = async (by, me, models, type) => {
|
||||||
case 'votes':
|
case 'votes':
|
||||||
return await topOrderByWeightedSats(me, models)
|
return await topOrderByWeightedSats(me, models)
|
||||||
default:
|
default:
|
||||||
return `ORDER BY "${type === 'bookmarks' ? 'Bookmark' : 'Item'}".created_at DESC`
|
return `ORDER BY ${type === 'bookmarks' ? '"bookmarkCreatedAt"' : '"Item".created_at'} DESC`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,13 +221,13 @@ async function itemQueryWithMeta ({ me, models, query, orderBy = '' }, ...args)
|
||||||
} else {
|
} else {
|
||||||
return await models.$queryRawUnsafe(`
|
return await models.$queryRawUnsafe(`
|
||||||
SELECT "Item".*, to_json(users.*) as user, COALESCE("ItemAct"."meMsats", 0) as "meMsats",
|
SELECT "Item".*, to_json(users.*) as user, COALESCE("ItemAct"."meMsats", 0) as "meMsats",
|
||||||
COALESCE("ItemAct"."meDontLike", false) as "meDontLike", "Bookmark"."itemId" IS NOT NULL AS "meBookmark",
|
COALESCE("ItemAct"."meDontLike", false) as "meDontLike", b."itemId" IS NOT NULL AS "meBookmark",
|
||||||
"ThreadSubscription"."itemId" IS NOT NULL AS "meSubscription"
|
"ThreadSubscription"."itemId" IS NOT NULL AS "meSubscription"
|
||||||
FROM (
|
FROM (
|
||||||
${query}
|
${query}
|
||||||
) "Item"
|
) "Item"
|
||||||
JOIN users ON "Item"."userId" = users.id
|
JOIN users ON "Item"."userId" = users.id
|
||||||
LEFT JOIN "Bookmark" ON "Bookmark"."itemId" = "Item".id AND "Bookmark"."userId" = ${me.id}
|
LEFT JOIN "Bookmark" b ON b."itemId" = "Item".id AND b."userId" = ${me.id}
|
||||||
LEFT JOIN "ThreadSubscription" ON "ThreadSubscription"."itemId" = "Item".id AND "ThreadSubscription"."userId" = ${me.id}
|
LEFT JOIN "ThreadSubscription" ON "ThreadSubscription"."itemId" = "Item".id AND "ThreadSubscription"."userId" = ${me.id}
|
||||||
LEFT JOIN LATERAL (
|
LEFT JOIN LATERAL (
|
||||||
SELECT "itemId", sum("ItemAct".msats) FILTER (WHERE act = 'FEE' OR act = 'TIP') AS "meMsats",
|
SELECT "itemId", sum("ItemAct".msats) FILTER (WHERE act = 'FEE' OR act = 'TIP') AS "meMsats",
|
||||||
|
@ -261,6 +261,10 @@ const relationClause = (type) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selectClause = (type) => type === 'bookmarks'
|
||||||
|
? `${SELECT}, "Bookmark"."created_at" as "bookmarkCreatedAt"`
|
||||||
|
: SELECT
|
||||||
|
|
||||||
const subClauseTable = (type) => COMMENT_TYPE_QUERY.includes(type) ? 'root' : 'Item'
|
const subClauseTable = (type) => COMMENT_TYPE_QUERY.includes(type) ? 'root' : 'Item'
|
||||||
|
|
||||||
const activeOrMine = (me) => {
|
const activeOrMine = (me) => {
|
||||||
|
@ -301,7 +305,7 @@ export default {
|
||||||
me,
|
me,
|
||||||
models,
|
models,
|
||||||
query: `
|
query: `
|
||||||
${SELECT}
|
${selectClause(type)}
|
||||||
${relationClause(type)}
|
${relationClause(type)}
|
||||||
WHERE "${table}"."userId" = $2 AND "${table}".created_at <= $1
|
WHERE "${table}"."userId" = $2 AND "${table}".created_at <= $1
|
||||||
${subClause(sub, 5, subClauseTable(type))}
|
${subClause(sub, 5, subClauseTable(type))}
|
||||||
|
@ -338,7 +342,7 @@ export default {
|
||||||
me,
|
me,
|
||||||
models,
|
models,
|
||||||
query: `
|
query: `
|
||||||
${SELECT}
|
${selectClause(type)}
|
||||||
${relationClause(type)}
|
${relationClause(type)}
|
||||||
WHERE "Item".created_at <= $1
|
WHERE "Item".created_at <= $1
|
||||||
AND "Item"."pinId" IS NULL AND "Item"."deletedAt" IS NULL
|
AND "Item"."pinId" IS NULL AND "Item"."deletedAt" IS NULL
|
||||||
|
@ -883,7 +887,7 @@ export default {
|
||||||
},
|
},
|
||||||
meDontLike: async (item, args, { me, models }) => {
|
meDontLike: async (item, args, { me, models }) => {
|
||||||
if (!me) return false
|
if (!me) return false
|
||||||
if (typeof item.meDontLike === 'boolean') return item.meDontLike
|
if (typeof item.meDontLike !== 'undefined') return item.meDontLike
|
||||||
|
|
||||||
const dontLike = await models.itemAct.findFirst({
|
const dontLike = await models.itemAct.findFirst({
|
||||||
where: {
|
where: {
|
||||||
|
@ -897,7 +901,7 @@ export default {
|
||||||
},
|
},
|
||||||
meBookmark: async (item, args, { me, models }) => {
|
meBookmark: async (item, args, { me, models }) => {
|
||||||
if (!me) return false
|
if (!me) return false
|
||||||
if (typeof item.meBookmark === 'boolean') return item.meBookmark
|
if (typeof item.meBookmark !== 'undefined') return item.meBookmark
|
||||||
|
|
||||||
const bookmark = await models.bookmark.findUnique({
|
const bookmark = await models.bookmark.findUnique({
|
||||||
where: {
|
where: {
|
||||||
|
@ -912,7 +916,7 @@ export default {
|
||||||
},
|
},
|
||||||
meSubscription: async (item, args, { me, models }) => {
|
meSubscription: async (item, args, { me, models }) => {
|
||||||
if (!me) return false
|
if (!me) return false
|
||||||
if (typeof item.meSubscription === 'boolean') return item.meSubscription
|
if (typeof item.meSubscription !== 'undefined') return item.meSubscription
|
||||||
|
|
||||||
const subscription = await models.threadSubscription.findUnique({
|
const subscription = await models.threadSubscription.findUnique({
|
||||||
where: {
|
where: {
|
||||||
|
|
Loading…
Reference in New Issue