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 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 }) => {
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
            })
 | 
			
		||||
          })
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user