Browse Source

Merge pull request #2898 from Lezek123/giza-qn-channel-collab

Giza query node: Support for channel collaboration feature
Mokhtar Naamani 3 years ago
parent
commit
f5e93a624a

+ 10 - 6
query-node/mappings/content/channel.ts

@@ -4,7 +4,7 @@ eslint-disable @typescript-eslint/naming-convention
 import { EventContext, StoreContext } from '@joystream/hydra-common'
 import { Content } from '../generated/types'
 import { convertContentActorToChannelOwner, processChannelMetadata } from './utils'
-import { Channel, ChannelCategory, StorageDataObject } from 'query-node/dist/model'
+import { Channel, ChannelCategory, StorageDataObject, Membership } from 'query-node/dist/model'
 import { deserializeMetadata, inconsistentState, logger } from '../common'
 import { ChannelCategoryMetadata, ChannelMetadata } from '@joystream/metadata-protobuf'
 import { integrateMeta } from '@joystream/metadata-protobuf/utils'
@@ -14,9 +14,7 @@ import { removeDataObject } from '../storage/utils'
 export async function content_ChannelCreated(ctx: EventContext & StoreContext): Promise<void> {
   const { store, event } = ctx
   // read event data
-  const [contentActor, channelId, runtimeChannel, channelCreationParameters] = new Content.ChannelCreatedEvent(
-    event
-  ).params
+  const [contentActor, channelId, , channelCreationParameters] = new Content.ChannelCreatedEvent(event).params
 
   // create entity
   const channel = new Channel({
@@ -26,12 +24,14 @@ export async function content_ChannelCreated(ctx: EventContext & StoreContext):
     videos: [],
     createdInBlock: event.blockNumber,
     rewardAccount: channelCreationParameters.reward_account.unwrapOr(undefined)?.toString(),
-    deletionPrizeDestAccount: runtimeChannel.deletion_prize_source_account_id.toString(),
     // fill in auto-generated fields
     createdAt: new Date(event.blockTimestamp),
     updatedAt: new Date(event.blockTimestamp),
     // prepare channel owner (handles fields `ownerMember` and `ownerCuratorGroup`)
     ...(await convertContentActorToChannelOwner(store, contentActor)),
+    collaborators: Array.from(channelCreationParameters.collaborators).map(
+      (id) => new Membership({ id: id.toString() })
+    ),
   })
 
   // deserialize & process metadata
@@ -76,13 +76,17 @@ export async function content_ChannelUpdated(ctx: EventContext & StoreContext):
 
   // prepare changed reward account
   const newRewardAccount = channelUpdateParameters.reward_account.unwrapOr(null)
-
   // reward account change happened?
   if (newRewardAccount) {
     // this will change the `channel`!
     channel.rewardAccount = newRewardAccount.unwrapOr(undefined)?.toString()
   }
 
+  const newCollaborators = channelUpdateParameters.collaborators.unwrapOr(undefined)
+  if (newCollaborators) {
+    channel.collaborators = Array.from(newCollaborators).map((id) => new Membership({ id: id.toString() }))
+  }
+
   // set last update time
   channel.updatedAt = new Date(event.blockTimestamp)
 

+ 5 - 3
query-node/schemas/content.graphql

@@ -35,9 +35,6 @@ type Channel @entity {
   "Reward account where revenue is sent if set."
   rewardAccount: String
 
-  "Destination account for the prize associated with channel deletion"
-  deletionPrizeDestAccount: String!
-
   "The title of the Channel"
   title: String @fulltext(query: "search")
 
@@ -61,9 +58,14 @@ type Channel @entity {
   "The primary langauge of the channel's content"
   language: Language
 
+  "List of videos that belong to the channel"
   videos: [Video!]! @derivedFrom(field: "channel")
 
+  "Number of the block the channel was created in"
   createdInBlock: Int!
+
+  "List of channel collaborators (members)"
+  collaborators: [Membership!]
 }
 
 type CuratorGroup @entity {

+ 4 - 0
query-node/schemas/membership.graphql

@@ -33,5 +33,9 @@ type Membership @entity {
   "The type of subscription the member has purchased if any."
   subscription: Int
 
+  "List of channels the member owns"
   channels: [Channel!]! @derivedFrom(field: "ownerMember")
+
+  "List of channels the member has collaborator access to"
+  collaboratorInChannels: [Channel!] @derivedFrom(field: "collaborators")
 }