Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/resolvers/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,17 @@ export default {
}
return { id }
},
unsubscribeThread: async (parent, { id }, { me, models }) => {
if (!me) throw new GqlAuthenticationError()
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
`
return { id }
},
deleteItem: async (parent, { id }, { me, models }) => {
const old = await models.item.findUnique({ where: { id: Number(id) } })
if (Number(old.userId) !== Number(me?.id)) {
Expand Down
1 change: 1 addition & 0 deletions api/typeDefs/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default gql`
bookmarkItem(id: ID): Item
pinItem(id: ID): Item
subscribeItem(id: ID): Item
unsubscribeThread(id: ID!): Item
deleteItem(id: ID): Item
upsertLink(
id: ID, subNames: [String!], title: String!, url: String!, text: String, forward: [ItemForwardInput],
Expand Down
38 changes: 36 additions & 2 deletions components/notifications.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect, useMemo, useCallback } from 'react'
import { gql } from '@apollo/client'
import { useQuery } from '@apollo/client/react'
import { useMutation, useQuery } from '@apollo/client/react'
import Comment, { CommentSkeleton } from './comment'
import Item from './item'
import ItemJob from './item-job'
Expand Down Expand Up @@ -716,7 +716,41 @@ function JobChanged ({ n }) {
}

function Reply ({ n }) {
return <NoteItem item={n.item} />
const toaster = useToast()
const [unsubscribed, setUnsubscribed] = useState(false)
const [unsubscribeThread] = useMutation(
gql`
mutation unsubscribeThread($id: ID!) {
unsubscribeThread(id: $id) {
id
}
}
`
)
return (
<>
<NoteItem item={n.item} />
{!unsubscribed && (
<div className='text-end'>
<span
className='text-muted small pointer'
onClick={async () => {
try {
await unsubscribeThread({ variables: { id: n.item.id } })
setUnsubscribed(true)
toaster.success('unsubscribed from thread')
} catch (err) {
console.error(err)
toaster.danger('failed to unsubscribe from thread')
}
}}
>
unsubscribe from thread
</span>
</div>
)}
</>
)
}

function FollowActivity ({ n }) {
Expand Down