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;
}
}