diff --git a/client/mobile/src/lib/socket/index.ts b/client/mobile/src/lib/socket/index.ts index 753a5fa8..7a3de81b 100644 --- a/client/mobile/src/lib/socket/index.ts +++ b/client/mobile/src/lib/socket/index.ts @@ -37,9 +37,10 @@ export function createSocket(url: string, token: string): Promise { export function bindSocketEvent(socket: Socket): void { socket.on('notify:chat.inbox.append', (inboxItem: InboxItem) => { if (inboxItem.type === 'message') { + const payload = inboxItem.message ?? inboxItem.payload; showNotification({ - title: inboxItem.message?.converseId ?? '', - body: inboxItem.message?.messageSnippet ?? '', + title: payload.converseId ?? '', + body: payload.messageSnippet ?? '', }); } }); diff --git a/client/shared/index.tsx b/client/shared/index.tsx index 563c80a9..b603d99e 100644 --- a/client/shared/index.tsx +++ b/client/shared/index.tsx @@ -144,7 +144,11 @@ export type { GroupMember, GroupPanelFeature, } from './model/group'; -export type { InboxItem } from './model/inbox'; +export type { + BasicInboxItem, + MessageInboxItem, + InboxItem, +} from './model/inbox'; export { sendMessage, recallMessage, diff --git a/client/shared/model/inbox.ts b/client/shared/model/inbox.ts index bf897d10..894e94c5 100644 --- a/client/shared/model/inbox.ts +++ b/client/shared/model/inbox.ts @@ -3,21 +3,37 @@ import { request } from '../api/request'; /** * 收件箱记录项类型 */ -export interface InboxItem { +export interface BasicInboxItem { _id: string; userId: string; readed: boolean; + type: string; + payload?: object; + createdAt: string; + updatedAt: string; +} + +export interface MessageInboxItem extends BasicInboxItem { type: 'message'; + /** + * @deprecated + */ message?: { groupId?: string; converseId: string; messageId: string; messageSnippet: string; }; - createdAt: string; - updatedAt: string; + payload: { + groupId?: string; + converseId: string; + messageId: string; + messageSnippet: string; + }; } +export type InboxItem = MessageInboxItem; + /** * 设置收件箱某条记录已读 */ diff --git a/client/web/src/routes/Main/Content/Inbox/Content/Message.tsx b/client/web/src/routes/Main/Content/Inbox/Content/Message.tsx index dba0418f..f22c0d98 100644 --- a/client/web/src/routes/Main/Content/Inbox/Content/Message.tsx +++ b/client/web/src/routes/Main/Content/Inbox/Content/Message.tsx @@ -4,19 +4,24 @@ import { JumpToConverseButton } from '@/components/JumpToButton'; import { LoadingSpinner } from '@/components/LoadingSpinner'; import { Problem } from '@/components/Problem'; import React from 'react'; -import { InboxItem, model, showErrorToasts, useAsync } from 'tailchat-shared'; +import { + MessageInboxItem, + model, + showErrorToasts, + useAsync, +} from 'tailchat-shared'; interface Props { - info: InboxItem; + info: MessageInboxItem; } export const InboxMessageContent: React.FC = React.memo((props) => { const info = props.info; - const message = info.message; - if (!message) { + const payload = info.message ?? info.payload; + if (!payload) { return ; } - const { groupId, converseId, messageId } = message; + const { groupId, converseId, messageId } = payload; return (
diff --git a/client/web/src/routes/Main/Content/Inbox/Sidebar.tsx b/client/web/src/routes/Main/Content/Inbox/Sidebar.tsx index 3cb92644..da97d342 100644 --- a/client/web/src/routes/Main/Content/Inbox/Sidebar.tsx +++ b/client/web/src/routes/Main/Content/Inbox/Sidebar.tsx @@ -33,20 +33,20 @@ export const InboxSidebar: React.FC = React.memo(() => { const renderInbox = (item: InboxItem) => { if (item.type === 'message') { - const message: Partial = - item.message ?? {}; + const payload: Partial = + item.message ?? item.payload ?? {}; let title: React.ReactNode = ''; - if (isValidStr(message.groupId)) { - title = ; - } else if (isValidStr(message.converseId)) { - title = ; + if (isValidStr(payload.groupId)) { + title = ; + } else if (isValidStr(payload.converseId)) { + title = ; } return ( ; + createdAt: string; + updatedAt: string; +} + +export interface MessageInboxItem extends BasicInboxItem { + type: 'message'; + /** + * @deprecated + */ message?: { groupId?: string; converseId: string; messageId: string; messageSnippet: string; }; - payload?: Record; - createdAt: string; - updatedAt: string; + payload: { + groupId?: string; + converseId: string; + messageId: string; + messageSnippet: string; + }; } + +export type InboxItem = MessageInboxItem; diff --git a/server/models/chat/inbox.ts b/server/models/chat/inbox.ts index 9e82a5fb..7351702c 100644 --- a/server/models/chat/inbox.ts +++ b/server/models/chat/inbox.ts @@ -55,6 +55,9 @@ export class Inbox extends TimeStamps implements Base { }) type: string; + /** + * @deprecated please use payload + */ @prop() message?: InboxMessage; @@ -62,7 +65,7 @@ export class Inbox extends TimeStamps implements Base { * 信息体,没有类型 */ @prop() - payload?: object; + payload?: InboxMessage | object; /** * 是否已读 diff --git a/server/packages/sdk/src/structs/chat.ts b/server/packages/sdk/src/structs/chat.ts index e231d5cd..7cc0a6eb 100644 --- a/server/packages/sdk/src/structs/chat.ts +++ b/server/packages/sdk/src/structs/chat.ts @@ -44,7 +44,10 @@ interface InboxMessageStruct { messageSnippet: string; } -export interface InboxStruct { +/** + * 收件箱记录项类型 + */ +export interface BasicInboxItem { _id: string; userId: string; type: string; @@ -60,3 +63,24 @@ export interface InboxStruct { */ readed: boolean; } + +export interface MessageInboxItem extends BasicInboxItem { + type: 'message'; + /** + * @deprecated + */ + message?: { + groupId?: string; + converseId: string; + messageId: string; + messageSnippet: string; + }; + payload: { + groupId?: string; + converseId: string; + messageId: string; + messageSnippet: string; + }; +} + +export type InboxStruct = MessageInboxItem; diff --git a/server/plugins/com.msgbyte.getui/services/getui.service.ts b/server/plugins/com.msgbyte.getui/services/getui.service.ts index 29bfbe5d..aa128661 100644 --- a/server/plugins/com.msgbyte.getui/services/getui.service.ts +++ b/server/plugins/com.msgbyte.getui/services/getui.service.ts @@ -50,7 +50,7 @@ class GetuiService extends TcService { async (inboxItem: InboxStruct, ctx) => { if (inboxItem.type === 'message') { const userId = inboxItem.userId; - const message = inboxItem.message; + const message = inboxItem.payload; let title = 'new'; if (message.groupId) { diff --git a/server/services/core/chat/inbox.service.ts b/server/services/core/chat/inbox.service.ts index 99776281..a43e14ac 100644 --- a/server/services/core/chat/inbox.service.ts +++ b/server/services/core/chat/inbox.service.ts @@ -32,12 +32,15 @@ class InboxService extends TcService { if (payload.type === 'add') { await Promise.all( mentions.map((userId) => { - return ctx.call('chat.inbox.appendMessage', { + return ctx.call('chat.inbox.append', { userId, - groupId: payload.groupId, - converseId: payload.converseId, - messageId: payload.messageId, - messageSnippet: payload.content, + type: 'message', + payload: { + groupId: payload.groupId, + converseId: payload.converseId, + messageId: payload.messageId, + messageSnippet: payload.content, + }, }); }) ); @@ -65,16 +68,6 @@ class InboxService extends TcService { payload: 'any', }, }); - this.registerAction('appendMessage', this.appendMessage, { - visibility: 'public', - params: { - userId: { type: 'string', optional: true }, - groupId: { type: 'string', optional: true }, - converseId: 'string', - messageId: 'string', - messageSnippet: 'string', - }, - }); this.registerAction('removeMessage', this.removeMessage, { visibility: 'public', params: { @@ -120,45 +113,6 @@ class InboxService extends TcService { return true; } - /** - * 增加收件夹消息 - */ - async appendMessage( - ctx: TcContext<{ - userId?: string; - groupId?: string; - converseId: string; - messageId: string; - messageSnippet: string; - }> - ) { - const { - userId = ctx.meta.userId, - groupId, - converseId, - messageId, - messageSnippet, - } = ctx.params; - - const doc = await this.adapter.model.create({ - userId, - type: 'message', - message: { - groupId, - converseId, - messageId, - messageSnippet, - }, - }); - - const inboxItem = await this.transformDocuments(ctx, {}, doc); - - await this.notifyUsersInboxAppend(ctx, [userId], inboxItem); - await this.emitInboxAppendEvent(ctx, inboxItem); - - return true; - } - async removeMessage( ctx: TcContext<{ userId?: string; @@ -177,7 +131,7 @@ class InboxService extends TcService { await this.adapter.model.remove({ userId, type: 'message', - message: { + payload: { groupId, converseId, messageId,