diff --git a/src/im/useIm.ts b/src/im/useIm.ts index 512602a..e53a6e7 100644 --- a/src/im/useIm.ts +++ b/src/im/useIm.ts @@ -1,4 +1,4 @@ -import { ref, shallowRef, onUnmounted } from 'vue' +import { ref, shallowRef, onUnmounted, reactive, type Ref } from 'vue' import { ImClient } from './ImClient' import { deleteConversation, @@ -28,13 +28,49 @@ import { import type { ConversationView, HistoryQuery, + ImGroup, ImMessage, PageResult, SendMessageParams, ChatType, + FriendRequest, + GroupJoinRequest, } from '../types' -export function useIm() { +export interface UseImReturn { + connect: () => void + send: (params: SendMessageParams) => ImMessage + revoke: (msgId: string) => Promise + edit: (msgId: string, content: string) => Promise + disconnect: () => void + messages: Ref + conversations: Ref + connected: Ref + error: Ref + refreshConversations: () => Promise + loadHistory: (toId: string, query?: HistoryQuery) => Promise> + loadGroupHistory: (groupId: string, query?: HistoryQuery) => Promise> + jumpToMessagePage: (toId: string, messageId: string, pageSize?: number, maxPages?: number) => Promise + jumpToGroupMessagePage: (groupId: string, messageId: string, pageSize?: number, maxPages?: number) => Promise + setConversationRead: (targetId: string, chatType?: ChatType) => Promise + setConversationPinnedState: (targetId: string, chatType: ChatType, pinned: boolean) => Promise + setConversationMutedState: (targetId: string, chatType: ChatType, muted: boolean) => Promise + setConversationDraft: (targetId: string, chatType: ChatType, draft: string) => Promise + removeConversation: (targetId: string, chatType: ChatType) => Promise + getFriends: () => Promise + getGroups: () => Promise + getGroup: (groupId: string) => Promise + sendFriend: (toUserId: string, remark?: string) => Promise + loadFriendRequests: (direction?: 'incoming' | 'outgoing') => Promise + approveFriendRequest: (requestId: string) => Promise + declineFriendRequest: (requestId: string) => Promise + sendGroupJoin: (groupId: string, remark?: string) => Promise + loadGroupJoinRequests: (groupId: string) => Promise + approveGroupJoinRequest: (groupId: string, requestId: string) => Promise + declineGroupJoinRequest: (groupId: string, requestId: string) => Promise +} + +export function useIm(): UseImReturn { const client = shallowRef(null) const messages = ref([]) const conversations = ref([]) @@ -220,7 +256,7 @@ export function useIm() { onUnmounted(disconnect) - return { + return reactive({ connect, send, revoke, @@ -251,5 +287,5 @@ export function useIm() { loadGroupJoinRequests, approveGroupJoinRequest, declineGroupJoinRequest, - } + }) as UseImReturn } diff --git a/src/types/index.ts b/src/types/index.ts index 2e78a4e..1526599 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -18,6 +18,8 @@ export type MsgType = | 'RICH_TEXT' | 'CALL_AUDIO' | 'CALL_VIDEO' + | 'QUOTE' + | 'MERGE' | 'REVOKED' | 'FORWARD' @@ -39,6 +41,7 @@ export interface ImMessage { groupReadCount?: number revoked?: boolean createdAt: string + editedAt?: string | null } export interface ConversationView {