Also unsubscribe from any children (#2120)
This commit is contained in:
parent
838418ab81
commit
9fc819ec37
@ -838,8 +838,16 @@ export default {
|
|||||||
const data = { itemId: Number(id), userId: me.id }
|
const data = { itemId: Number(id), userId: me.id }
|
||||||
const old = await models.threadSubscription.findUnique({ where: { userId_itemId: data } })
|
const old = await models.threadSubscription.findUnique({ where: { userId_itemId: data } })
|
||||||
if (old) {
|
if (old) {
|
||||||
await models.threadSubscription.delete({ where: { userId_itemId: data } })
|
await models.$executeRaw`
|
||||||
} else await models.threadSubscription.create({ data })
|
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 }
|
return { id }
|
||||||
},
|
},
|
||||||
deleteItem: async (parent, { id }, { me, models }) => {
|
deleteItem: async (parent, { id }, { me, models }) => {
|
||||||
|
@ -20,6 +20,25 @@ export default function SubscribeDropdownItem ({ item: { id, meSubscription } })
|
|||||||
},
|
},
|
||||||
optimistic: true
|
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
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user