feat(core): add notification service (#10855)

This commit is contained in:
EYHN
2025-03-14 09:32:10 +00:00
parent 4a1a557a9e
commit a2eb3fe1b2
6 changed files with 79 additions and 0 deletions

View File

@@ -1,18 +1,22 @@
export { NotificationCountService } from './services/count';
export { NotificationListService } from './services/list';
export { NotificationService } from './services/notification';
export type { Notification, NotificationBody } from './stores/notification';
export { NotificationType } from './stores/notification';
import type { Framework } from '@toeverything/infra';
import { GraphQLService, ServerScope, ServerService } from '../cloud';
import { GlobalSessionState } from '../storage';
import { NotificationCountService } from './services/count';
import { NotificationListService } from './services/list';
import { NotificationService } from './services/notification';
import { NotificationStore } from './stores/notification';
export function configureNotificationModule(framework: Framework) {
framework
.scope(ServerScope)
.service(NotificationService, [NotificationStore])
.service(NotificationCountService, [NotificationStore])
.service(NotificationListService, [
NotificationStore,

View File

@@ -0,0 +1,24 @@
import type { DocMode } from '@affine/graphql';
import { Service } from '@toeverything/infra';
import type { NotificationStore } from '../stores/notification';
export class NotificationService extends Service {
constructor(private readonly store: NotificationStore) {
super();
}
async mentionUser(
userId: string,
workspaceId: string,
doc: {
id: string;
title: string;
blockId?: string;
elementId?: string;
mode: DocMode;
}
): Promise<string> {
return this.store.mentionUser(userId, workspaceId, doc);
}
}

View File

@@ -1,6 +1,8 @@
import {
type DocMode,
type ListNotificationsQuery,
listNotificationsQuery,
mentionUserMutation,
notificationCountQuery,
type PaginationInput,
readNotificationMutation,
@@ -82,4 +84,28 @@ export class NotificationStore extends Store {
},
});
}
async mentionUser(
userId: string,
workspaceId: string,
doc: {
id: string;
title: string;
blockId?: string;
elementId?: string;
mode: DocMode;
}
) {
const result = await this.gqlService.gql({
query: mentionUserMutation,
variables: {
input: {
userId,
workspaceId,
doc,
},
},
});
return result.mentionUser;
}
}

View File

@@ -1107,6 +1107,14 @@ export const listUsersQuery = {
}`,
};
export const mentionUserMutation = {
id: 'mentionUserMutation' as const,
op: 'mentionUser',
query: `mutation mentionUser($input: MentionInput!) {
mentionUser(input: $input)
}`,
};
export const notificationCountQuery = {
id: 'notificationCountQuery' as const,
op: 'notificationCount',

View File

@@ -0,0 +1,3 @@
mutation mentionUser($input: MentionInput!) {
mentionUser(input: $input)
}

View File

@@ -3424,6 +3424,15 @@ export type ListUsersQuery = {
}>;
};
export type MentionUserMutationVariables = Exact<{
input: MentionInput;
}>;
export type MentionUserMutation = {
__typename?: 'Mutation';
mentionUser: string;
};
export type NotificationCountQueryVariables = Exact<{ [key: string]: never }>;
export type NotificationCountQuery = {
@@ -4434,6 +4443,11 @@ export type Mutations =
variables: LeaveWorkspaceMutationVariables;
response: LeaveWorkspaceMutation;
}
| {
name: 'mentionUserMutation';
variables: MentionUserMutationVariables;
response: MentionUserMutation;
}
| {
name: 'publishPageMutation';
variables: PublishPageMutationVariables;