From 21fc5b016d4798b4732221042566e80f79bb6957 Mon Sep 17 00:00:00 2001 From: Ignazio Bovo Date: Wed, 22 Nov 2023 09:21:16 +0100 Subject: [PATCH 1/3] fix: :bug: unitialized access video posted + misc --- src/mappings/content/utils.ts | 1 + src/mappings/content/video.ts | 1 + src/utils/notification/notificationsData.ts | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mappings/content/utils.ts b/src/mappings/content/utils.ts index 2303f7e31..5e27782a0 100644 --- a/src/mappings/content/utils.ts +++ b/src/mappings/content/utils.ts @@ -75,6 +75,7 @@ import { createType } from '@joystream/types' import { EntityManager } from 'typeorm' import BN from 'bn.js' import { addNotification } from '../../utils/notification' +import fs from 'fs' // eslint-disable-next-line @typescript-eslint/no-explicit-any export type AsDecoded = MetaClass extends { create: (props?: infer I) => any } diff --git a/src/mappings/content/video.ts b/src/mappings/content/video.ts index f8104dcb4..ab704811d 100644 --- a/src/mappings/content/video.ts +++ b/src/mappings/content/video.ts @@ -129,6 +129,7 @@ export async function processVideoCreatedEvent({ channelTitle: parseChannelTitle(channel), videoTitle: parseVideoTitle(video), videoId: video.id, + channelId: channel.id, }) await notifyChannelFollowers(overlay, channel.id, notificationData, eventEntity) diff --git a/src/utils/notification/notificationsData.ts b/src/utils/notification/notificationsData.ts index 6d9f005b7..6e746b0ce 100644 --- a/src/utils/notification/notificationsData.ts +++ b/src/utils/notification/notificationsData.ts @@ -90,7 +90,7 @@ export const getNotificationData = async ( icon: await getNotificationIcon(em, 'nft-alt'), link: await getNotificationLink(em, 'nft-page', [videoId]), avatar: await getNotificationAvatar(em, 'membershipId', newBidderId), - text: `${newBidderHandle} placed a higher bid in the auction for NFT: “${videoTitle}”`, + text: `${newBidderHandle} placed a higher bid in the timed auction for NFT: “${videoTitle}”`, } } case 'AuctionWon': { From 2a6df5d67032d0fa8651b3ab9ad80cf0cdb4a794 Mon Sep 17 00:00:00 2001 From: Ignazio Bovo Date: Fri, 24 Nov 2023 15:41:08 +0100 Subject: [PATCH 2/3] feat: :zap: batch channel verification --- .../resolvers/ChannelsResolver/index.ts | 94 ++++++++++--------- .../resolvers/ChannelsResolver/types.ts | 4 +- src/tests/integration/notifications.test.ts | 4 +- 3 files changed, 53 insertions(+), 49 deletions(-) diff --git a/src/server-extension/resolvers/ChannelsResolver/index.ts b/src/server-extension/resolvers/ChannelsResolver/index.ts index ca4adac52..f4fd77d2b 100644 --- a/src/server-extension/resolvers/ChannelsResolver/index.ts +++ b/src/server-extension/resolvers/ChannelsResolver/index.ts @@ -1,6 +1,6 @@ import 'reflect-metadata' import { Args, Query, Mutation, Resolver, Info, Ctx, UseMiddleware } from 'type-graphql' -import { EntityManager, IsNull } from 'typeorm' +import { EntityManager, In, IsNull } from 'typeorm' import { ChannelNftCollector, ChannelNftCollectorsArgs, @@ -394,9 +394,9 @@ export class ChannelsResolver { @Mutation(() => VerifyChannelResult) @UseMiddleware(OperatorOnly()) - async verifyChannel(@Args() { channelId }: VerifyChannelArgs): Promise { + async verifyChannel(@Args() { channelIds }: VerifyChannelArgs): Promise { const em = await this.em() - return await verifyChannelService(em, channelId) + return await verifyChannelService(em, channelIds) } @Mutation(() => ExcludeChannelResult) @@ -468,51 +468,55 @@ export const excludeChannelService = async ( }) } -export const verifyChannelService = async (em: EntityManager, channelId: string) => { +export const verifyChannelService = async (em: EntityManager, channelIds: string[]) => { return withHiddenEntities(em, async () => { - const channel = await em.findOne(Channel, { - where: { id: channelId }, - }) - - if (!channel) { - throw new Error(`Channel by id ${channelId} not found!`) - } - // If channel already verified - return its data - if (channel.yppStatus.isTypeOf === 'YppVerified') { - const existingVerification = await em.getRepository(ChannelVerification).findOneOrFail({ - where: { channelId: channel.id }, - }) - return { - id: existingVerification.id, - channelId: channel.id, - createdAt: existingVerification.timestamp, - } - } - // othewise create new verification - const newVerification = new ChannelVerification({ - id: uniqueId(), - channelId: channel.id, - timestamp: new Date(), + const channels = await em.getRepository(Channel).find({ + where: { id: In(channelIds) }, }) - channel.yppStatus = new YppVerified({ verification: newVerification.id }) - await em.save([newVerification, channel]) - // in case account exist deposit notification - const channelOwnerMemberId = channel.ownerMemberId - if (channelOwnerMemberId) { - const account = await em.findOne(Account, { where: { membershipId: channelOwnerMemberId } }) - await addNotification( - em, - account, - new ChannelRecipient({ channel: channel.id }), - new ChannelVerified({}) - ) - } + const results = channels + .filter((channel) => channel) + .map(async (channel) => { + // If channel already verified - return its data + if (channel.yppStatus.isTypeOf === 'YppVerified') { + const existingVerification = await em.getRepository(ChannelVerification).findOneOrFail({ + where: { channelId: channel.id }, + }) + return { + id: existingVerification.id, + channelId: channel.id, + createdAt: existingVerification.timestamp, + } + } + // othewise create new verification regardless whether the channel was previously verified + const newVerification = new ChannelVerification({ + id: uniqueId(), + channelId: channel.id, + timestamp: new Date(), + }) + channel.yppStatus = new YppVerified({ verification: newVerification.id }) + await em.save([newVerification, channel]) + + // in case account exist deposit notification + const channelOwnerMemberId = channel.ownerMemberId + if (channelOwnerMemberId) { + const account = await em.findOne(Account, { + where: { membershipId: channelOwnerMemberId }, + }) + await addNotification( + em, + account, + new ChannelRecipient({ channel: channel.id }), + new ChannelVerified({}) + ) + } - return { - id: newVerification.id, - channelId: channel.id, - createdAt: newVerification.timestamp, - } + return { + id: newVerification.id, + channelId: channel.id, + createdAt: newVerification.timestamp, + } + }) + return await Promise.all(results) }) } diff --git a/src/server-extension/resolvers/ChannelsResolver/types.ts b/src/server-extension/resolvers/ChannelsResolver/types.ts index 35964bef8..82594cad2 100644 --- a/src/server-extension/resolvers/ChannelsResolver/types.ts +++ b/src/server-extension/resolvers/ChannelsResolver/types.ts @@ -186,8 +186,8 @@ export class SuspendChannelArgs { @ArgsType() export class VerifyChannelArgs { - @Field(() => String, { nullable: false }) - channelId!: string + @Field(() => [String], { nullable: false }) + channelIds!: string[] } @ObjectType() diff --git a/src/tests/integration/notifications.test.ts b/src/tests/integration/notifications.test.ts index 83e8f1cac..62d26861a 100644 --- a/src/tests/integration/notifications.test.ts +++ b/src/tests/integration/notifications.test.ts @@ -77,7 +77,7 @@ describe('notifications tests', () => { const channelId = '1' const nextNotificationIdPre = await getNextNotificationId(em, false) notificationId = OFFCHAIN_NOTIFICATION_ID_TAG + '-' + nextNotificationIdPre - await verifyChannelService(em, channelId) + await verifyChannelService(em, [channelId]) notification = await em.getRepository(Notification).findOneBy({ id: notificationId, @@ -108,7 +108,7 @@ describe('notifications tests', () => { it('verify channel should mark channel as excluded with entity inserted', async () => { const channelId = '2' - await verifyChannelService(em, channelId) + await verifyChannelService(em, [channelId]) const channel = await em.getRepository(Channel).findOneByOrFail({ id: channelId }) const channelVerification = await em From 44a38a113a472f60cb03a57862529728b78597f4 Mon Sep 17 00:00:00 2001 From: Ignazio Bovo Date: Mon, 27 Nov 2023 15:52:35 +0100 Subject: [PATCH 3/3] fix: :zap: remove non necessary import --- src/mappings/content/utils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mappings/content/utils.ts b/src/mappings/content/utils.ts index 5e27782a0..2303f7e31 100644 --- a/src/mappings/content/utils.ts +++ b/src/mappings/content/utils.ts @@ -75,7 +75,6 @@ import { createType } from '@joystream/types' import { EntityManager } from 'typeorm' import BN from 'bn.js' import { addNotification } from '../../utils/notification' -import fs from 'fs' // eslint-disable-next-line @typescript-eslint/no-explicit-any export type AsDecoded = MetaClass extends { create: (props?: infer I) => any }