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

👥 Add member ids to NotificationType #219

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
32 changes: 31 additions & 1 deletion schema/notifications.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ type VideoExcluded @variant {
}

type NewChannelFollower @variant {
"follower member handle for link"
"follower member id for the avatar and the link"
followerId: String!

"follower member handle for the text"
followerHandle: String!
}

Expand All @@ -149,6 +152,9 @@ type CommentPostedToVideo @variant {
"video Id used for link"
videoId: String!

"commenter id for the avatar"
memberId: String!

"commenter handle for text"
memberHandle: String!

Expand All @@ -163,6 +169,9 @@ type VideoLiked @variant {
"video title for notification text"
videoTitle: String!

"id for the member that dropped the like"
memberId: String!

"handle for the member that dropped the like"
memberHandle: String!
}
Expand All @@ -174,6 +183,9 @@ type VideoDisliked @variant {
"video title for notification text"
videoTitle: String!

"id for the member that dropped the dislike"
memberId: String!

"handle for the member that dropped the dislike"
memberHandle: String!
}
Expand All @@ -185,6 +197,9 @@ type NftPurchased @variant {
"video title for notification text"
videoTitle: String!

"buyer id for notification the avatar"
buyerId: String!

"buyer handle for notification text"
buyerHandle: String!

Expand All @@ -199,6 +214,9 @@ type CreatorReceivesAuctionBid @variant {
"video title used for notification text"
videoTitle: String!

"bidder id for notification the avatar"
bidderId: String!

"bidder handle for notification text"
bidderHandle: String!

Expand All @@ -218,6 +236,9 @@ type NftOffered @variant {
}

type DirectChannelPaymentByMember @variant {
"payer id"
payerId: String!

"payer handle"
payerHandle: String!

Expand Down Expand Up @@ -259,6 +280,9 @@ type CommentReply @variant {
"video title for notification text"
videoTitle: String!

"member who replied"
memberId: String!

"member who replied"
memberHandle: String!
}
Expand All @@ -273,6 +297,9 @@ type ReactionToComment @variant {
"video title for notification text"
videoTitle: String!

"member who replied"
memberId: String!

"member who replied"
memberHandle: String!
}
Expand Down Expand Up @@ -326,6 +353,9 @@ type HigherBidPlaced @variant {
"video Id used for link"
videoId: String!

"new bidder id"
newBidderId: String!

"new bidder handle "
newBidderHandle: String!
}
Expand Down
9 changes: 8 additions & 1 deletion src/mappings/content/commentsAndReactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,12 @@ async function processVideoReaction(
if (channelOwnerMemberId) {
const memberHandle = await memberHandleById(overlay, memberId)
const channelOwnerAccount = await getAccountForMember(overlay, channelOwnerMemberId)
const reactionData = { videoId: video.id, videoTitle: parseVideoTitle(video), memberHandle }
const reactionData = {
videoId: video.id,
videoTitle: parseVideoTitle(video),
memberId,
memberHandle,
}
const reaction =
reactionType === VideoReactionOptions.LIKE
? new VideoLiked(reactionData)
Expand Down Expand Up @@ -395,6 +400,7 @@ export async function processReactCommentMessage(
commentId: comment.id,
videoId: video.id,
videoTitle: parseVideoTitle(video),
memberId,
memberHandle: await memberHandleById(overlay, memberId),
}
await addNotification(
Expand Down Expand Up @@ -526,6 +532,7 @@ export async function processCreateCommentMessage(
const notificationData = {
videoId: video.id,
videoTitle: parseVideoTitle(video),
memberId: authorId,
memberHandle: authorHandle,
comentId: comment.id,
}
Expand Down
2 changes: 1 addition & 1 deletion src/mappings/content/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ export async function processChannelPaymentFromMember(
overlay,
ownerAccount,
new ChannelRecipient({ channel: channel.id }),
new DirectChannelPaymentByMember({ amount, payerHandle: member.handle }),
new DirectChannelPaymentByMember({ amount, payerId: member.id, payerHandle: member.handle }),
event
)

Expand Down
2 changes: 2 additions & 0 deletions src/mappings/content/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
NftOfferedEventData,
Account,
MemberRecipient,
AuctionTypeOpen,

Check warning on line 53 in src/mappings/content/nft.ts

View workflow job for this annotation

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

'AuctionTypeOpen' is defined but never used. Allowed unused vars must match /^_/u
} from '../../model'
import { addNftActivity, addNftHistoryEntry, genericEventFields } from '../utils'
import { SubstrateBlock, assertNotNull } from '@subsquid/substrate-processor'
Expand Down Expand Up @@ -602,6 +602,7 @@
const notificationData = new NftPurchased({
videoId: video.id,
videoTitle: parseVideoTitle(video),
buyerId: memberId.toString(),
buyerHandle,
price,
})
Expand Down Expand Up @@ -757,6 +758,7 @@
await addNewBidNotification(overlay, nft.owner, previousTopBid, event, {
videoId: videoId.toString(),
videoTitle,
newTopBidderId: memberId.toString(),
newTopBidderHandle,
bidAmount,
})
Expand Down
5 changes: 4 additions & 1 deletion src/mappings/content/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ export async function getAccountsForBidders(
export type NewBidNotificationMetadata = {
videoId: string
videoTitle: string
newTopBidderId: string
newTopBidderHandle: string
bidAmount: bigint
}
Expand All @@ -709,13 +710,14 @@ export async function addNewBidNotification(
owner: NftOwner,
previousTopBid: Flat<Bid> | undefined | null,
event: Event,
{ videoId, videoTitle, newTopBidderHandle, bidAmount }: NewBidNotificationMetadata
{ videoId, videoTitle, newTopBidderId, newTopBidderHandle, bidAmount }: NewBidNotificationMetadata
) {
if (previousTopBid?.bidderId) {
const outbiddedMemberId = previousTopBid.bidderId
const outbiddedMemberAccount = await getAccountForMember(overlay, outbiddedMemberId)

const notificationData = {
newBidderId: newTopBidderId,
newBidderHandle: newTopBidderHandle,
videoId,
videoTitle,
Expand All @@ -732,6 +734,7 @@ export async function addNewBidNotification(
if (owner.isTypeOf === 'NftOwnerChannel') {
const notificationData = new CreatorReceivesAuctionBid({
amount: bidAmount,
bidderId: newTopBidderId,
bidderHandle: newTopBidderHandle,
videoId,
videoTitle,
Expand Down
5 changes: 4 additions & 1 deletion src/server-extension/resolvers/ChannelsResolver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ export class ChannelsResolver {
em,
ownerAccount,
new ChannelRecipient({ channel: channel.id }),
new NewChannelFollower({ followerHandle: assertNotNull(followerMembership.handle) })
new NewChannelFollower({
followerId: assertNotNull(followerMembership.id),
followerHandle: assertNotNull(followerMembership.handle),
})
)
}

Expand Down
9 changes: 3 additions & 6 deletions src/utils/notification/notificationAvatars.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { EntityManager, FindOptionsWhere } from 'typeorm'
import { EntityManager } from 'typeorm'
import { Channel, MemberMetadata } from '../../model'

const PLACEHOLDER = 'https://example.com/avatar.png'

export const getNotificationAvatar = async (
em: EntityManager,
type: 'channelId' | 'membershipId' | 'membershipHandle',
type: 'channelId' | 'membershipId',
param: string
): Promise<string> => {
if (type === 'channelId') {
Expand All @@ -19,10 +19,7 @@ export const getNotificationAvatar = async (
return avatar.resolvedUrls[0]
}

const where: FindOptionsWhere<MemberMetadata> =
type === 'membershipId' ? { id: param } : { member: { handle: param } }

const member = await em.getRepository(MemberMetadata).findOneBy(where)
const member = await em.getRepository(MemberMetadata).findOneBy({ id: param })
const avatar = member?.avatar

// AvatarObject is not yet supported
Expand Down
2 changes: 1 addition & 1 deletion src/utils/notification/notificationLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const getNotificationLink = async (
return await getLink(em, `channel/${params[0]}`)

case 'member-page':
return await getLink(em, `member/${params[0]}`)
return await getLink(em, `member/id/${params[0]}`)

case 'category-page':
return await getLink(em, `category/${params[0]}`)
Expand Down
44 changes: 22 additions & 22 deletions src/utils/notification/notificationsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ export const getNotificationData = async (

// Engagement
case 'CommentReply': {
const { videoId, videoTitle, commentId, memberHandle } = notificationType
const { videoId, videoTitle, commentId, memberId, memberHandle } = notificationType
return {
icon: await getNotificationIcon(em, 'follow'),
link: await getNotificationLink(em, 'video-page', [videoId, commentId]),
avatar: await getNotificationAvatar(em, 'membershipHandle', memberHandle),
avatar: await getNotificationAvatar(em, 'membershipId', memberId),
text: `${memberHandle} replied to your comment under the video: “${videoTitle}”`,
}
}
case 'ReactionToComment': {
const { videoId, videoTitle, commentId, memberHandle } = notificationType
const { videoId, videoTitle, commentId, memberId, memberHandle } = notificationType
return {
icon: await getNotificationIcon(em, 'reaction'),
link: await getNotificationLink(em, 'video-page', [videoId, commentId]),
avatar: await getNotificationAvatar(em, 'membershipHandle', memberHandle),
avatar: await getNotificationAvatar(em, 'membershipId', memberId),
text: `${memberHandle} reacted to your comment on the video: “${videoTitle}”`,
}
}
Expand Down Expand Up @@ -85,11 +85,11 @@ export const getNotificationData = async (

// NFT
case 'HigherBidPlaced': {
const { videoId, videoTitle, newBidderHandle } = notificationType
const { videoId, videoTitle, newBidderId, newBidderHandle } = notificationType
return {
icon: await getNotificationIcon(em, 'nft-alt'),
link: await getNotificationLink(em, 'nft-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipHandle', newBidderHandle),
avatar: await getNotificationAvatar(em, 'membershipId', newBidderId),
text: `${newBidderHandle} placed a higher bid in the auction for NFT: “${videoTitle}”`,
}
}
Expand Down Expand Up @@ -149,38 +149,38 @@ export const getNotificationData = async (

// Engagement
case 'NewChannelFollower': {
const { followerHandle } = notificationType
const { followerId, followerHandle } = notificationType
return {
icon: await getNotificationIcon(em, 'follow'),
link: await getNotificationLink(em, 'member-page', [followerHandle]),
avatar: await getNotificationAvatar(em, 'membershipHandle', followerHandle),
link: await getNotificationLink(em, 'member-page', [followerId]),
avatar: await getNotificationAvatar(em, 'membershipId', followerId),
text: `${followerHandle} followed your channel`,
}
}
case 'CommentPostedToVideo': {
const { videoId, videoTitle, memberHandle } = notificationType
const { videoId, videoTitle, memberId, memberHandle } = notificationType
return {
icon: await getNotificationIcon(em, 'follow'),
link: await getNotificationLink(em, 'nft-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipHandle', memberHandle),
avatar: await getNotificationAvatar(em, 'membershipId', memberId),
text: `${memberHandle} left a comment on your video: “${videoTitle}”`,
}
}
case 'VideoLiked': {
const { videoId, videoTitle, memberHandle } = notificationType
const { videoId, videoTitle, memberId, memberHandle } = notificationType
return {
icon: await getNotificationIcon(em, 'like'),
link: await getNotificationLink(em, 'video-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipHandle', memberHandle),
avatar: await getNotificationAvatar(em, 'membershipId', memberId),
text: `${memberHandle} liked your video: “${videoTitle}”`,
}
}
case 'VideoDisliked': {
const { videoId, videoTitle, memberHandle } = notificationType
const { videoId, videoTitle, memberId, memberHandle } = notificationType
return {
icon: await getNotificationIcon(em, 'dislike'),
link: await getNotificationLink(em, 'video-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipHandle', memberHandle),
avatar: await getNotificationAvatar(em, 'membershipId', memberId),
text: `${memberHandle} disliked your video: “${videoTitle}”`,
}
}
Expand All @@ -205,11 +205,11 @@ export const getNotificationData = async (

// NFTs Auctions
case 'NftPurchased': {
const { videoId, videoTitle, buyerHandle, price } = notificationType
const { videoId, videoTitle, buyerId, buyerHandle, price } = notificationType
return {
icon: await getNotificationIcon(em, 'nft'),
link: await getNotificationLink(em, 'nft-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipHandle', buyerHandle),
avatar: await getNotificationAvatar(em, 'membershipId', buyerId),
text: `${buyerHandle} purchased for ${formatJOY(price)} your NFT: “${videoTitle}”`,
}
}
Expand All @@ -223,22 +223,22 @@ export const getNotificationData = async (
}
}
case 'CreatorReceivesAuctionBid': {
const { videoId, videoTitle, amount, bidderHandle } = notificationType
const { videoId, videoTitle, amount, bidderId, bidderHandle } = notificationType
return {
icon: await getNotificationIcon(em, 'nft'),
link: await getNotificationLink(em, 'nft-page', [videoId]),
avatar: await getNotificationAvatar(em, 'membershipHandle', bidderHandle),
avatar: await getNotificationAvatar(em, 'membershipId', bidderId),
text: `${bidderHandle} placed a bid of ${formatJOY(amount)} for your NFT: “${videoTitle}”`,
}
}

// Payouts
case 'DirectChannelPaymentByMember': {
const { amount, payerHandle } = notificationType
const { amount, payerId, payerHandle } = notificationType
return {
icon: await getNotificationIcon(em, 'payout'),
link: await getNotificationLink(em, 'member-page', [payerHandle]),
avatar: await getNotificationAvatar(em, 'membershipHandle', payerHandle),
link: await getNotificationLink(em, 'member-page', [payerId]),
avatar: await getNotificationAvatar(em, 'membershipId', payerId),
text: `${payerHandle} transferred ${formatJOY(amount)} to your channel`,
}
}
Expand Down
Loading