Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/db/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ export const COLLECTIONS_MANIFEST: CollectionsManifest = new Map([
['initiatorAddress', {}],
['context.colonyAddress', { sparse: true }],
['context.taskId', { sparse: true }],
['context.transactionHash', { sparse: true }],
],
},
],
Expand Down
18 changes: 17 additions & 1 deletion src/db/colonyMongoApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,9 @@ export class ColonyMongoApi {
* This way we ensure that the asignee always gets notified
*/
await this.subscribeToTask(initiator, taskId)
const workerExists = !!(await this.users.findOne({ walletAddress: workerAddress }))
const workerExists = !!(await this.users.findOne({
walletAddress: workerAddress,
}))
if (workerExists) {
await this.subscribeToTask(workerAddress, taskId)
}
Expand Down Expand Up @@ -1560,4 +1562,18 @@ export class ColonyMongoApi {
{ $set: update },
)
}

async sendTransactionMessage(
initiator: string,
transactionHash: string,
colonyAddress: string,
message: string,
) {
await this.tryGetUser(initiator)
return this.createEvent(initiator, EventType.TransactionMessage, {
transactionHash,
message,
colonyAddress,
})
}
}
8 changes: 8 additions & 0 deletions src/db/colonyMongoDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,4 +776,12 @@ export class ColonyMongoDataSource extends MongoDataSource<Collections, {}>

return ColonyMongoDataSource.transformToken(token)
}

async getTransactionMessages(transactionHash: string, ttl?: number) {
const query = { 'context.transactionHash': transactionHash }
const events = ttl
? await this.collections.events.findManyByQuery(query, { ttl })
: await this.collections.events.collection.find(query).toArray()
return events.map(ColonyMongoDataSource.transformEvent)
}
}
2 changes: 2 additions & 0 deletions src/graphql/__tests__/apolloServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Suggestion from '../typeDefs/Suggestion'
import Task from '../typeDefs/Task'
import TokenInfo from '../typeDefs/TokenInfo'
import SystemInfo from '../typeDefs/SystemInfo'
import Transaction from '../typeDefs/Transaction'
import User from '../typeDefs/User'
import scalars from '../typeDefs/scalars'
import { resolvers } from '../resolvers'
Expand Down Expand Up @@ -62,6 +63,7 @@ const typeDefs = [
Task,
TokenInfo,
SystemInfo,
Transaction,
User,
scalars,
]
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/eventContext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
TaskMessageEvent,
UnassignWorkerEvent,
UnlockNextLevelEvent,
TransactionMessageEvent,
} from './types'

interface EventContextMap {
Expand All @@ -49,6 +50,7 @@ interface EventContextMap {
[EventType.UnassignWorker]: UnassignWorkerEvent
[EventType.UnlockNextLevel]: UnlockNextLevelEvent
[EventType.NewUser]: NewUserEvent
[EventType.TransactionMessage]: TransactionMessageEvent
}

export type EventContextOfType<T extends EventType> = Omit<
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Task from './typeDefs/Task'
import TokenInfo from './typeDefs/TokenInfo'
import SystemInfo from './typeDefs/SystemInfo'
import User from './typeDefs/User'
import Transaction from './typeDefs/Transaction'
import scalars from './typeDefs/scalars'

const authenticate = (token: string) => {
Expand Down Expand Up @@ -79,6 +80,7 @@ export const createApolloServer = (db: Db, provider: Provider) => {
SystemInfo,
User,
scalars,
Transaction,
],
resolvers,
formatError: (err) => {
Expand Down
13 changes: 13 additions & 0 deletions src/graphql/resolvers/Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,19 @@ export const Mutation: MutationResolvers<ApolloContext> = {
await api.sendTaskMessage(userAddress, id, message)
return true
},
async sendTransactionMessage(
parent,
{ input: { transactionHash, message, colonyAddress } },
{ userAddress, api, dataSources: { data } },
) {
await api.sendTransactionMessage(
userAddress,
transactionHash,
colonyAddress,
message,
)
return true
},
// Domains
async createDomain(
parent,
Expand Down
11 changes: 11 additions & 0 deletions src/graphql/resolvers/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,15 @@ export const Query: QueryResolvers<ApolloContext> = {
const system = new SystemDataSource()
return system.getSystemInfo()
},
async transactionMessages(
parent,
{ transactionHash }: { transactionHash: string },
{ dataSources: { data } },
) {
const messages = await data.getTransactionMessages(transactionHash)
return {
transactionHash,
messages,
}
},
}
8 changes: 8 additions & 0 deletions src/graphql/typeDefs/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ export default gql`
submissionId: String!
}

type TransactionMessageEvent {
type: EventType!
transactionHash: String!
message: String!
colonyAddress: String!
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we also need to return person which added comment and time when this person added comment


union EventContext =
AcceptLevelTaskSubmissionEvent
| AssignWorkerEvent
Expand All @@ -196,6 +203,7 @@ export default gql`
| TaskMessageEvent
| UnassignWorkerEvent
| UnlockNextLevelEvent
| TransactionMessageEvent

type Event {
id: String!
Expand Down
7 changes: 7 additions & 0 deletions src/graphql/typeDefs/Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ export default gql`
id: String!
}

input SendTransactionMessageInput {
transactionHash: String!
message: String!
colonyAddress: String!
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure, we're not missing here person which added comment?


type Mutation {
# Colonies
createColony(input: CreateColonyInput!): Colony
Expand All @@ -273,6 +279,7 @@ export default gql`
editDomainName(input: EditDomainNameInput!): Domain
# Messages
sendTaskMessage(input: SendTaskMessageInput!): Boolean!
sendTransactionMessage(input: SendTransactionMessageInput!): Boolean!
# Notifications
markAllNotificationsAsRead: Boolean!
markNotificationAsRead(input: MarkNotificationAsReadInput!): Boolean!
Expand Down
1 change: 1 addition & 0 deletions src/graphql/typeDefs/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export default gql`
task(id: String!): Task!
tokenInfo(address: String!): TokenInfo!
systemInfo: SystemInfo!
transactionMessages(transactionHash: String!): TransactionMessages!
}
`
8 changes: 8 additions & 0 deletions src/graphql/typeDefs/Transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { gql } from 'apollo-server-express'

export default gql`
type TransactionMessages {
transactionHash: String!
messages: [Event!]!
}
`
1 change: 1 addition & 0 deletions src/graphql/typeDefs/scalars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ export default gql`
TaskMessage
UnassignWorker
UnlockNextLevel
TransactionMessage
}
`
Loading