feat(server): received receipts cleanup

This commit is contained in:
Dimitrie Stefanescu
2021-10-05 16:28:13 +01:00
parent bef4974360
commit ff166927d4
8 changed files with 120 additions and 54 deletions
@@ -17,22 +17,23 @@
{{ commit.message }}
</v-list-item-title>
<v-list-item-subtitle class="caption">
<b>{{ commit.authorName }}</b>&nbsp;
<b>{{ commit.authorName }}</b>
&nbsp;
<timeago :datetime="commit.createdAt"></timeago>
({{ commitDate }})
</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action >
<v-list-item-action>
<p class="text-end mt-2 mb-0">
<v-list-item-title >
{{ "Received" }}
</v-list-item-title>
<v-list-item-title>Received</v-list-item-title>
</p>
<v-list-item-subtitle class="mt-2 caption">
<p> {{"by"}} &nbsp;
<b>{{ commit.authorName }}</b>&nbsp;
<timeago :datetime="commit.createdAt"></timeago>
<p>
by
<b>{{ commit.authorName }}</b>
&nbsp;
<timeago :datetime="commit.createdAt"></timeago>
</p>
</v-list-item-subtitle>
</v-list-item-action>
@@ -49,7 +50,12 @@
<v-list-item-action>
<div>
<span v-if="commit.branchName" class="caption">
<v-chip small v-tooltip="`On branch '${commit.branchName}'`" color="primary" :to="`/streams/${streamId}/branches/${commit.branchName}`">
<v-chip
v-tooltip="`On branch '${commit.branchName}'`"
small
color="primary"
:to="`/streams/${streamId}/branches/${commit.branchName}`"
>
<v-icon small class="mr-2">mdi-source-branch</v-icon>
{{ commit.branchName }}
</v-chip>
@@ -57,16 +63,57 @@
<source-app-avatar :application-name="commit.sourceApplication" />
</div>
</v-list-item-action>
<br />
{{ activity ? uniqueUsersThatReceived : 'loading' }}
</v-list-item>
</template>
<script>
import gql from 'graphql-tag'
import UserAvatar from './UserAvatar'
import SourceAppAvatar from './SourceAppAvatar'
export default {
components: { UserAvatar, SourceAppAvatar },
props: ['commit', 'streamId', 'route'],
apollo: {
activity: {
query: gql`
query CommitActivity($streamId: String!, $commitId: String!) {
stream(id: $streamId) {
id
commit(id: $commitId) {
id
activity(actionType: "commit_receive", limit: 200) {
items {
info
time
userId
message
}
}
}
}
}
`,
update: (data) => data.stream.commit.activity,
variables() {
return {
streamId: this.streamId,
commitId: this.commit.id
}
},
skip() {
if (!this.streamId || !this.commit) return true
return false
}
}
},
data() {
return {
activity: null,
uniqueUsersThatReceived: []
}
},
computed: {
commitDate() {
if (!this.commit) return null
@@ -82,6 +129,14 @@ export default {
}/branches/${encodeURIComponent(this.commit.branchName)}`
}
},
watch: {
activity(val) {
console.log(val.items)
let set = new Set()
val.items.forEach((item) => set.add(item.userId))
this.uniqueUsersThatReceived = Array.from( set )
}
},
methods: {
goToBranch() {
this.$router.push(this.branchUrl)
-1
View File
@@ -11,7 +11,6 @@ query Stream($streamid: String!, $id: String!) {
authorId
authorAvatar
createdAt
received
branchName
sourceApplication
}
@@ -43,6 +43,15 @@ module.exports = {
return { items, cursor, totalCount }
}
},
},
Commit: {
async activity( parent, args, context, info ) {
let { items, cursor } = await getResourceActivity( { resourceType: 'commit', resourceId: parent.id, actionType: args.actionType, after: args.after, before: args.before, cursor: args.cursor, limit: args.limit } )
let totalCount = await getActivityCountByResourceId( { resourceId: parent.id, actionType: args.actionType, after: args.after, before: args.before } )
return { items, cursor, totalCount }
}
}
}
@@ -30,6 +30,15 @@ extend type Branch {
@hasScope(scope: "streams:read")
}
extend type Commit {
"""
All the recent activity on this commit in chronological order
"""
activity(actionType: String, after: DateTime, before: DateTime, cursor: DateTime, limit: Int! = 25): ActivityCollection
@hasRole(role: "server:user")
@hasScope(scope: "streams:read")
}
type ActivityCollection {
totalCount: Int!
cursor: String
@@ -18,7 +18,6 @@ module.exports = {
userId, // populated by the api
info: JSON.stringify( info ), // can be anything with conventions! (TBD)
message, // something human understandable for frontend purposes mostly
received
}
await StreamActivity( ).insert( dbObject )
if ( streamId ) {
@@ -21,6 +21,10 @@ const {
getCommitsTotalCountByBranchId
} = require( '../../services/commits' )
const { getStream } = require( '../../services/streams' )
const { getUser } = require( '../../services/users' )
// subscription events
const COMMIT_CREATED = 'COMMIT_CREATED'
const COMMIT_UPDATED = 'COMMIT_UPDATED'
@@ -131,32 +135,37 @@ module.exports = {
},
async commitReceive( parent, args, context, info ) {
await authorizeResolver( context.userId, args.commit.streamId, 'stream:contributor' )
// if the request is NOT authenticated (ie, there's no user behind it), return/throw error
// Above is BS: route guards prevent anon requests
let commit = await getCommitById( { id: args.commit.id } )
if ( commit.authorId !== context.userId )
throw new ForbiddenError( 'Only the author of a commit may update it.' )
let receivedd = await receiveCommit( { ...args.commit } )
if ( receivedd ) {
await saveActivity( {
streamId: args.commit.streamId,
resourceType: 'commit',
resourceId: args.commit.id,
actionType: 'commit_receive',
userId: context.userId,
info: { old: commit, new: args.commit },
message: `Commit was received: ${args.commit.id} (${args.commit.message})`,
received: args.commit.received
} )
await pubsub.publish( COMMIT_RECEIVED, {
commitReceived: { ...args.commit },
streamId: args.commit.streamId,
commitId: args.commit.id
} )
// if stream is private, check if the user has access to it
console.log()
let stream = await getStream( { streamId: args.input.streamId } )
if ( !stream.public ) {
await authorizeResolver( context.userId, args.input.streamId, 'stream:reviewer' )
}
return receivedd
let commit = await getCommitById( { id: args.input.commitId } )
let user = await getUser( context.userId )
await saveActivity( {
streamId: args.input.streamId,
resourceType: 'commit',
resourceId: args.input.commitId,
actionType: 'commit_receive',
userId: context.userId,
info: { sourceApplication: args.input.sourceApplication, message: args.input.message },
message: `Commit ${args.input.commitId} was received by ${user.name}.`,
} )
// await pubsub.publish( COMMIT_RECEIVED, {
// commitReceived: { ...args.commit },
// streamId: args.commit.streamId,
// commitId: args.commit.id
// } )
return true
},
async commitDelete( parent, args, context, info ) {
@@ -29,7 +29,6 @@ type Commit {
authorId: String
authorAvatar: String
createdAt: DateTime
received: String
}
type CommitCollectionUserNode {
@@ -43,7 +42,6 @@ type CommitCollectionUserNode {
streamId: String
streamName: String
createdAt: DateTime
received: String
}
type BranchCollection {
@@ -81,7 +79,7 @@ extend type Mutation {
commitUpdate(commit: CommitUpdateInput!): Boolean!
@hasRole(role: "server:user")
@hasScope(scope: "streams:write")
commitReceive(commit: CommitReceivedInput!): Boolean!
commitReceive(input: CommitReceivedInput!): Boolean!
@hasRole(role: "server:user")
@hasScope(scope: "streams:write")
commitDelete(commit: CommitDeleteInput!): Boolean!
@@ -123,12 +121,6 @@ extend type Subscription {
@hasRole(role: "server:user")
@hasScope(scope: "streams:read")
"""
Subscribe to commit receive event.
"""
commitReceived(streamId: String!, commitId: String): JSONObject
@hasRole(role: "server:user")
@hasScope(scope: "streams:read")
"""
Subscribe to commit deleted event
"""
commitDeleted(streamId: String!): JSONObject
@@ -166,7 +158,6 @@ input CommitCreateInput {
"""
previousCommitIds: [String]
parents: [String]
received: String
}
input CommitUpdateInput {
@@ -177,10 +168,9 @@ input CommitUpdateInput {
input CommitReceivedInput {
streamId: String!
id: String!
parents: [String]
message: String!
received: String
commitId: String!
sourceApplication: String!
message: String
}
input CommitDeleteInput {
@@ -60,10 +60,6 @@ module.exports = {
return await Commits( ).where( { id: id } ).update( { message: message } )
},
async receiveCommit( { id, message, received } ) {
return await Commits( ).where( { id: id } ).update( { message: message, received: received } )
},
async getCommitById( { id } ) {
let query = await Commits( )
.columns( [ { id: 'commits.id' }, 'message', 'referencedObject', 'sourceApplication', 'totalChildrenCount', 'parents', 'commits.createdAt', { branchName: 'branches.name' }, { authorName: 'users.name' }, { authorId: 'users.id' }, { authorAvatar: 'users.avatar' } ] )