Also unsubscribe from any children (#2120)

This commit is contained in:
ekzyis 2025-04-22 15:02:36 +02:00 committed by GitHub
parent 838418ab81
commit 9fc819ec37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 2 deletions

View File

@ -838,8 +838,16 @@ export default {
const data = { itemId: Number(id), userId: me.id }
const old = await models.threadSubscription.findUnique({ where: { userId_itemId: data } })
if (old) {
await models.threadSubscription.delete({ where: { userId_itemId: data } })
} else await models.threadSubscription.create({ data })
await models.$executeRaw`
DELETE FROM "ThreadSubscription" ts
USING "Item" i
WHERE ts."userId" = ${me.id}
AND i.path <@ (SELECT path FROM "Item" WHERE id = ${Number(id)})
AND ts."itemId" = i.id
`
} else {
await models.threadSubscription.create({ data })
}
return { id }
},
deleteItem: async (parent, { id }, { me, models }) => {

View File

@ -20,6 +20,25 @@ export default function SubscribeDropdownItem ({ item: { id, meSubscription } })
},
optimistic: true
})
const unsubscribed = !subscribeItem.meSubscription
if (!unsubscribed) return
const cacheState = cache.extract()
Object.keys(cacheState)
.filter(key => key.startsWith('Item:'))
.forEach(key => {
cache.modify({
id: key,
fields: {
meSubscription: (existing, { readField }) => {
const path = readField('path')
return !path || !path.includes(id) ? existing : false
}
},
optimistic: true
})
})
}
}
)