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

Notifications/qa fixes #250

Merged
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/mappings/content/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
94 changes: 49 additions & 45 deletions src/server-extension/resolvers/ChannelsResolver/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -394,9 +394,9 @@ export class ChannelsResolver {

@Mutation(() => VerifyChannelResult)
@UseMiddleware(OperatorOnly())
async verifyChannel(@Args() { channelId }: VerifyChannelArgs): Promise<VerifyChannelResult> {
async verifyChannel(@Args() { channelIds }: VerifyChannelArgs): Promise<VerifyChannelResult[]> {
const em = await this.em()
return await verifyChannelService(em, channelId)
return await verifyChannelService(em, channelIds)
}

@Mutation(() => ExcludeChannelResult)
Expand Down Expand Up @@ -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)
})
}
4 changes: 2 additions & 2 deletions src/server-extension/resolvers/ChannelsResolver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ export class SuspendChannelArgs {

@ArgsType()
export class VerifyChannelArgs {
@Field(() => String, { nullable: false })
channelId!: string
@Field(() => [String], { nullable: false })
channelIds!: string[]
}

@ObjectType()
Expand Down
4 changes: 2 additions & 2 deletions src/tests/integration/notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}

const createOverlay = async () => {
return await EntityManagerOverlay.create(new Store(() => globalEm), (_em: EntityManager) =>

Check warning on line 61 in src/tests/integration/notifications.test.ts

View workflow job for this annotation

GitHub Actions / Local build, linting and formatting (ubuntu-latest, 16.x)

'_em' is defined but never used
Promise.resolve()
)
}
Expand All @@ -77,7 +77,7 @@
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,
Expand Down Expand Up @@ -108,7 +108,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion src/utils/notification/notificationsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
Loading