Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds mappings for ChannelAssetsDeletedByModerator & VideoAssetsDeletedByModerator events #199

Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.1.0
### Additions
- Implements mappings for `Content.VideoAssetsDeletedByModerator` and `Content.ChannelAssetsDeletedByModerator` runtime events

# 3.0.1
### Misc
- add migration for the `Account` id field
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions schema/events.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ union EventData =
| ChannelPayoutsUpdatedEventData
| ChannelPaymentMadeEventData
| MemberBannedFromChannelEventData
| ChannelAssetsDeletedByModeratorEventData
| VideoAssetsDeletedByModeratorEventData

# Atlas use-case: `GetCommentEdits` query
type CommentCreatedEventData {
Expand Down Expand Up @@ -388,3 +390,33 @@ type MemberBannedFromChannelEventData {
"The action performed. TRUE if the member is being banned, FALSE if the member is being unbanned"
action: Boolean!
}

# Emitted when channel asset/s are deleted by the moderator
type ChannelAssetsDeletedByModeratorEventData {
"Channel whose assets were deleted"
channel: Channel!

"IDs of channel assets being deleted by moderator"
assetIds: [BigInt!]

"Actor who deleted the channel assets."
deletedBy: ContentActor!

"why the channel assets were deleted"
rationale: String!
}

# Emitted when video asset/s are deleted by the moderator
type VideoAssetsDeletedByModeratorEventData {
"Video whose assets were deleted"
video: Video!

"IDs of video assets being deleted by moderator"
assetIds: [BigInt!]

"Actor who deleted the video assets."
deletedBy: ContentActor!

"why the video assets were deleted"
rationale: String!
}
24 changes: 24 additions & 0 deletions src/mappings/content/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ChannelRewardClaimedEventData,
ChannelRewardClaimedAndWithdrawnEventData,
ChannelFundsWithdrawnEventData,
ChannelAssetsDeletedByModeratorEventData,
} from '../../model'
import { deserializeMetadata, genericEventFields, toAddress, u8aToBytes } from '../utils'
import {
Expand All @@ -26,6 +27,7 @@ import { processAppActionMetadata, deleteChannel, encodeAssets, parseContentActo
import { Flat } from '../../utils/overlay'
import { DecodedMetadataObject } from '@joystream/metadata-protobuf/types'
import { generateAppActionCommitment } from '@joystream/js/utils'
import { ContentChannelAssetsDeletedByModeratorEvent } from '../../types/events'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not used apparently

Suggested change
import { ContentChannelAssetsDeletedByModeratorEvent } from '../../types/events'


export async function processChannelCreatedEvent({
overlay,
Expand Down Expand Up @@ -154,6 +156,28 @@ export async function processChannelDeletedByModeratorEvent({
await deleteChannel(overlay, channelId)
}

export async function processChannelAssetsDeletedByModeratorEvent({
block,
indexInBlock,
extrinsicHash,
overlay,
event: {
asV1000: [deletedBy, channelId, assetIds, rationale],
},
}: EventHandlerContext<'Content.ChannelAssetsDeletedByModerator'>): Promise<void> {
const channel = await overlay.getRepository(Channel).getByIdOrFail(channelId.toString())

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe also here you should deleted relevant StorageDataObjects.

overlay.getRepository(Event).new({
...genericEventFields(overlay, block, indexInBlock, extrinsicHash),
data: new ChannelAssetsDeletedByModeratorEventData({
channel: channel.id,
assetIds,
deletedBy: parseContentActor(deletedBy),
rationale: rationale.toString(),
}),
})
}

export async function processChannelVisibilitySetByModeratorEvent({
overlay,
event: {
Expand Down
45 changes: 42 additions & 3 deletions src/mappings/content/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,28 @@ import {
} from '@joystream/metadata-protobuf'
import { DecodedMetadataObject } from '@joystream/metadata-protobuf/types'
import { integrateMeta } from '@joystream/metadata-protobuf/utils'
import { Channel, Video, VideoViewEvent } from '../../model'
import {
Channel,
Event,
Video,
VideoAssetsDeletedByModeratorEventData,
VideoViewEvent,
} from '../../model'
import { EventHandlerContext } from '../../utils/events'
import { deserializeMetadata, u8aToBytes, videoRelevanceManager } from '../utils'
import {
deserializeMetadata,
genericEventFields,
u8aToBytes,
videoRelevanceManager,
} from '../utils'
import { processVideoMetadata } from './metadata'
import { deleteVideo, encodeAssets, processAppActionMetadata, processNft } from './utils'
import {
deleteVideo,
encodeAssets,
parseContentActor,
processAppActionMetadata,
processNft,
} from './utils'
import { generateAppActionCommitment } from '@joystream/js/utils'

export async function processVideoCreatedEvent({
Expand Down Expand Up @@ -169,6 +186,28 @@ export async function processVideoDeletedByModeratorEvent({
await deleteVideo(overlay, contentId)
}

export async function processVideoAssetsDeletedByModeratorEvent({
block,
indexInBlock,
extrinsicHash,
overlay,
event: {
asV1000: [deletedBy, contentId, assetIds, rationale],
},
}: EventHandlerContext<'Content.VideoAssetsDeletedByModerator'>): Promise<void> {
const video = await overlay.getRepository(Video).getByIdOrFail(contentId.toString())

overlay.getRepository(Event).new({
...genericEventFields(overlay, block, indexInBlock, extrinsicHash),
data: new VideoAssetsDeletedByModeratorEventData({
video: video.id,
assetIds,
deletedBy: parseContentActor(deletedBy),
rationale: rationale.toString(),
}),
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please check whether is it suitable to also remove the related StorageDataObject rows starting from assetIds. If you go through the processVideoDeletion I believe data objects are not deleted but in the rutnime they are.
So maybe the same considerations apply also there

}

export async function processVideoVisibilitySetByModeratorEvent({
overlay,
event: {
Expand Down
4 changes: 4 additions & 0 deletions src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ import {
processChannelRewardUpdatedEvent,
processChannelFundsWithdrawnEvent,
processChannelRewardClaimedAndWithdrawnEvent,
processChannelAssetsDeletedByModeratorEvent,
} from './mappings/content/channel'
import {
processVideoCreatedEvent,
processVideoUpdatedEvent,
processVideoDeletedEvent,
processVideoDeletedByModeratorEvent,
processVideoVisibilitySetByModeratorEvent,
processVideoAssetsDeletedByModeratorEvent,
} from './mappings/content/video'
import {
processOpenAuctionStartedEvent,
Expand Down Expand Up @@ -193,11 +195,13 @@ const eventHandlers: { [E in EventNames]: EventHandler<E> } = {
'Content.VideoUpdated': processVideoUpdatedEvent,
'Content.VideoDeleted': processVideoDeletedEvent,
'Content.VideoDeletedByModerator': processVideoDeletedByModeratorEvent,
'Content.VideoAssetsDeletedByModerator': processVideoAssetsDeletedByModeratorEvent,
'Content.VideoVisibilitySetByModerator': processVideoVisibilitySetByModeratorEvent,
'Content.ChannelCreated': processChannelCreatedEvent,
'Content.ChannelUpdated': processChannelUpdatedEvent,
'Content.ChannelDeleted': processChannelDeletedEvent,
'Content.ChannelDeletedByModerator': processChannelDeletedByModeratorEvent,
'Content.ChannelAssetsDeletedByModerator': processChannelAssetsDeletedByModeratorEvent,
'Content.ChannelVisibilitySetByModerator': processChannelVisibilitySetByModeratorEvent,
'Content.ChannelOwnerRemarked': processChannelOwnerRemarkedEvent,
'Content.ChannelAgentRemarked': processChannelAgentRemarkedEvent,
Expand Down
46 changes: 46 additions & 0 deletions src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,29 @@ export class ContentChannelAgentRemarkedEvent {
}
}

export class ContentChannelAssetsDeletedByModeratorEvent {
private readonly _chain: Chain
private readonly event: Event

constructor(ctx: EventContext)
constructor(ctx: ChainContext, event: Event)
constructor(ctx: EventContext, event?: Event) {
event = event || ctx.event
assert(event.name === 'Content.ChannelAssetsDeletedByModerator')
this._chain = ctx._chain
this.event = event
}

get isV1000(): boolean {
return this._chain.getEventHash('Content.ChannelAssetsDeletedByModerator') === 'f4c7c11dc109020978738fadcb5d4de0d532e2db61ee2c06f4cd2a2e97d0fc83'
}

get asV1000(): [v1000.ContentActor, bigint, bigint[], Uint8Array] {
assert(this.isV1000)
return this._chain.decodeEvent(this.event)
}
}

export class ContentChannelCreatedEvent {
private readonly _chain: Chain
private readonly event: Event
Expand Down Expand Up @@ -671,6 +694,29 @@ export class ContentOpenAuctionStartedEvent {
}
}

export class ContentVideoAssetsDeletedByModeratorEvent {
private readonly _chain: Chain
private readonly event: Event

constructor(ctx: EventContext)
constructor(ctx: ChainContext, event: Event)
constructor(ctx: EventContext, event?: Event) {
event = event || ctx.event
assert(event.name === 'Content.VideoAssetsDeletedByModerator')
this._chain = ctx._chain
this.event = event
}

get isV1000(): boolean {
return this._chain.getEventHash('Content.VideoAssetsDeletedByModerator') === '14b77a8c7d1aeffb21964d60e341eb69dff798d1e4b2806fb41efccd54b8221e'
}

get asV1000(): [v1000.ContentActor, bigint, bigint[], boolean, Uint8Array] {
assert(this.isV1000)
return this._chain.decodeEvent(this.event)
}
}

export class ContentVideoCreatedEvent {
private readonly _chain: Chain
private readonly event: Event
Expand Down
6 changes: 6 additions & 0 deletions src/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import {
ContentVideoUpdatedEvent,
ContentVideoDeletedEvent,
ContentVideoDeletedByModeratorEvent,
ContentVideoAssetsDeletedByModeratorEvent,
ContentVideoVisibilitySetByModeratorEvent,
ContentChannelCreatedEvent,
ContentChannelUpdatedEvent,
ContentChannelDeletedEvent,
ContentChannelDeletedByModeratorEvent,
ContentChannelAssetsDeletedByModeratorEvent,
ContentChannelVisibilitySetByModeratorEvent,
ContentChannelOwnerRemarkedEvent,
ContentChannelAgentRemarkedEvent,
Expand Down Expand Up @@ -78,12 +80,16 @@ export const eventConstructors = {
'Content.VideoCreated': ContentVideoCreatedEvent,
'Content.VideoUpdated': ContentVideoUpdatedEvent,
'Content.VideoDeleted': ContentVideoDeletedEvent,
// Deprecated in runtime spec version 2002 (nara), but still required for Orion processing from genesis block
'Content.VideoDeletedByModerator': ContentVideoDeletedByModeratorEvent,
'Content.VideoAssetsDeletedByModerator': ContentVideoAssetsDeletedByModeratorEvent,
'Content.VideoVisibilitySetByModerator': ContentVideoVisibilitySetByModeratorEvent,
'Content.ChannelCreated': ContentChannelCreatedEvent,
'Content.ChannelUpdated': ContentChannelUpdatedEvent,
'Content.ChannelDeleted': ContentChannelDeletedEvent,
// Deprecated in runtime spec version 2002 (nara), but still required for Orion processing from genesis block
'Content.ChannelDeletedByModerator': ContentChannelDeletedByModeratorEvent,
'Content.ChannelAssetsDeletedByModerator': ContentChannelAssetsDeletedByModeratorEvent,
'Content.ChannelVisibilitySetByModerator': ContentChannelVisibilitySetByModeratorEvent,
'Content.ChannelOwnerRemarked': ContentChannelOwnerRemarkedEvent,
'Content.ChannelAgentRemarked': ContentChannelAgentRemarkedEvent,
Expand Down
2 changes: 2 additions & 0 deletions typegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
"Content.VideoUpdated",
"Content.VideoDeleted",
"Content.VideoDeletedByModerator",
"Content.VideoAssetsDeletedByModerator",
"Content.VideoVisibilitySetByModerator",
"Content.ChannelCreated",
"Content.ChannelUpdated",
"Content.ChannelDeleted",
"Content.ChannelDeletedByModerator",
"Content.ChannelAssetsDeletedByModerator",
"Content.ChannelVisibilitySetByModerator",
"Content.ChannelOwnerRemarked",
"Content.ChannelAgentRemarked",
Expand Down