feat(chat): 添加聊天界面和文件更新SDK功能
- 实现完整的聊天界面UI组件,支持文本、图片、视频、音频、文件等多种消息类型 - 集成IM消息收发功能,实现消息气泡显示和用户头像占位符 - 添加媒体文件选择和拍摄功能,支持相册图片、视频及相机拍照录像 - 实现语音录制和播放功能,包含按住说话交互和权限处理 - 添加群组提及功能,支持@用户和提及候选列表显示 - 实现消息回复和引用功能,支持消息长按回复操作 - 添加本地消息搜索功能,支持搜索当前会话的历史消息 - 实现文件上传下载功能,集成FileSDK进行文件传输管理 - 添加应用更新检查功能,集成UpdateSDK支持版本更新 - 实现消息状态显示,包括发送、送达、已读等状态标识 - 添加群组已读人数统计,显示消息在群聊中的阅读情况 - 实现草稿保存和恢复功能,支持断点续聊体验 - 添加连接状态横幅,实时显示IM服务连接状态 - 实现滚动加载更多历史消息,优化大量消息的性能表现 - 添加多媒体文件下载保存功能,支持保存到应用专属目录
这个提交包含在:
父节点
ebf6a389cf
当前提交
110f5f3421
@ -3,7 +3,10 @@ import { http } from '../core/http'
|
|||||||
import type {
|
import type {
|
||||||
ChatType,
|
ChatType,
|
||||||
ConversationView,
|
ConversationView,
|
||||||
|
FriendRequest,
|
||||||
HistoryQuery,
|
HistoryQuery,
|
||||||
|
GroupJoinRequest,
|
||||||
|
ImGroup,
|
||||||
ImMessage,
|
ImMessage,
|
||||||
PageResult,
|
PageResult,
|
||||||
UserProfile,
|
UserProfile,
|
||||||
@ -100,3 +103,68 @@ export function updateProfile(
|
|||||||
appQuery({ nickname, avatar, gender }),
|
appQuery({ nickname, avatar, gender }),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function listFriends(): Promise<string[]> {
|
||||||
|
return http.get<string[]>('/api/im/friends', appQuery())
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listGroups(): Promise<ImGroup[]> {
|
||||||
|
return http.get<ImGroup[]>('/api/im/groups', appQuery())
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getGroupInfo(groupId: string): Promise<ImGroup> {
|
||||||
|
return http.get<ImGroup>(`/api/im/groups/${encodeURIComponent(groupId)}`, appQuery())
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sendFriendRequest(toUserId: string, remark?: string): Promise<FriendRequest> {
|
||||||
|
return http.post<FriendRequest>(
|
||||||
|
'/api/im/friend-requests',
|
||||||
|
undefined,
|
||||||
|
appQuery({
|
||||||
|
toUserId,
|
||||||
|
...(remark ? { remark } : {}),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listFriendRequests(direction: 'incoming' | 'outgoing' = 'incoming'): Promise<FriendRequest[]> {
|
||||||
|
return http.get<FriendRequest[]>('/api/im/friend-requests', appQuery({ direction }))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function acceptFriendRequest(requestId: string): Promise<FriendRequest> {
|
||||||
|
return http.post<FriendRequest>(`/api/im/friend-requests/${encodeURIComponent(requestId)}/accept`, undefined, appQuery())
|
||||||
|
}
|
||||||
|
|
||||||
|
export function rejectFriendRequest(requestId: string): Promise<FriendRequest> {
|
||||||
|
return http.post<FriendRequest>(`/api/im/friend-requests/${encodeURIComponent(requestId)}/reject`, undefined, appQuery())
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sendGroupJoinRequest(groupId: string, remark?: string): Promise<GroupJoinRequest> {
|
||||||
|
return http.post<GroupJoinRequest>(
|
||||||
|
`/api/im/groups/${encodeURIComponent(groupId)}/join-requests`,
|
||||||
|
undefined,
|
||||||
|
appQuery({
|
||||||
|
...(remark ? { remark } : {}),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listGroupJoinRequests(groupId: string): Promise<GroupJoinRequest[]> {
|
||||||
|
return http.get<GroupJoinRequest[]>(`/api/im/groups/${encodeURIComponent(groupId)}/join-requests`, appQuery())
|
||||||
|
}
|
||||||
|
|
||||||
|
export function acceptGroupJoinRequest(groupId: string, requestId: string): Promise<GroupJoinRequest> {
|
||||||
|
return http.post<GroupJoinRequest>(
|
||||||
|
`/api/im/groups/${encodeURIComponent(groupId)}/join-requests/${encodeURIComponent(requestId)}/accept`,
|
||||||
|
undefined,
|
||||||
|
appQuery(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function rejectGroupJoinRequest(groupId: string, requestId: string): Promise<GroupJoinRequest> {
|
||||||
|
return http.post<GroupJoinRequest>(
|
||||||
|
`/api/im/groups/${encodeURIComponent(groupId)}/join-requests/${encodeURIComponent(requestId)}/reject`,
|
||||||
|
undefined,
|
||||||
|
appQuery(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@ -2,10 +2,21 @@ import { ref, shallowRef, onUnmounted } from 'vue'
|
|||||||
import { ImClient } from './ImClient'
|
import { ImClient } from './ImClient'
|
||||||
import {
|
import {
|
||||||
deleteConversation,
|
deleteConversation,
|
||||||
|
acceptFriendRequest,
|
||||||
|
acceptGroupJoinRequest,
|
||||||
|
getGroupInfo,
|
||||||
fetchGroupHistory,
|
fetchGroupHistory,
|
||||||
fetchHistory,
|
fetchHistory,
|
||||||
|
listFriendRequests,
|
||||||
|
listFriends,
|
||||||
|
listGroupJoinRequests,
|
||||||
|
listGroups,
|
||||||
listConversations,
|
listConversations,
|
||||||
markRead,
|
markRead,
|
||||||
|
rejectFriendRequest,
|
||||||
|
rejectGroupJoinRequest,
|
||||||
|
sendFriendRequest,
|
||||||
|
sendGroupJoinRequest,
|
||||||
setConversationMuted,
|
setConversationMuted,
|
||||||
setConversationPinned,
|
setConversationPinned,
|
||||||
setDraft,
|
setDraft,
|
||||||
@ -107,6 +118,50 @@ export function useIm() {
|
|||||||
return deleteConversation(targetId, chatType)
|
return deleteConversation(targetId, chatType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getFriends() {
|
||||||
|
return listFriends()
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGroups() {
|
||||||
|
return listGroups()
|
||||||
|
}
|
||||||
|
|
||||||
|
function getGroup(groupId: string) {
|
||||||
|
return getGroupInfo(groupId)
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendFriend(toUserId: string, remark?: string) {
|
||||||
|
return sendFriendRequest(toUserId, remark)
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadFriendRequests(direction: 'incoming' | 'outgoing' = 'incoming') {
|
||||||
|
return listFriendRequests(direction)
|
||||||
|
}
|
||||||
|
|
||||||
|
function approveFriendRequest(requestId: string) {
|
||||||
|
return acceptFriendRequest(requestId)
|
||||||
|
}
|
||||||
|
|
||||||
|
function declineFriendRequest(requestId: string) {
|
||||||
|
return rejectFriendRequest(requestId)
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendGroupJoin(groupId: string, remark?: string) {
|
||||||
|
return sendGroupJoinRequest(groupId, remark)
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadGroupJoinRequests(groupId: string) {
|
||||||
|
return listGroupJoinRequests(groupId)
|
||||||
|
}
|
||||||
|
|
||||||
|
function approveGroupJoinRequest(groupId: string, requestId: string) {
|
||||||
|
return acceptGroupJoinRequest(groupId, requestId)
|
||||||
|
}
|
||||||
|
|
||||||
|
function declineGroupJoinRequest(groupId: string, requestId: string) {
|
||||||
|
return rejectGroupJoinRequest(groupId, requestId)
|
||||||
|
}
|
||||||
|
|
||||||
onUnmounted(disconnect)
|
onUnmounted(disconnect)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -126,5 +181,16 @@ export function useIm() {
|
|||||||
setConversationMutedState,
|
setConversationMutedState,
|
||||||
setConversationDraft,
|
setConversationDraft,
|
||||||
removeConversation,
|
removeConversation,
|
||||||
|
getFriends,
|
||||||
|
getGroups,
|
||||||
|
getGroup,
|
||||||
|
sendFriend,
|
||||||
|
loadFriendRequests,
|
||||||
|
approveFriendRequest,
|
||||||
|
declineFriendRequest,
|
||||||
|
sendGroupJoin,
|
||||||
|
loadGroupJoinRequests,
|
||||||
|
approveGroupJoinRequest,
|
||||||
|
declineGroupJoinRequest,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/index.ts
14
src/index.ts
@ -2,12 +2,23 @@ export { init, setToken, setUserId, getToken, getUserId, getConfig } from './cor
|
|||||||
export { http } from './core/http'
|
export { http } from './core/http'
|
||||||
export { ImClient } from './im/ImClient'
|
export { ImClient } from './im/ImClient'
|
||||||
export {
|
export {
|
||||||
|
acceptFriendRequest,
|
||||||
|
acceptGroupJoinRequest,
|
||||||
deleteConversation,
|
deleteConversation,
|
||||||
|
getGroupInfo,
|
||||||
fetchGroupHistory,
|
fetchGroupHistory,
|
||||||
fetchHistory,
|
fetchHistory,
|
||||||
|
listFriendRequests,
|
||||||
|
listFriends,
|
||||||
|
listGroupJoinRequests,
|
||||||
|
listGroups,
|
||||||
listConversations,
|
listConversations,
|
||||||
markRead,
|
markRead,
|
||||||
getProfile,
|
getProfile,
|
||||||
|
rejectFriendRequest,
|
||||||
|
rejectGroupJoinRequest,
|
||||||
|
sendFriendRequest,
|
||||||
|
sendGroupJoinRequest,
|
||||||
setConversationMuted,
|
setConversationMuted,
|
||||||
setConversationPinned,
|
setConversationPinned,
|
||||||
setDraft,
|
setDraft,
|
||||||
@ -22,6 +33,9 @@ export type {
|
|||||||
ImMessage,
|
ImMessage,
|
||||||
ConversationView,
|
ConversationView,
|
||||||
HistoryQuery,
|
HistoryQuery,
|
||||||
|
ImGroup,
|
||||||
|
FriendRequest,
|
||||||
|
GroupJoinRequest,
|
||||||
PageResult,
|
PageResult,
|
||||||
UserProfile,
|
UserProfile,
|
||||||
SendMessageParams,
|
SendMessageParams,
|
||||||
|
|||||||
@ -84,6 +84,40 @@ export interface UserProfile {
|
|||||||
createdAt?: string | number | null
|
createdAt?: string | number | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ImGroup {
|
||||||
|
id: string
|
||||||
|
appId?: string
|
||||||
|
name: string
|
||||||
|
groupType?: string
|
||||||
|
creatorId: string
|
||||||
|
memberIds: string
|
||||||
|
adminIds: string
|
||||||
|
announcement?: string | null
|
||||||
|
createdAt?: string | number | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FriendRequest {
|
||||||
|
id: string
|
||||||
|
appId?: string
|
||||||
|
fromUserId: string
|
||||||
|
toUserId: string
|
||||||
|
remark?: string | null
|
||||||
|
status: 'PENDING' | 'ACCEPTED' | 'REJECTED'
|
||||||
|
createdAt: string | number
|
||||||
|
reviewedAt?: string | number | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupJoinRequest {
|
||||||
|
id: string
|
||||||
|
appId?: string
|
||||||
|
groupId: string
|
||||||
|
requesterId: string
|
||||||
|
remark?: string | null
|
||||||
|
status: 'PENDING' | 'ACCEPTED' | 'REJECTED'
|
||||||
|
createdAt: string | number
|
||||||
|
reviewedAt?: string | number | null
|
||||||
|
}
|
||||||
|
|
||||||
export interface SendMessageParams {
|
export interface SendMessageParams {
|
||||||
messageId?: string
|
messageId?: string
|
||||||
toId: string
|
toId: string
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户