Skip to content

Commit

Permalink
feat: lens v2 new mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
marian2js committed Nov 8, 2023
1 parent b830cff commit 30ca4b1
Showing 1 changed file with 83 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,6 @@ export class NewMentionTrigger extends OperationTrigger {
ownedBy: {
type: 'string',
},
stats: {
type: 'object',
properties: {
totalFollowers: {
type: 'number',
},
totalFollowing: {
type: 'number',
},
totalPosts: {
type: 'number',
},
totalComments: {
type: 'number',
},
totalMirrors: {
type: 'number',
},
totalPublications: {
type: 'number',
},
totalCollects: {
type: 'number',
},
},
},
},
},
canComment: {
Expand Down Expand Up @@ -127,61 +101,87 @@ export class NewMentionTrigger extends OperationTrigger {
}
const { profileId } = credentials

// const postOrCommentQuery = `
// id
// stats {
// totalAmountOfMirrors
// totalAmountOfCollects
// totalAmountOfComments
// }
// metadata {
// name
// content
// }
// profile {
// id
// name
// bio
// isDefault
// handle
// ownedBy
// stats {
// totalFollowers
// totalFollowing
// totalPosts
// totalComments
// totalMirrors
// totalPublications
// totalCollects
// }
// }
// canComment(profileId: "${profileId}") {
// result
// }
// `
const postOrCommentQuery = `
id
stats {
totalAmountOfMirrors
totalAmountOfCollects
totalAmountOfComments
id
stats {
mirrors
comments
}
metadata {
... on TextOnlyMetadataV3 {
id
content
}
metadata {
name
... on ArticleMetadataV3 {
id
content
}
profile {
... on ImageMetadataV3 {
id
name
bio
isDefault
handle
ownedBy
stats {
totalFollowers
totalFollowing
totalPosts
totalComments
totalMirrors
totalPublications
totalCollects
}
content
}
... on LinkMetadataV3 {
id
content
}
}
by {
id
handle {
fullHandle
}
canComment(profileId: "${profileId}") {
result
ownedBy {
address
}
`
metadata {
displayName
}
}`

const query = `
query Notifications {
notifications(request: { profileId: "${profileId}", notificationTypes: [MENTION_POST, MENTION_COMMENT], limit: ${
fetchAll ? 50 : 10
} }) {
notifications(request: { where: { notificationTypes: [MENTIONED, MENTIONED] } }) {
items {
... on NewMentionNotification {
notificationId
mentionPublication {
... on MentionNotification {
id
publication {
... on Post {
${postOrCommentQuery}
}
... on Comment {
${postOrCommentQuery}
mainPost {
... on Post {
id
}
... on Mirror {
id
}
}
}
}
}
Expand All @@ -195,15 +195,26 @@ export class NewMentionTrigger extends OperationTrigger {
if (!res?.data?.notifications?.items) {
throw new Error(res.errors?.[0]?.message ?? 'Bad response from lens')
}

return {
outputs: {
items: res.data.notifications.items.map((item) => ({
...item,
mentionPublication: {
...item.mentionPublication,
canComment: item.mentionPublication.canComment.result,
},
})),
items: res.data.notifications.items.map((item) => {
item.profile = item.publication.by
item.profile.name = item.publication.by.metadata?.displayName
item.profile.handle = item.publication.by.handle?.fullHandle
item.profile.ownedBy = item.publication.by.ownedBy?.address
delete item.publication.by
delete item.profile.metadata

item.mentionPublication = item.publication
if (item.stats) {
item.stats.totalAmountOfMirrors = item.stats.mirrors
item.stats.totalAmountOfComments = item.stats.comments
// item.stats.totalAmountOfCollects = item.stats.collects // TODO
}
delete item.publication
return item
}),
},
refreshedCredentials,
}
Expand Down

0 comments on commit 30ca4b1

Please sign in to comment.