diff --git a/packages/client/src/actions/posts.ts b/packages/client/src/actions/posts.ts index b1baa4d7f..0537da52e 100644 --- a/packages/client/src/actions/posts.ts +++ b/packages/client/src/actions/posts.ts @@ -13,12 +13,25 @@ import type { import { PostActionsQuery, PostBookmarksQuery, + PostEditsQuery, PostQuery, + PostReactionStatusQuery, PostReactionsQuery, PostReferencesQuery, + PostTagsQuery, + WhoActedOnPostQuery, + WhoReferencedPostQuery, } from '@lens-protocol/graphql'; import type { ResultAsync } from '@lens-protocol/types'; +import type { PostTagsRequest } from '@lens-protocol/graphql'; +import type { PostReactionStatusRequest } from '@lens-protocol/graphql'; +import type { PostReactionStatus } from '@lens-protocol/graphql'; +import type { WhoReferencedPostRequest } from '@lens-protocol/graphql'; +import type { Account } from '@lens-protocol/graphql'; +import type { WhoActedOnPostQueryRequest } from '@lens-protocol/graphql'; +import type { PostEditsRequest } from '@lens-protocol/graphql'; +import type { PostEdit } from '@lens-protocol/graphql'; import type { AnyClient, SessionClient } from '../clients'; import type { UnauthenticatedError, UnexpectedError } from '../errors'; @@ -120,3 +133,107 @@ export function fetchPostReferences( ): ResultAsync, UnexpectedError | UnauthenticatedError> { return client.query(PostReferencesQuery, { request }); } + +/** + * Fetch post tags. + * + * ```ts + * const result = await fetchPostTags(anyClient, { + * forFeeds: [evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')], + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The list of post tags. + */ +export function fetchPostTags( + client: AnyClient, + request: PostTagsRequest, +): ResultAsync, UnexpectedError> { + return client.query(PostTagsQuery, { request }); +} + +/** + * Fetch post reaction status. + * + * ```ts + * const result = await fetchPostReactionStatus(anyClient, { + * pairs: [{ + * account: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')], + * post: postId('42'), + * }], + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The list of post reaction status. + */ +export function fetchPostReactionStatus( + client: AnyClient, + request: PostReactionStatusRequest, +): ResultAsync { + return client.query(PostReactionStatusQuery, { request }); +} + +/** + * Fetch who referenced post. + * + * ```ts + * const result = await fetchWhoReferencedPost(anyClient, { + * referenceTypes: [PostReferenceType.CommentOn] + * post: postId('42'), + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The list of accounts who referenced the post. + */ +export function fetchWhoReferencedPost( + client: AnyClient, + request: WhoReferencedPostRequest, +): ResultAsync, UnexpectedError> { + return client.query(WhoReferencedPostQuery, { request }); +} + +/** + * Fetch who acted on post. + * + * ```ts + * const result = await fetchWhoActedOnPost(anyClient, { + * post: postId('42'), + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The list of accounts who acted on the post. + */ +export function fetchWhoActedOnPost( + client: AnyClient, + request: WhoActedOnPostQueryRequest, +): ResultAsync, UnexpectedError> { + return client.query(WhoActedOnPostQuery, { request }); +} + +/** + * Fetch post edits. + * + * ```ts + * const result = await fetchPostEdits(anyClient, { + * post: postId('42'), + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The list of edits for the post. + */ +export function fetchPostEdits( + client: AnyClient, + request: PostEditsRequest, +): ResultAsync, UnexpectedError> { + return client.query(PostEditsQuery, { request }); +} diff --git a/packages/graphql/src/enums.ts b/packages/graphql/src/enums.ts index 4d247954c..c351c4097 100644 --- a/packages/graphql/src/enums.ts +++ b/packages/graphql/src/enums.ts @@ -45,7 +45,25 @@ export enum PostReactionType { * Enum for the different content warnings. */ export enum ContentWarning { - nsfw = 'NSFW', - sensitive = 'SENSITIVE', - spoiler = 'SPOILER', + Nsfw = 'NSFW', + Sensitive = 'SENSITIVE', + Spoiler = 'SPOILER', +} + +/** + * Enum for the different types of references a post can have. + */ +export enum PostReferenceType { + CommentOn = 'COMMENT_ON', + RepostOf = 'REPOST_OF', + QuoteOf = 'QUOTE_OF', +} + +/** + * Enum for the different order by options for who referenced on a post. + */ +export enum WhoReferencedPostOrderBy { + MostRecent = 'MOST_RECENT', + Oldest = 'OLDEST', + AccountScore = 'ACCOUNT_SCORE', } diff --git a/packages/graphql/src/graphql.ts b/packages/graphql/src/graphql.ts index 89cf6e57b..e807b838d 100644 --- a/packages/graphql/src/graphql.ts +++ b/packages/graphql/src/graphql.ts @@ -34,6 +34,8 @@ import type { PageSize, PostActionType, PostReactionType, + PostReferenceType, + WhoReferencedPostOrderBy, } from './enums'; import type { introspection } from './graphql-env'; @@ -60,17 +62,20 @@ export const graphql = initGraphQLTada<{ LegacyRefreshToken: CompactJwt; PostActionType: PostActionType; PostReactionType: PostReactionType; + PostReferenceType: PostReferenceType; PageSize: PageSize; PostId: PostId; RefreshToken: RefreshToken; Signature: Signature; String: string; + Tag: string; TxHash: TxHash; URI: URI; URL: URL; UsernameValue: UsernameValue; UUID: UUID; Void: Void; + WhoReferencedPostOrderBy: WhoReferencedPostOrderBy; }; }>(); diff --git a/packages/graphql/src/post.ts b/packages/graphql/src/post.ts index fa62fd82f..0c766f3c1 100644 --- a/packages/graphql/src/post.ts +++ b/packages/graphql/src/post.ts @@ -1,9 +1,11 @@ import type { FragmentOf } from 'gql.tada'; import { + AccountFragment, AccountPostReactionFragment, ActionInfoFragment, AnyPostFragment, PaginatedResultInfoFragment, + PostMetadataFragment, SelfFundedTransactionRequest, SponsoredTransactionRequest, TransactionWillFail, @@ -261,3 +263,97 @@ export const ReportPostMutation = graphql( }`, ); export type ReportPostRequest = RequestOf; + +export const PostTagsQuery = graphql( + `query PostTags($request: PostTagsRequest!) { + value: postTags(request: $request) { + __typename + items + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [PaginatedResultInfoFragment], +); +export type PostTagsRequest = RequestOf; + +export const PostReactionStatusFragment = graphql( + `fragment PostReactionStatus on PostReactionStatus { + __typename + postId + account + result + }`, +); +export type PostReactionStatus = FragmentOf; + +export const PostReactionStatusQuery = graphql( + `query PostReactionStatus($request: PostReactionStatusRequest!) { + value: postReactionStatus(request: $request) { + ...PostReactionStatus + } + }`, + [PostReactionStatusFragment], +); +export type PostReactionStatusRequest = RequestOf; + +export const WhoReferencedPostQuery = graphql( + `query WhoReferencedPost($request: WhoReferencedPostRequest!) { + value: whoReferencedPost(request: $request) { + __typename + items { + ...Account + } + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [PaginatedResultInfoFragment, AccountFragment], +); +export type WhoReferencedPostRequest = RequestOf; + +export const WhoActedOnPostQuery = graphql( + `query WhoReferencedPost($request: WhoActedOnPostRequest!) { + value: whoActedOnPost(request: $request) { + __typename + items { + ...Account + } + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [PaginatedResultInfoFragment, AccountFragment], +); +export type WhoActedOnPostQueryRequest = RequestOf; + +export const PostEditFragment = graphql( + `fragment PostEdit on PostEdit { + __typename + metadata{ + ...PostMetadata + } + timestamp + }`, + [PostMetadataFragment], +); +export type PostEdit = FragmentOf; + +export const PostEditsQuery = graphql( + `query PostEdits($request: PostEditsRequest!) { + value: postEdits(request: $request) { + __typename + items { + ...PostEdit + } + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [PostEditFragment, PaginatedResultInfoFragment], +); +export type PostEditsRequest = RequestOf;