Skip to content

Commit

Permalink
add notifications queries
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysu committed Aug 11, 2023
1 parent 12afc11 commit 0e7591a
Show file tree
Hide file tree
Showing 6 changed files with 578 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/client/lens-v2.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2964,7 +2964,7 @@ input ValidatePublicationMetadataRequest {
scalar NotificationId

type FutureProofNotification {
id: String
id: NotificationId!
}

type ReactionNotification {
Expand Down Expand Up @@ -3000,7 +3000,7 @@ type ProfileActedResult {
actions: OpenActionResult!
}

type ActedNotificaion {
type ActedNotification {
id: NotificationId!
actions: [ProfileActedResult!]!
publication: AnyPublication!
Expand All @@ -3021,7 +3021,7 @@ union Notification =
| CommentNotification
| MirrorNotification
| QuoteNotification
| ActedNotificaion
| ActedNotification
| FollowNotification
| MentionNotification
| FutureProofNotification
Expand Down
8 changes: 8 additions & 0 deletions packages/client/src/feed/graphql/feed.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
PaginatedResultInfoFragment,
ProfileFragment,
CommentFragment,
CollectOpenActionResultFragment,
NftDropOpenActionFragment,
UnknownOpenActionResultFragment,
MirrorFragment,
} from '../../graphql/fragments.generated';
import { GraphQLClient } from 'graphql-request';
import { GraphQLClientRequestHeaders } from 'graphql-request/build/cjs/types';
Expand All @@ -20,6 +24,10 @@ import {
PaginatedResultInfoFragmentDoc,
ProfileFragmentDoc,
CommentFragmentDoc,
CollectOpenActionResultFragmentDoc,
NftDropOpenActionFragmentDoc,
UnknownOpenActionResultFragmentDoc,
MirrorFragmentDoc,
} from '../../graphql/fragments.generated';
export type ElectedMirrorFragment = {
mirrorId: string;
Expand Down
78 changes: 78 additions & 0 deletions packages/client/src/notifications/Notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import type { PromiseResult } from '@lens-protocol/shared-kernel';

import type { Authentication } from '../authentication';
import type { LensConfig } from '../consts/config';
import type { CredentialsExpiredError, NotAuthenticatedError } from '../consts/errors';
import { FetchGraphQLClient } from '../graphql/FetchGraphQLClient';
import type { NotificationRequest } from '../graphql/types.generated';
import {
PaginatedResult,
buildImageTransformsFromConfig,
buildPaginatedQueryResult,
requireAuthHeaders,
} from '../helpers';
import {
ActedNotificationFragment,
CommentNotificationFragment,
FollowNotificationFragment,
FutureProofNotificationFragment,
getSdk,
MentionNotificationFragment,
MirrorNotificationFragment,
QuoteNotificationFragment,
ReactionNotificationFragment,
Sdk,
} from './graphql/notifications.generated';

export type NotificationFragment =
| ActedNotificationFragment
| CommentNotificationFragment
| FollowNotificationFragment
| FutureProofNotificationFragment
| MentionNotificationFragment
| MirrorNotificationFragment
| QuoteNotificationFragment
| ReactionNotificationFragment;

/**
* Notifications on activity for a profile including collects, comment, new followers, and mirrors.
*
* @group LensClient Modules
*/
export class Notifications {
private readonly authentication: Authentication | undefined;
private readonly sdk: Sdk;

constructor(
private readonly config: LensConfig,
authentication: Authentication,
) {
const client = new FetchGraphQLClient(config.environment.gqlEndpoint);

this.sdk = getSdk(client);
this.authentication = authentication;
}

async fetch(
request: NotificationRequest,
observerId?: string,
): PromiseResult<
PaginatedResult<NotificationFragment>,
CredentialsExpiredError | NotAuthenticatedError
> {
return requireAuthHeaders(this.authentication, async (headers) => {
return buildPaginatedQueryResult(async (currRequest) => {
const result = await this.sdk.Notifications(
{
request: currRequest,
observerId,
...buildImageTransformsFromConfig(this.config.mediaTransforms),
},
headers,
);

return result.data.result;
}, request);
});
}
}
Loading

0 comments on commit 0e7591a

Please sign in to comment.