feat(comments): deletion handled properly in frontend
This commit is contained in:
@@ -185,7 +185,7 @@ export default {
|
||||
let commentInput = {
|
||||
streamId: this.$route.params.streamId,
|
||||
resources: [
|
||||
{ resourceType: 'stream', resourceId: this.$route.params.streamId }, // TODO: remove
|
||||
// { resourceType: 'stream', resourceId: this.$route.params.streamId }, // TODO: remove
|
||||
{
|
||||
resourceType: this.$route.path.includes('object') ? 'object' : 'commit',
|
||||
resourceId: this.$route.params.resourceId
|
||||
|
||||
@@ -186,20 +186,29 @@ export default {
|
||||
$subscribe: {
|
||||
commentActivity: {
|
||||
query: gql`
|
||||
subscription($streamId: String!, $resourceId: String!) {
|
||||
commentActivity(streamId: $streamId, resourceId: $resourceId)
|
||||
subscription($streamId: String!, $resourceIds: [String]) {
|
||||
commentActivity(streamId: $streamId, resourceIds: $resourceIds)
|
||||
}
|
||||
`,
|
||||
variables() {
|
||||
let resIds = [this.$route.params.resourceId]
|
||||
if(this.$route.query.overlay) resIds = [...resIds, ...this.$route.query.overlay.split(',')]
|
||||
return {
|
||||
streamId: this.$route.params.streamId,
|
||||
resourceId: this.$route.params.resourceId
|
||||
resourceIds: resIds
|
||||
}
|
||||
},
|
||||
skip() {
|
||||
return !this.$loggedIn() || !this.$route.params.resourceId
|
||||
},
|
||||
error(e) {
|
||||
console.log(e)
|
||||
this.$eventHub.$emit('notification', {
|
||||
text: 'Failed to subscribe to live events: ' + e.message
|
||||
})
|
||||
},
|
||||
result({ data }) {
|
||||
console.log(data)
|
||||
if (!data.commentActivity) return
|
||||
// Creation
|
||||
if (data.commentActivity.eventType === 'comment-added') {
|
||||
@@ -229,9 +238,6 @@ export default {
|
||||
computed: {
|
||||
hasExpandedComment() {
|
||||
return this.localComments.filter((c) => c.expanded).length !== 0
|
||||
},
|
||||
flatComments() {
|
||||
return this.comments ? this.localComments : []
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
@@ -332,9 +338,15 @@ export default {
|
||||
window.__viewer.sectionBox.off()
|
||||
}
|
||||
},
|
||||
handleDeletion(comment) {
|
||||
async handleDeletion(comment) {
|
||||
this.collapseComment(comment)
|
||||
this.localComments = this.localComments.filter((c) => c.id !== comment.id)
|
||||
// this.localComments = []
|
||||
// await this.$apollo.queries.comments.refetch()
|
||||
// this.updateCommentBubbles()
|
||||
this.$store.commit('setCommentSelection', { comment: null })
|
||||
let indx = this.localComments.findIndex(c => c.id === comment.id)
|
||||
this.localComments.splice(indx, 1)
|
||||
this.updateCommentBubbles()
|
||||
},
|
||||
updateCommentBubbles() {
|
||||
if (!this.comments) return
|
||||
|
||||
@@ -96,13 +96,11 @@ export default {
|
||||
query: gql`
|
||||
query(
|
||||
$streamId: String!
|
||||
$resources: [ResourceIdentifierInput]!
|
||||
$archived: Boolean!
|
||||
$cursor: String
|
||||
) {
|
||||
comments(
|
||||
streamId: $streamId
|
||||
resources: $resources
|
||||
limit: 10
|
||||
archived: $archived
|
||||
cursor: $cursor
|
||||
@@ -119,15 +117,10 @@ export default {
|
||||
return {
|
||||
streamId: this.$route.params.streamId,
|
||||
archived: this.showArchivedComments,
|
||||
resources: [
|
||||
{
|
||||
resourceType: 'stream',
|
||||
resourceId: this.$route.params.streamId
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
result({ data }) {
|
||||
if(!data) return
|
||||
this.cursor = data.comments.cursor
|
||||
for (let c of data.comments.items) {
|
||||
if (this.localComments.findIndex((lc) => c.id === lc.id) === -1)
|
||||
|
||||
@@ -67,8 +67,9 @@ module.exports = {
|
||||
await pubsub.publish( 'COMMENT_ACTIVITY', {
|
||||
commentActivity: { ...args.input, authorId: context.userId, id, replies: { totalCount: 0 }, updatedAt: Date.now(), createdAt: Date.now(), eventType: 'comment-added' },
|
||||
streamId: args.input.streamId,
|
||||
resourceId: args.input.resources[1].resourceId // TODO: hack for now
|
||||
resourceIds: args.input.resources.map( res => res.resourceId ).join(',') // TODO: hack for now
|
||||
})
|
||||
|
||||
return id
|
||||
},
|
||||
|
||||
@@ -119,7 +120,13 @@ module.exports = {
|
||||
commentActivity: {
|
||||
subscribe: withFilter(() => pubsub.asyncIterator(['COMMENT_ACTIVITY']), async (payload, variables, context) => {
|
||||
await authorizeResolver(context.userId, payload.streamId, 'stream:reviewer')
|
||||
return payload.streamId === variables.streamId && payload.resourceId === variables.resourceId
|
||||
|
||||
if(!payload.resourceIds)
|
||||
return payload.streamId === variables.streamId
|
||||
|
||||
for(let res of variables.resourceIds)
|
||||
if(payload.resourceIds.includes( res ) && payload.streamId === variables.streamId) return true
|
||||
return false
|
||||
})
|
||||
},
|
||||
commentThreadActivity: {
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
extend type Query {
|
||||
comment(id: String!, streamId: String!): Comment
|
||||
|
||||
comments(streamId: String!, resources: [ResourceIdentifierInput]!, limit: Int = 25, cursor: String, archived: Boolean! = false): CommentCollection
|
||||
"""
|
||||
This query can be used in the follwing ways:
|
||||
- get all the comments for a stream: do not pass in any resource identifiers.
|
||||
- get the comments targeting any of a set of provided resources (comments/objects): pass in an array of resources.
|
||||
"""
|
||||
comments(streamId: String!, resources: [ResourceIdentifierInput], limit: Int = 25, cursor: String, archived: Boolean! = false): CommentCollection
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +65,7 @@ input CommentCreateInput {
|
||||
Specfies the resources this comment is linked to. There are several usecases:
|
||||
- a comment targets only one resource (commit or object)
|
||||
- a comment targets one or more resources (commits or objects)
|
||||
- a comment targets
|
||||
- a comment targets only a stream
|
||||
"""
|
||||
resources: [ResourceIdentifierInput]!
|
||||
text: String!
|
||||
@@ -139,7 +143,7 @@ extend type Subscription {
|
||||
"""
|
||||
userViewerActivity(streamId: String!, resourceId: String!): JSONObject
|
||||
|
||||
commentActivity(streamId: String!, resourceId: String!): JSONObject
|
||||
commentActivity(streamId: String!, resourceIds: [String]): JSONObject
|
||||
@hasRole(role: "server:user")
|
||||
@hasScope(scope: "streams:read")
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ module.exports = {
|
||||
return true
|
||||
},
|
||||
|
||||
async getComments( { resources, limit, cursor, userId = null, replies = false, archived = false } ) {
|
||||
async getComments( { resources, limit, cursor, userId = null, replies = false, streamId, archived = false } ) {
|
||||
let query = knex.with( 'comms', cte => {
|
||||
cte.select( ).distinctOn('id').from( 'comments' )
|
||||
cte.join( 'comment_links', 'comments.id', '=', 'commentId' )
|
||||
@@ -149,12 +149,16 @@ module.exports = {
|
||||
})
|
||||
}
|
||||
|
||||
cte.where(q => {
|
||||
// link resources
|
||||
for (let res of resources) {
|
||||
q.orWhere('comment_links.resourceId', '=', res.resourceId)
|
||||
}
|
||||
})
|
||||
if(resources && resources.length !== 0 ) {
|
||||
cte.where(q => {
|
||||
// link resources
|
||||
for (let res of resources) {
|
||||
q.orWhere('comment_links.resourceId', '=', res.resourceId)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
cte.where({streamId: streamId })
|
||||
}
|
||||
if (!replies) {
|
||||
cte.whereNull('parentComment')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user