diff --git a/api/resolvers/item.js b/api/resolvers/item.js index 48014c45..279d2c26 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -125,7 +125,7 @@ async function itemQueryWithMeta ({ me, models, query, orderBy = '' }, ...args) COALESCE("ItemAct"."meMsats", 0) as "meMsats", COALESCE("ItemAct"."meDontLikeMsats", 0) as "meDontLikeMsats", b."itemId" IS NOT NULL AS "meBookmark", "ThreadSubscription"."itemId" IS NOT NULL AS "meSubscription", "ItemForward"."itemId" IS NOT NULL AS "meForward", - to_jsonb("Sub".*) as sub + to_jsonb("Sub".*) || jsonb_build_object('meMuteSub', "MuteSub"."userId" IS NOT NULL) as sub FROM ( ${query} ) "Item" @@ -135,6 +135,7 @@ async function itemQueryWithMeta ({ me, models, query, orderBy = '' }, ...args) LEFT JOIN "ThreadSubscription" ON "ThreadSubscription"."itemId" = "Item".id AND "ThreadSubscription"."userId" = ${me.id} LEFT JOIN "ItemForward" ON "ItemForward"."itemId" = "Item".id AND "ItemForward"."userId" = ${me.id} LEFT JOIN "Sub" ON "Sub"."name" = "Item"."subName" + LEFT JOIN "MuteSub" ON "Sub"."name" = "MuteSub"."subName" AND "MuteSub"."userId" = ${me.id} LEFT JOIN LATERAL ( SELECT "itemId", sum("ItemAct".msats) FILTER (WHERE act = 'FEE' OR act = 'TIP') AS "meMsats", sum("ItemAct".msats) FILTER (WHERE act = 'DONT_LIKE_THIS') AS "meDontLikeMsats" @@ -1034,17 +1035,14 @@ export default { mine: async (item, args, { me, models }) => { return me?.id === item.userId }, - root: async (item, args, { models }) => { + root: async (item, args, { models, me }) => { if (!item.rootId) { return null } if (item.root) { return item.root } - return await models.item.findUnique({ - where: { id: item.rootId }, - include: { sub: true } - }) + return await getItem(item, { id: item.rootId }, { me, models }) }, parent: async (item, args, { models }) => { if (!item.parentId) { diff --git a/api/resolvers/sub.js b/api/resolvers/sub.js index d32ced1c..b2a09bba 100644 --- a/api/resolvers/sub.js +++ b/api/resolvers/sub.js @@ -86,7 +86,7 @@ export default { LEFT JOIN "MuteSub" ON "Sub".name = "MuteSub"."subName" AND "MuteSub"."userId" = ${me.id}::INTEGER WHERE status <> 'STOPPED' GROUP BY "Sub".name, "MuteSub"."userId" - ORDER BY "MuteSub"."userId" NULLS FIRST, "Sub".name ASC + ORDER BY "Sub".name ASC ` } @@ -191,7 +191,7 @@ export default { return await models.user.findUnique({ where: { id: sub.userId } }) }, meMuteSub: async (sub, args, { models }) => { - return sub.MuteSub?.length > 0 + return sub.meMuteSub || sub.MuteSub?.length > 0 } } } diff --git a/components/item-info.js b/components/item-info.js index eaeea9fb..2ed16411 100644 --- a/components/item-info.js +++ b/components/item-info.js @@ -20,6 +20,7 @@ import ActionDropdown from './action-dropdown' import MuteDropdownItem from './mute' import { DropdownItemUpVote } from './upvote' import { useRoot } from './root' +import { MuteSubDropdownItem } from './territory-header' export default function ItemInfo ({ item, full, commentsText = 'comments', @@ -168,6 +169,11 @@ export default function ItemInfo ({