mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-01 01:29:31 +08:00
feat(core): add notification service (#10855)
This commit is contained in:
@@ -1,18 +1,22 @@
|
|||||||
export { NotificationCountService } from './services/count';
|
export { NotificationCountService } from './services/count';
|
||||||
export { NotificationListService } from './services/list';
|
export { NotificationListService } from './services/list';
|
||||||
|
export { NotificationService } from './services/notification';
|
||||||
export type { Notification, NotificationBody } from './stores/notification';
|
export type { Notification, NotificationBody } from './stores/notification';
|
||||||
export { NotificationType } from './stores/notification';
|
export { NotificationType } from './stores/notification';
|
||||||
|
|
||||||
import type { Framework } from '@toeverything/infra';
|
import type { Framework } from '@toeverything/infra';
|
||||||
|
|
||||||
import { GraphQLService, ServerScope, ServerService } from '../cloud';
|
import { GraphQLService, ServerScope, ServerService } from '../cloud';
|
||||||
import { GlobalSessionState } from '../storage';
|
import { GlobalSessionState } from '../storage';
|
||||||
import { NotificationCountService } from './services/count';
|
import { NotificationCountService } from './services/count';
|
||||||
import { NotificationListService } from './services/list';
|
import { NotificationListService } from './services/list';
|
||||||
|
import { NotificationService } from './services/notification';
|
||||||
import { NotificationStore } from './stores/notification';
|
import { NotificationStore } from './stores/notification';
|
||||||
|
|
||||||
export function configureNotificationModule(framework: Framework) {
|
export function configureNotificationModule(framework: Framework) {
|
||||||
framework
|
framework
|
||||||
.scope(ServerScope)
|
.scope(ServerScope)
|
||||||
|
.service(NotificationService, [NotificationStore])
|
||||||
.service(NotificationCountService, [NotificationStore])
|
.service(NotificationCountService, [NotificationStore])
|
||||||
.service(NotificationListService, [
|
.service(NotificationListService, [
|
||||||
NotificationStore,
|
NotificationStore,
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
|
type DocMode,
|
||||||
type ListNotificationsQuery,
|
type ListNotificationsQuery,
|
||||||
listNotificationsQuery,
|
listNotificationsQuery,
|
||||||
|
mentionUserMutation,
|
||||||
notificationCountQuery,
|
notificationCountQuery,
|
||||||
type PaginationInput,
|
type PaginationInput,
|
||||||
readNotificationMutation,
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 = {
|
export const notificationCountQuery = {
|
||||||
id: 'notificationCountQuery' as const,
|
id: 'notificationCountQuery' as const,
|
||||||
op: 'notificationCount',
|
op: 'notificationCount',
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
mutation mentionUser($input: MentionInput!) {
|
||||||
|
mentionUser(input: $input)
|
||||||
|
}
|
||||||
@@ -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 NotificationCountQueryVariables = Exact<{ [key: string]: never }>;
|
||||||
|
|
||||||
export type NotificationCountQuery = {
|
export type NotificationCountQuery = {
|
||||||
@@ -4434,6 +4443,11 @@ export type Mutations =
|
|||||||
variables: LeaveWorkspaceMutationVariables;
|
variables: LeaveWorkspaceMutationVariables;
|
||||||
response: LeaveWorkspaceMutation;
|
response: LeaveWorkspaceMutation;
|
||||||
}
|
}
|
||||||
|
| {
|
||||||
|
name: 'mentionUserMutation';
|
||||||
|
variables: MentionUserMutationVariables;
|
||||||
|
response: MentionUserMutation;
|
||||||
|
}
|
||||||
| {
|
| {
|
||||||
name: 'publishPageMutation';
|
name: 'publishPageMutation';
|
||||||
variables: PublishPageMutationVariables;
|
variables: PublishPageMutationVariables;
|
||||||
|
|||||||
Reference in New Issue
Block a user