This commit is contained in:
Your Name
2026-03-11 09:49:47 +08:00
parent 02ae537b4c
commit 38ad60f4bb
290 changed files with 36917 additions and 123 deletions
@@ -0,0 +1,102 @@
import type { ChatSDK } from '@tencentcloud/lite-chat/basic';
import type { LoginParams } from '../../type';
import type { IEventCenter } from './event-center';
import type {
ITUIConversationService,
ITUIChatService,
ITUIGroupService,
ITUIUserService,
} from '../service';
import type { ITUIStore } from '../store';
/**
* @interface ITUIChatEngine
* @property {Object} EVENT {@link https://web.sdk.qcloud.com/im/doc/v3/zh-cn/module-EVENT.html Chat SDK 定义的事件列表 }
* @property {Object} TYPES {@link https://web.sdk.qcloud.com/im/doc/v3/zh-cn/module-TYPES.html Chat SDK 定义的类型常量}
*/
export interface ITUIChatEngine {
isInited: boolean;
chat: ChatSDK;
EVENT: any;
TYPES: any;
eventCenter: IEventCenter;
TUIStore: ITUIStore;
TUIConversation: ITUIConversationService;
TUIChat: ITUIChatService;
TUIGroup: ITUIGroupService;
TUIUser: ITUIUserService;
/**
* 创建 Chat SDK 实例 & 登录 Chat SDK
* @function
* @param {LoginParams} options 登录参数
* @example
* let promise = TUIChatEngine.login({
* SDKAppID: xxx,
* userID: 'xxx',
* userSig: 'xxx',
* useUploadPlugin: true, // 使用文件上传插件
* });
* promise.then(() => {
* // 登录成功后进行相关业务逻辑处理
* })
*/
login(options: LoginParams): Promise<any>;
/**
* 登出 Chat SDK
* @function
* @example
* let promise = TUIChatEngine.logout();
* promise.then(() => {
* // 登出成功后进行相关业务逻辑处理
* })
*/
logout(): Promise<any>;
/**
* Chat SDK 是否 ready。SDK ready 后,开发者可调用 SDK 发送消息等 API,使用 SDK 的各项功能。
* @function
* @example
* let isReady = TUIChatEngine.isReady();
*/
isReady(): boolean;
/**
* 销毁 Chat SDK 实例,SDK 会先 logout,然后断开 WebSocket 长连接,并释放资源。
* @function
* @example
* let promise = TUIChatEngine.destroy();
*/
destroy(): Promise<any>;
/**
* 设置 SDK 日志级别
* @function
* @param {number} level 日志级别
* - 0 普通级别,日志量较多,接入时建议使用
* - 1 release级别,SDK 输出关键信息,生产环境时建议使用
* - 2 告警级别,SDK 只输出告警和错误级别的日志
* - 3 错误级别,SDK 只输出错误级别的日志
* - 4 无日志级别,SDK 将不打印任何日志
* @example
* TUIChatEngine.setLogLevel(0)
*/
setLogLevel(level: number): void;
/**
* 模块挂载
* @function
* @param {string} name 模块名
* @param {any} instance 类的实例
* @private
*/
mount(name: string, instance: any): void;
/**
* 获取当前用户 ID
* @function
* @private
*/
getMyUserID(): string;
}
@@ -0,0 +1,21 @@
import type { func } from '../../type';
export interface IEventCenter {
/**
* Service 添加监听事件
* @param {string} event 事件名
* @param {Function} callback 回调函数
*/
addEvent(event: string, callback: func): void;
/**
* 移除 chatEngine 内部注册的事件回调
*/
removeEvents(): void;
/**
* 解绑 IM SDK 事件
*/
unbindIMEvents(): void;
}
@@ -0,0 +1,2 @@
export * from './event-center';
export * from './engine';
@@ -0,0 +1,12 @@
/**
* @interface TUIGlobal
*/
export interface ITUIGlobal {
global: any; // 挂在 wx、uni、window 对象
isOfficial: boolean;
[key: string]: any;
initOfficial(isOfficial: boolean): void;
getPlatform(): string;
}
@@ -0,0 +1,137 @@
import type { Conversation } from '@tencentcloud/lite-chat/basic';
/**
* @description ConversationModel 主要负责会话操作和会话数据处理,ConversationModel 不需要开发者进行开发,由 TUIChatEngine 通过 {@link https://web.sdk.qcloud.com/im/doc/chat-engine/global.html#ConversationStore ConversationStore} 的 conversationList 提供给开发者直接使用。
* @interface ConversationModel
* @property {String} conversationID - 会话 ID。会话ID组成方式:<br/>
* - `C2C${userID}`(单聊)
* - `GROUP${groupID}`(群聊)
* @property {String} type - 会话类型,具体如下:<br/>
* | 类型 | 含义 |
* | :--- | :---- |
* | TUIChatEngine.TYPES.CONV_C2C | C2CClient to Client, 端到端)会话 |
* | TUIChatEngine.TYPES.CONV_GROUP | GROUP(群组)会话 |
* | TUIChatEngine.TYPES.CONV_SYSTEM | SYSTEM(系统)会话。该会话只能接收来自系统的通知消息,不能发送消息。 |
* @property {String} subType - 群组会话的群组类型,具体如下:<br/>
* | 类型 | 含义 |
* | :--- | :---- |
* | TUIChatEngine.TYPES.GRP_WORK | 好友工作群 |
* | TUIChatEngine.TYPES.GRP_PUBLIC | 陌生人社交群 |
* | TUIChatEngine.TYPES.GRP_MEETING | 临时会议群 |
* | TUIChatEngine.TYPES.GRP_AVCHATROOM | 直播群 |
* @property {Number} unreadCount - 未读计数。TUIChatEngine.TYPES.GRP_MEETING / TUIChatEngine.TYPES.GRP_AVCHATROOM 类型的群组会话不记录未读计数,该字段值为0
* @property {Object} lastMessage - 会话最新的消息
* @property {String} lastMessage.nick - 群会话最新消息的发送者的昵称,C2C 会话为 ''
* @property {String} lastMessage.nameCard - 群会话最新消息的发送者的群名片,C2C 会话为 ''
* @property {Number} lastMessage.lastTime - 当前会话最新消息的时间戳,单位:秒
* @property {Number} lastMessage.lastSequence - 当前会话的最新消息的 Sequence
* @property {String} lastMessage.fromAccount - 最新消息来源用户的 userID
* @property {Boolean} lastMessage.isRevoked - 会话最新的消息是否已被撤回,true 表示已撤回,默认值为 false
* @property {String|null} lastMessage.revoker - 消息撤回者的 userID
* @property {Boolean} lastMessage.isPeerRead - 对端是否已读 C2C 会话的最新消息,默认值为 false
* @property {String} lastMessage.messageForShow - 最新消息的内容,用于展示。可能值:文本消息内容、"[图片]"、"[语音]"、"[位置]"、"[表情]"、"[文件]"、"[自定义消息]"。<br/>
* 若该字段不满足您的需求,您可以使用 payload 来自定义渲染。
* @property {String} lastMessage.type - 消息类型,具体如下:<br/>
* | 类型 | 含义 |
* | :--- | :---- |
* | TUIChatEngine.TYPES.MSG_TEXT | 文本消息 |
* | TUIChatEngine.TYPES.MSG_IMAGE | 图片消息 |
* | TUIChatEngine.TYPES.MSG_SOUND | 音频消息 |
* | TUIChatEngine.TYPES.MSG_AUDIO | 音频消息 |
* | TUIChatEngine.TYPES.MSG_VIDEO | 视频消息 |
* | TUIChatEngine.TYPES.MSG_FILE | 文件消息 |
* | TUIChatEngine.TYPES.MSG_LOCATION | 地理位置消息 |
* | TUIChatEngine.TYPES.MSG_CUSTOM | 自定义消息 |
* | TUIChatEngine.TYPES.MSG_GRP_TIP | 群提示消息 |
* | TUIChatEngine.TYPES.MSG_GRP_SYS_NOTICE | 群系统通知消息 |
* @property {Object} lastMessage.payload - 消息的内容,收到的音频 / 文件消息的 payload 中没有 url 字段。
* @property {Group} groupProfile - 群会话的群组资料
* @property {Profile} userProfile - C2C会话的用户资料
* @property {GroupAtInfo[]} groupAtInfoList - 群会话的 at 信息列表,接入侧可根据此信息在会话列表展示【有人@我】【@所有人】等效果。
* @property {String} remark - 好友备注,只有C2C会话且对端是我的好友,且我设置过此好友的备注才有值
* @property {Boolean} isPinned - 会话是否置顶
* @property {String} messageRemindType - 消息提醒类型,具体如下:<br/>
* - TUIChatEngine.TYPES.MSG_REMIND_ACPT_AND_NOTE 在线正常接收消息,离线时会有厂商的离线推送通知(Web 和小程序端无离线推送)
* - TUIChatEngine.TYPES.MSG_REMIND_DISCARD 在线和离线都拒收消息
* - TUIChatEngine.TYPES.MSG_REMIND_ACPT_NOT_NOTE 在线正常接收消息,离线不会有推送通知(消息免打扰)
* @property {Array} markList - 会话标记列表,具体如下:<br/>
* - TUIChatEngine.TYPES.CONV_MARK_TYPE_STAR 会话标星
* - TUIChatEngine.TYPES.CONV_MARK_TYPE_UNREAD 会话标记未读(重要会话)
* - TUIChatEngine.TYPES.CONV_MARK_TYPE_FOLD 会话折叠
* - TUIChatEngine.TYPES.CONV_MARK_TYPE_HIDE 会话隐藏
* @property {String} customData - 会话自定义数据
* @property {Array} conversationGroupList - 会话所属分组列表
* @property {String} draftText - 会话草稿
* @property {Boolean} isMuted 会话是否已设置免打扰,默认为 false
* @property {Number} operationType 群组操作类型, 默认 0。4-被踢出群组 5-群组被解散 8-主动退群
*/
export interface IConversationModel {
conversationID: string;
type: string;
subType: string;
unreadCount: number;
lastMessage?: {
nick: string;
nameCard: string;
lastTime: number | string;
lastSequence: string;
fromAccount: string;
isRevoked: boolean;
revoker?: string;
isPeerRead: boolean;
messageForShow: string;
type: string;
payload: any;
};
groupProfile?: any;
userProfile?: any;
groupAtInfoList?: any[];
remark: string;
isPinned: boolean;
messageRemindType: string;
markList: string[];
customData: string;
conversationGroupList: any[];
draftText: string;
isMuted: boolean;
operationType: number; // 群组会话的操作类型
_conversation: any; // 保存原始 conversation 实例数据
/**
* 更新 conversationModel 属性
* @function
* @private
*/
updateProperties(options: Conversation): void;
/**
* 更新 operationType 属性
* @function
* @private
*/
updateOperationType(operationType: number): void;
/**
* 获取 IM SDK 提供的 conversation 对象
* @function
* @private
*/
getConversation(): any;
// 以下方法用于处理 conversation 需要展示的数据
/**
* 获取会话头像
* @function
* @example
* let avatar = conversationModel.getAvatar();
*/
getAvatar(): string;
/**
* 获取会话名称
* @function
* @example
* let name = conversationModel.getShowName();
*/
getShowName(): string;
}
@@ -0,0 +1,39 @@
import type TencentCloudChat from '@tencentcloud/lite-chat/basic';
/**
* @description GroupModel 的属性与 IM SDK Group 属性字段保持一致,详情可参考:{@link https://web.sdk.qcloud.com/im/doc/zh-cn/Group.html Group}。
* @interface GroupModel
*/
export interface IGroupModel {
groupID: string;
name: string;
avatar: string;
type: TencentCloudChat.TYPES.GRP_WORK
| TencentCloudChat.TYPES.GRP_PUBLIC
| TencentCloudChat.TYPES.GRP_MEETING
| TencentCloudChat.TYPES.GRP_AVCHATROOM
| TencentCloudChat.TYPES.GRP_COMMUNITY;
introduction: string;
notification: string;
ownerID: string;
createTime: number;
infoSequence?: number;
lastInfoTime?: number;
selfInfo?: {
role?: string;
messageRemindType?: string;
joinTime?: number;
nameCard?: string;
userID?: string;
memberCustomField?: any[];
};
lastMessage?: any;
nextMessageSeq: number;
memberCount: number;
maxMemberCount: number;
muteAllMembers: boolean;
joinOption: string;
groupCustomField?: any[];
isSupportTopic: boolean;
groupAttributes: any;
groupCounters: any;
}
@@ -0,0 +1,3 @@
export * from './conversation';
export * from './group';
export * from './message';
@@ -0,0 +1,326 @@
import type { Message } from '@tencentcloud/lite-chat/basic';
import type TencentCloudChat from '@tencentcloud/lite-chat/basic';
import type { ModifyMessageParams, ReactionInfo } from '../../type';
/**
* @description MessageModel 主要负责消息操作和消息上屏数据处理,MessageModel 不需要开发者进行开发,由 TUIChatEngine 通过 {@link https://web.sdk.qcloud.com/im/doc/chat-engine/global.html#ChatStore ChatStore} 的 messageList 提供给开发者直接使用。<br/>
* @interface IMessageModel
* @property {String} ID - 消息 ID
* @property {String} type - 消息类型,具体如下:<br/>
* | 类型 | 含义 |
* | :--- | :---- |
* | TUIChatEngine.TYPES.MSG_TEXT | 文本消息 |
* | TUIChatEngine.TYPES.MSG_IMAGE | 图片消息 |
* | TUIChatEngine.TYPES.MSG_SOUND | 音频消息 |
* | TUIChatEngine.TYPES.MSG_AUDIO | 音频消息 |
* | TUIChatEngine.TYPES.MSG_VIDEO | 视频消息 |
* | TUIChatEngine.TYPES.MSG_FILE | 文件消息 |
* | TUIChatEngine.TYPES.MSG_CUSTOM | 自定义消息 |
* | TUIChatEngine.TYPES.MSG_MERGER | 合并消息 |
* | TUIChatEngine.TYPES.MSG_LOCATION | 位置消息 |
* | TUIChatEngine.TYPES.MSG_FACE | 表情消息 |
* | TUIChatEngine.TYPES.MSG_GRP_TIP | 群提示消息 |
* | TUIChatEngine.TYPES.MSG_GRP_SYS_NOTICE | 群系统通知消息 |
* @property {Object} payload - 消息的内容,详细内容请查看: [Message](https://web.sdk.qcloud.com/im/doc/v3/zh-cn/Message.html)
* @property {String} conversationID - 消息所属的会话 ID
* @property {String} conversationType - 消息所属会话的类型,具体如下:<br/>
* | 类型 | 含义 |
* | :--- | :---- |
* | TUIChatEngine.TYPES.CONV_C2C | C2C(Client to Client, 端到端) 会话 |
* | TUIChatEngine.TYPES.CONV_GROUP | GROUP(群组) 会话 |
* | TUIChatEngine.TYPES.CONV_SYSTEM | SYSTEM(系统) 会话 |
* @property {String} to - 接收方的 userID
* @property {String} from - 发送方的 userID,在消息发送时,会默认设置为当前登录的用户
* @property {String} flow - 消息的流向<br/>
* - in 为收到的消息
* - out 为发出的消息
* @property {Number} time - 消息时间戳。单位:秒
* @property {String} status - 消息状态
* - unSend(未发送)
* - success(发送成功)
* - fail(发送失败)
* @property {Boolean} isRevoked =false - 是否被撤回的消息,true 标识被撤回的消息
* @property {String} priority=TUIChatEngineTYPES.MSG_PRIORITY_NORMAL - 消息优先级,用于群聊
* @property {String} nick='' 消息发送者的昵称(在 AVChatRoom 内支持,需提前调用 [TUIUserService.updateMyProfile](https://web.sdk.qcloud.com/im/doc/chat-engine/ITUIUserService.html#updateMyProfile) 设置)
* @property {String} avatar='' 消息发送者的头像地址(在 AVChatRoom 内支持,需提前调用 [TUIUserService.updateMyProfile](https://web.sdk.qcloud.com/im/doc/chat-engine/ITUIUserService.html#updateMyProfile) 设置)
* @property {Boolean} isPeerRead=false - C2C 消息对端是否已读,true 标识对端已读
* @property {String} nameCard='' 非直播群消息发送者的群名片(也可称之为消息发送者的群昵称),需提前调用 [TUIGroupService.setGroupMemberNameCard](https://web.sdk.qcloud.com/im/doc/chat-engine/ITUIGroupService.html#setGroupMemberNameCard) 设置
* @property {Array} atUserList 群聊时此字段存储被 at 的群成员的 userID
* @property {String} cloudCustomData='' - 消息自定义数据(云端保存,会发送到对端,程序卸载重装后还能拉取到)
* @property {Boolean} isDeleted=false - 是否被删除的消息,true 标识被删除的消息
* @property {Boolean} isModified=false - 是否被修改过,true 标识被修改过的消息
* @property {Boolean} needReadReceipt=false - 是否需要已读回执,true 标识需要(需要您购买旗舰版套餐)
* @property {Object} readReceiptInfo={readCount,unreadCount,isPeerRead} - 消息已读回执信息
* @property {Number|undefined} readReceiptInfo.readCount - 群消息已读数<br/>
* 如果想要查询哪些群成员已读了消息,可调用 [TUIChatService.getGroupMessageReadMemberList](https://web.sdk.qcloud.com/im/doc/chat-engine/ITUIChatService.html#getGroupMessageReadMemberList)
* @property {Number|undefined} readReceiptInfo.unreadCount - 群消息未读数
* @property {Boolean|undefined} readReceiptInfo.isPeerRead - C2C消息对端是否已发送已读回执,消息发送方收到已读回执通知或拉漫游时会更新此属性
* @property {Boolean} isBroadcastMessage=false - 对所有直播群广播消息,true 标识直播群广播消息(需要您购买旗舰版套餐)
* @property {Boolean} isSupportExtension=false - 是否支持消息扩展,true 支持 false 不支持(需要您购买旗舰版套餐)
* @property {String|null} revoker - 消息撤回者的 userID
* @property {Number} progress - 图片、视频、语音、文件消息上传进度, 默认 0
* @property {Object} revokerInfo - 消息撤回者的信息。
* @property {String} revokerInfo.avatar - 消息撤回者的头像
* @property {String} revokerInfo.nick - 消息撤回者的昵称
* @property {String} revokerInfo.userID - 消息撤回者的 userID
* @property {String} revokeReason - 消息撤回的原因。
* @property {Boolean} hasRiskContent - 语音、视频消息是否被标记为有安全风险的消息,默认为 false。
* - 只有在开通【云端审核】功能后才生效,【云端审核】开通流程请参考 [云端审核功能](https://cloud.tencent.com/document/product/269/83795#.E4.BA.91.E7.AB.AF.E5.AE.A1.E6.A0.B8.E5.8A.9F.E8.83.BD)。
* @property {Array<ReactionInfo>} reactionList - 需要您购买旗舰版才支持此功能,购买旗舰版能力并重新登录后,拉漫游时会自动获取表情回复摘要信息。
*/
export interface IMessageModel {
ID: string;
type: TencentCloudChat.TYPES;
payload: any;
conversationID: string;
conversationType: TencentCloudChat.TYPES;
to: string;
from: string;
flow: string;
time: number;
status: string;
isRevoked: boolean;
priority: TencentCloudChat.TYPES;
nick: string;
avatar: string;
isPeerRead: boolean;
nameCard: string;
atUserList: string[];
cloudCustomData: string;
isDeleted: boolean;
isModified: boolean;
needReadReceipt: boolean;
readReceiptInfo: any;
isBroadcastMessage: boolean;
isSupportExtension: boolean;
receiverList?: string[];
revoker: string;
sequence: number;
progress: number;
revokerInfo: { userID: string; nick: string; avatar: string };
revokeReason: string;
hasRiskContent: boolean;
reactionList: ReactionInfo[];
/**
* 更新 messageModel 属性
* @function
* @private
*/
updateProperties(options: Message): void;
/**
* 获取 Chat SDK 提供的 message 实例
* @function
* @private
* @example
* let message = messageModel.getMessage();
*/
getMessage(): Message;
/**
* 修改消息
*
* @param {ModifyMessageParams} options 修改的内容
* @function
* @example
* let promise = messageModel.modifyMessage(options);
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
modifyMessage(options: ModifyMessageParams): Promise<any>;
/**
* 撤回单聊消息或者群聊消息。撤回成功后,消息对象的 isRevoked 属性值为 true。
* @function
* @example
* let promise = messageModel.revokeMessage();
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
revokeMessage(): Promise<any>;
/**
* 重发消息的接口,当消息发送失败时,可调用该接口进行重发
* @function
* @example
* let promise = messageModel.resendMessage();
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
resendMessage(): Promise<any>;
/**
* 删除消息的接口。删除成功后,被删除消息的 isDeleted 属性值为 true。
* @function
* @example
* let promise = messageModel.deleteMessage();
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
deleteMessage(): Promise<any>;
/**
* 引用当前消息
* @function
* @example
* let message = messageModel.quoteMessage();
*/
quoteMessage(): Message;
/**
* 回复当前消息
* @function
* @example
* let message = messageModel.replyMessage();
*/
replyMessage(): Message;
/**
* 设置消息扩展
* @function
* @param {Array<object>} extensions 扩展信息
* @private
* @example
* let promise = messageModel.setMessageExtensions([
* { key: 'a', value: '1' },
* { key: 'b', value: '2' }
* ]);
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
setMessageExtensions(extensions: object[]): Promise<any>;
/**
* 删除消息扩展
* @function
* @param {Array<string>|undefined} keyList 消息扩展 key 列表,不传 keyList 表示删除所有扩展 key
* @private
* @example
* // 删除部分 key
* let promise = messageModel.deleteMessageExtensions(['a', 'b']);
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
* // 删除全部 key
* let promise = messageModel.deleteMessageExtensions();
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
deleteMessageExtensions(keyList?: string[]): Promise<any>;
/**
* 获取消息扩展
* @function
* @private
* @example
* let promise = messageModel.getMessageExtensions();
* promise.then((chatResponse) => {
* // 消息扩展信息
* const { extensions } = chatResponse.data;
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
getMessageExtensions(): Promise<any>;
/**
* 获取信令信息
* @function
* @example
* let signaling = messageModel.getSignalingInfo();
* // signaling != null 说明是信令消息,可以进行信令相关的业务逻辑处理
* // signaling = null 说明是非信令消息
* if (signaling) {
* console.log(signaling)
* }
*/
getSignalingInfo(): Record<string, any> | null;
/**
* 获取消息展示内容 <br/>
* 注意1:以下解析为默认解析行为,如果需要自定义解析,可以通过 messageModel 结构体内容自行解析。<br/>
* 注意2:该接口不支持群系统消息解析。<br/>
* 注意3:群提示消息不支持返回 showName。<br/>
* 注意4:showName 显示优先级如下:
* - 单聊:remark > nick > userID
* - 群聊:remark > nameCard > nick > userID
* @function
* @example
* // 文本消息返回结果
* const result = messageModel.getMessageContent();
* // result.showName - 消息发送方名称
* // result.text - 文本消息展示内容
* // result.name - 文本消息名称,值为 text 或 img, 返回 img 时标识是 emoji 表情消息
* // result.type - 文本消息类型,自定义 emoji 表情消息时返回 customUIKit 默认的 emoji 表情和普通文本消息不返回 type 字段(v2.2.0 起支持)
* // result.emojiKey - emoji 表情的 keyv2.2.0 起支持)
* // result.src - emoji 表情消息展示链接,type = custom 时返回空字符串,需要 UIKit 层根据 baseUrl 和 emojiKey 拼接完整链接
* @example
* // 表情消息返回结果
* const result = messageModel.getMessageContent();
* // result.showName - 消息发送方名称
* // result.name - 表情消息名称
* // retsult.type - 表情消息类型,自定义 face 表情消息时返回 customUIKit 默认 face 表情包 type 返回 ‘’(v2.2.0 起支持)
* // result.url - 表情消息展示链接,type = custom 时返回空字符串,需要 UIKit 层根据 baseUrl 和 name 拼接完整链接
* @example
* // 地理位置消息返回结果
* const result = messageModel.getMessageContent();
* // result.showName - 消息发送方名称
* // result.lon - 经度
* // result.lat - 纬度
* // result.href - 地图跳转链接
* // result.url - 地图展示链接
* // result.description - 描述信息
* @example
* // 图片消息返回结果,默认返回的是原图信息,如果需要缩略图或大图信息请从 messageModel.payload 中获取
* const result = messageModel.getMessageContent();
* // result.showName - 消息发送方名称
* // result.url - 图片访问链接
* // result.width - 图片宽度
* // result.width - 图片高度
* @example
* // 语音消息返回结果
* const result = messageModel.getMessageContent();
* // result.showName - 消息发送方名称
* // result.url - 语音播放链接
* // result.second - 语音时长
* @example
* // 视频消息返回结果
* const result = messageModel.getMessageContent();
* // result.showName - 消息发送方名称
* // result.url - 视频播放链接
* // result.snapshotUrl - 视频封面图链接
* // result.snapshotWidth - 视频封面图宽度
* // result.snapshotHeight - 视频封面图高度
* @example
* // 文件消息返回结果
* const result = messageModel.getMessageContent();
* // result.showName - 消息发送方名称
* // result.url - 文件下载链接
* // result.name - 文件名称
* // result.size - 文件大小
* @example
* // 自定义消息返回结果
* const result = messageModel.getMessageContent();
* // result.showName - 消息发送方名称
* // result.custom - 自定义消息展示内容
* // result.businessID - 业务标识信息,创建群组自定义消息的 businessID 是 group_create,其他的自定义消息返回为空字符串
* @example
* // 合并消息返回结果
* const result = messageModel.getMessageContent();
* // result.showName - 消息发送方名称
* // 合并消息返回内容是 message.payload 内容
* @example
* // 群提示消息返回结果
* const result = messageModel.getMessageContent();
* // result.text - 群提示消息展示内容
*/
getMessageContent(): Record<string, any>;
}
@@ -0,0 +1,7 @@
export * from './tui-conversation';
export * from './tui-chat';
export * from './message-handler';
export * from './tui-group';
export * from './tui-user';
export * from './tui-report';
@@ -0,0 +1,46 @@
import type { Message } from '@tencentcloud/lite-chat/basic';
// message handler 因为需要在 MessageModel 中调用,需要保留声明文件
export interface IMessageHandler {
/**
* 处理文本消息
* @param {Message} message 文本消息
*/
handleTextMessage(message: Message): object;
/**
* 处理图片消息
* @param {Message} message 图片消息
*/
handleImageMessage(message: Message): object;
/**
* 处理视频消息
* @param {Message} message 视频消息
*/
handleVideoMessage(message: Message): object;
/**
* 处理自定义消息
* @param {Message} message 自定义消息
*/
handleCustomMessage(message: Message): object;
/**
* 处理群提示消息
* @param {Message} message 群 tips 消息
*/
handleGroupTipsMessage(message: Message): object;
/**
* 处理群系统消息
* @param {Message} message 群系统消息
*/
handleGroupSystemMessage(message: Message): object;
/**
* 处理音视频通话信令
* @param {any} message 会话最后一条消息或漫游消息
*/
handleCallKitSignaling(message: any): string | undefined;
}
@@ -0,0 +1,212 @@
import type { Message } from '@tencentcloud/lite-chat/basic';
import type TUIBase from '../../tui-base';
import type {
SendMessageParams,
GetMessageListParams,
SendMessageOptions,
GetMessageListHoppingParams,
} from '../../type';
import type { IMessageHandler } from './message-handler';
/**
* @interface TUIChatService
*/
export interface ITUIChatService extends TUIBase {
messageHandler: IMessageHandler;
/**
* 初始化 Service
* @function
* @private
*/
init: () => void;
/**
* 更新 store 里的 messageList
* @param messageList 要进行更新的 messageList
* @param type 更新类型
* @private
*/
updateMessageList(messageList: Message[], type: string): void;
/**
* 发送文本消息
* @function
* @param {SendMessageParams} options 文本消息相关参数
* @param {SendMessageOptions}[sendMessageOptions] 消息发送选项
* @example
* // 发送普通文本消息
* let promise = TUIChatService.sendTextMessage({
* payload: {
* text: 'Hello world!'
* },
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
* @example
* // 发送普通文本消息并携带消息自定义数据
* let promise = TUIChatService.sendTextMessage({
* payload: {
* text: 'Hello world!'
* },
* cloudCustomData: 'your cloud custom data'
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
sendTextMessage(
options: SendMessageParams,
sendMessageOptions?: SendMessageOptions,
): Promise<any>;
/**
* 发送附带 @ 提醒功能的文本消息
* @function
* @param {SendMessageParams} options 附带 @ 提醒功能的文本消息相关参数
* @param {SendMessageOptions}[sendMessageOptions] 消息发送选项
* @example
* // 发送 @ 消息
* let promise = TUIChatService.sendTextAtMessage({
* payload: {
* text: '@denny @lucy @所有人 今晚聚餐,收到的请回复1',
* atUserList: ['denny', 'lucy', TUIChatEngine.TYPES.MSG_AT_ALL] // 'denny' 'lucy' 都是 userID,而非昵称
* },
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
sendTextAtMessage(
options: SendMessageParams,
sendMessageOptions?: SendMessageOptions,
): Promise<any>;
/**
* 发送图片消息
* @function
* @param {SendMessageParams} options 图片消息相关参数
* @param {SendMessageOptions}[sendMessageOptions] 消息发送选项
* @example
* // 发送图片消息
* let promise = TUIChatService.sendImageMessage({
* payload: {
* file: file
* },
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
sendImageMessage(
options: SendMessageParams,
sendMessageOptions?: SendMessageOptions,
): Promise<any>;
/**
* 发送音频消息
* @function
* @param {SendMessageParams} options 音频消息相关参数
* @param {SendMessageOptions}[sendMessageOptions] 消息发送选项
* @example
* // 发送音频消息
* let promise = TUIChatService.sendAudioMessage({
* payload: {
* file: file
* },
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
sendAudioMessage(
options: SendMessageParams,
sendMessageOptions?: SendMessageOptions,
): Promise<any>;
/**
* 发送视频消息
* @function
* @param {SendMessageParams} options 视频消息相关参数
* @param {SendMessageOptions}[sendMessageOptions] 消息发送选项
* @example
* // 发送视频消息
* let promise = TUIChatService.sendVideoMessage({
* payload: {
* file: file
* },
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
sendVideoMessage(
options: SendMessageParams,
sendMessageOptions?: SendMessageOptions,
): Promise<any>;
/**
* 发送自定义消息
* @function
* @param {SendMessageParams} options 自定义消息相关参数
* @param {SendMessageOptions}[sendMessageOptions] 消息发送选项
* @example
* // 发送自定义消息
* let promise = TUIChatService.sendCustomMessage({
* payload: {
* data: 'dice', // 用于标识该消息是骰子类型消息
* description: String(random(1,6)), // 获取骰子点数
* extension: ''
* },
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
sendCustomMessage(
options: SendMessageParams,
sendMessageOptions?: SendMessageOptions,
): Promise<any>;
/**
* 重发消息的接口,当消息发送失败时,可调用该接口进行重发
* @function
* @param {Message} message 需要重发的消息对象
* @private
*/
resendMessage(message: Message): Promise<any>;
/**
* 分页拉取指定会话的消息列表的接口,当用户进入会话首次渲染消息列表或者用户“下拉查看更多消息”时,需调用该接口。
* @function
* @param {GetMessageListParams} [options] 获取漫游消息参数
* @example
* let promise = TUIChatService.getMessageList();
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
getMessageList(options?: GetMessageListParams): Promise<any>;
/**
* 根据指定的消息 sequence 或 消息时间拉取会话的消息列表
* @function
* @param {GetMessageListHoppingParams} options 消息实例
* @private
*/
getMessageListHopping(options?: GetMessageListHoppingParams): Promise<any>;
/**
* 清空单聊或群聊本地及云端的消息(不删除会话)
* @function
* @param {conversationID} string 会话 ID
* @example
* // 清空群聊 groupID 为 test 的历史消息
* let promise = TUIChatService.clearHistoryMessage('GROUPtest');
* promise.then((chatResponse) => {
* const { result } = chatResponse.data;
* });
*/
clearHistoryMessage(conversationID: string): Promise<any>;
}
@@ -0,0 +1,71 @@
import type { PinConversationParams, MuteConversationParams, SetConversationDraftParams, MarkConversationParams, DeleteConversationParams } from '../../type';
/**
* @interface TUIConversationService
*/
export interface ITUIConversationService {
/**
* 初始化 Service
* @private
*/
init(): void;
/**
* 切换会话
* @function
* @param {String} conversationID 会话 IDconversationID 生成规则:单聊(`C2C${userID}`),群聊(`GROUP${groupID}`)。
* @example
* // 切换到 public001 群会话
* let promise = TUIConversationService.switchConversation('GROUPpublic001');
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
switchConversation(conversationID: string): Promise<any>;
/**
* 获取会话列表
* @function
* @private
*/
getConversationList(): Promise<any>;
/**
* 获取会话资料
* 注意:Service API 主要用于跨组件时调用
* @function
* @param {String} conversationID 会话 ID
* @example
* // 获取 public001 群会话资料
* let promise = TUIConversationService.getConversationProfile('GROUPpublic001');
* promise.then((chatResponse) => {
* console.log(chatResponse.data.conversation); // 会话资料
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
getConversationProfile(conversationID: string): Promise<any>;
/**
* 设置会话已读上报
* @function
* @param {String} conversationID 会话 ID
* @example
* let promise = TUIConversationService.setMessageRead('GROUPpublic001');
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
setMessageRead(conversationID: string): Promise<any>;
/**
* 一键清空历史消息
* @function
* @param {String} conversationID 会话 ID
* @example
* @private
*/
clearHistoryMessage(conversationID: string): Promise<any>;
}
@@ -0,0 +1,528 @@
import type {
AddMemberParams,
ChangGroupOwnerParams,
CountersParams,
CreateGroupParams,
DeleteMemberParams,
GetGroupProfileParams,
GetMemberListParams,
GetMemberProfileParams,
GroupAttrParams,
JoinGroupParams,
KeyListParams,
MarkMemberParams,
SetCountersParams,
SetMemberCustomFiledParams,
SetMemberMuteParams,
SetMemberNameCardParams,
SetMemberRoleParams,
UpdateGroupParams,
handleGroupApplicationParams,
} from '../../type';
/**
* @interface TUIGroupService
*/
export interface ITUIGroupService {
/**
* 初始化 Service
* @function
* @private
*/
init(): void;
/**
* 切换群组
* @function
* @param {String} groupID 群组ID
* @example
* // 切换到 group1 群
* let promise = TUIGroupService.switchGroup('group1');
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
switchGroup(groupID: string): void;
/**
* 获取群详细资料
* @function
* @param {GetGroupProfileParams} options 获取群详细资料参数
* @example
* let promise = TUIGroupService.getGroupProfile({
* groupID: 'group1',
* groupCustomFieldFilter: ['key1','key2']
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
getGroupProfile(options: GetGroupProfileParams): Promise<any>;
/**
* 更新群详细资料
* @function
* @param {UpdateGroupParams} options 更新群详细资料参数
* @example
* let promise = TUIGroupService.updateGroupProfile({
* groupID: 'group1',
* name: 'new name', // 修改群名称
* introduction: 'this is introduction.', // 修改群简介
* groupCustomField: [{ key: 'group_level', value: 'high'}] // 修改群组维度自定义字段
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
* @example
* let promise = TUIGroupService.updateGroupProfile({
* groupID: 'group1',
* muteAllMembers: true, // true 表示全体禁言,false表示取消全体禁言
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
updateGroupProfile(options: UpdateGroupParams): Promise<any>;
/**
* 创建群组
* @function
* @param {CreateGroupParams} options 创建群组参数
* @example
* let promise = TUIGroupService.createGroup({
* type: TUIChatEngine.TYPES.GRP_WORK,
* name: 'newGroup',
* memberList: [{
* userID: 'user1',
* // 群成员维度的自定义字段,默认情况是没有的,需要开通,详情请参阅自定义字段
* memberCustomField: [{key: 'group_member_test', value: 'test'}]
* }, {
* userID: 'user2'
* }] // 如果填写了 memberList,则必须填写 userID
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
createGroup(options: CreateGroupParams): Promise<any>;
/**
* 解散群组
* @function
* @param {string} groupID 群组ID
* @example
* let promise = TUIGroupService.dismissGroup('group1');
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
dismissGroup(groupID: string): Promise<any>;
/**
* 通过 groupID 搜索群组
* @function
* @param {string} groupID 群组ID
* @example
* let promise = TUIGroupService.searchGroupByID('group1');
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
searchGroupByID(groupID: string): Promise<any>;
/**
* 申请加群
* @function
* @param {JoinGroupParams} options 加群参数
* @example
* let promise = TUIGroupService.joinGroup({
* groupID: 'group1',
* applyMessage: 'xxxx'
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
joinGroup(options: JoinGroupParams): Promise<any>;
/**
* 退出群组
* @function
* @param {string} groupID 群组ID
* @example
* let promise = TUIGroupService.quitGroup('group1');
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
quitGroup(groupID: string): Promise<any>;
/**
* 获取加群申请和邀请进群申请列表
* @function
* @example
* let promise = TUIGroupService.getGroupApplicationList();
* promise.then(function(chatResponse) {
* const { applicationList } = chatResponse.data;
* applicationList.forEach((item) => {
* // item.applicant - 申请者 userID
* // item.applicantNick - 申请者昵称
* // item.groupID - 群 ID
* // item.groupName - 群名称
* // item.applicationType - 申请类型:0 加群申请,2 邀请进群申请
* // item.userID - applicationType = 2 时,是被邀请人的 userID
* // 接入侧可调用 handleGroupApplication 接口同意或拒绝加群申请
* TUIGroupService.handleGroupApplication({
* handleAction: 'Agree',
* application: {...item},
* });
* });
* }).catch(function(imError) {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
getGroupApplicationList(): Promise<any>;
/**
* 处理加群申请和邀请进群申请
* @function
* @param {handleGroupApplicationParams} options 处理申请加群参数
* @example
* // 通过获取未决列表处理加群申请
* let promise = TUIGroupService.getGroupApplicationList();
* promise.then(function(chatResponse) {
* const { applicationList } = chatResponse.data;
* applicationList.forEach((item) => {
* if (item.applicationType === 0) {
* TUIGroupService.handleGroupApplication({
* handleAction: 'Agree',
* application: {...item},
* });
* }
* });
* }).catch(function(imError) {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
* @example
* // 通过获取未决列表处理邀请进群申请
* let promise = TUIGroupService.getGroupApplicationList();
* promise.then(function(chatResponse) {
* const { applicationList } = chatResponse.data;
* applicationList.forEach((item) => {
* if (item.applicationType === 2) {
* TUIGroupService.handleGroupApplication({
* handleAction: 'Agree',
* application: {...item},
* });
* }
* });
* }).catch(function(imError) {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
handleGroupApplication(options: handleGroupApplicationParams): Promise<any>;
/**
* 获取群在线人数
* - 注意:仅支持获取直播群在线人数
* @function
* @param {string} groupID 群组ID
* @example
* let promise = TUIGroupService.getGroupOnlineMemberCount('group1');
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
getGroupOnlineMemberCount(groupID: string): Promise<any>;
/**
* 转让群组
* @function
* @param {ChangGroupOwnerParams} options 群资料信息
* @example
* let promise = TUIGroupService.changeGroupOwner({
* groupID: 'group1',
* newOwnerID: 'user2'
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
changeGroupOwner(options: ChangGroupOwnerParams): Promise<any>;
/**
* 初始化群属性
* @function
* @param {GroupAttrParams} groupAttributes 群属性信息
* @example
* let promise = TUIGroupService.initGroupAttributes({
* groupID: 'group1',
* groupAttributes: { key1: 'value1', key2: 'value2' }
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
initGroupAttributes(groupAttributes: GroupAttrParams): Promise<any>;
/**
* 设置群属性
* @function
* @param {GroupAttrParams} groupAttributes 群属性信息
* @example
* let promise = TUIGroupService.setGroupAttributes({
* groupID: 'group1',
* groupAttributes: { key1: 'value1', key2: 'value2' }
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
setGroupAttributes(groupAttributes: GroupAttrParams): Promise<any>;
/**
* 删除群属性
* @function
* @param {KeyListParams} options 群属性参数
* @example
* let promise = TUIGroupService.deleteGroupAttributes({
* groupID: 'group1',
* keyList: ['key1', 'key2']
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
deleteGroupAttributes(options: KeyListParams): Promise<any>;
/**
* 获取群属性
* @function
* @param {KeyListParams} options 群属性参数
* @example
* let promise = TUIGroupService.getGroupAttributes({
* groupID: 'group1',
* keyList: ['key1', 'key2']
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
getGroupAttributes(options: KeyListParams): Promise<any>;
/**
* 设置计数器
* @function
* @param {SetCountersParams} counters 计数器信息
* @example
* let promise = TUIGroupService.setGroupCounters({
* groupID: 'group1',
* counters: { key1: 1, key2: 2 }
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
setGroupCounters(counters: SetCountersParams): Promise<any>;
/**
* 递增计数器
* @function
* @param {CountersParams} options 计数器信息
* @example
* let promise = TUIGroupService.increaseGroupCounter({
* groupID: 'group1',
* key: 'key1',
* value: 1,
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
increaseGroupCounter(options: CountersParams): Promise<any>;
/**
* 递减计数器
* @function
* @param {CountersParams} options 计数器信息
* @example
* let promise = TUIGroupService.decreaseGroupCounter({
* groupID: 'group1',
* key: 'key1',
* value: 2,
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
decreaseGroupCounter(options: CountersParams): Promise<any>;
/**
* 获取计数器
* @function
* @param {KeyListParams} options 计数器参数
* @example
* let promise = TUIGroupService.getGroupCounters({
* groupID: 'group1',
* keyList: ['key1', 'key2']
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
getGroupCounters(options: KeyListParams): Promise<any>;
// group member
/**
* 获取群成员列表
* @function
* @param {GetMemberListParams} options 参数选项
* @example
* let promise = TUIGroupService.getGroupMemberList({
* groupID: 'group1',
* count: 15,
* offset: 0
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
getGroupMemberList(options: GetMemberListParams): Promise<any>;
/**
* 获取群成员资料
* @function
* @param {GetMemberProfileParams} options 参数选项
* @example
* let promise = TUIGroupService.getGroupMemberProfile({
* groupID: 'group1',
* userIDList: ['user1', 'user2'], // 请注意:即使只拉取一个群成员的资料,也需要用数组类型,例如:userIDList: ['user1']
* memberCustomFieldFilter: ['group_member_custom'], // 筛选群成员自定义字段:group_member_custom
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
getGroupMemberProfile(options: GetMemberProfileParams): Promise<any>;
/**
* 邀请群成员
* @function
* @param {AddMemberParams} options 参数选项
* @example
* let promise = TUIGroupService.addGroupMember({
* groupID: 'group1',
* userIDList: ['user1','user2','user3']
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
addGroupMember(options: AddMemberParams): Promise<any>;
/**
* 删除群成员,群主可移除群成员。
* - 注意1:旗舰版套餐包支持删除直播群群成员。您可以通过调用此接口实现直播群【封禁群成员】的效果。
* - 注意2:踢出时长字段仅直播群(AVChatRoom)支持。
* - 注意3:群成员被移除出直播群后,在【踢出时长内】如果用户想再次进群,需要 APP 管理员调用 restapi 解封。过了【踢出时长】,用户可再次主动加入直播群。
* @function
* @param {DeleteMemberParams} options 参数选项
* @example
* let promise = TUIGroupService.deleteGroupMember({
* groupID: 'group1',
* userIDList: ['user1'],
* reason: '你违规了,我要踢你!',
* duration: 60
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
deleteGroupMember(options: DeleteMemberParams): Promise<any>;
/**
* 设置群成员禁言
* @function
* @param {SetMemberMuteParams} options 参数选项
* @example
* let promise = TUIGroupService.setGroupMemberMuteTime({
* groupID: 'group1',
* userID: 'user1',
* muteTime: 600 // 禁言10分钟;设为0,则表示取消禁言
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
setGroupMemberMuteTime(options: SetMemberMuteParams): Promise<any>;
/**
* 设置群成员角色
* @function
* @param {SetMemberRoleParams} options 参数选项
* @example
* let promise = TUIGroupService.setGroupMemberRole({
* groupID: 'group1',
* userID: 'user1',
* role: TUIChatEngine.TYPES.GRP_MBR_ROLE_ADMIN
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
setGroupMemberRole(options: SetMemberRoleParams): Promise<any>;
/**
* 设置群成员名片
* - 注意1:群主可设置所有群成员的名片。
* - 注意2: 群管理员可设置自身和其他普通群成员的群名片。
* - 注意3:普通群成员只能设置自身群名片。
* @function
* @param {SetMemberNameCardParams} options 参数选项
* @example
* let promise = TUIGroupService.setGroupMemberNameCard({
* groupID: 'group1',
* userID: 'user1',
* nameCard: '用户名片'
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
setGroupMemberNameCard(options: SetMemberNameCardParams): Promise<any>;
/**
* 设置群成员自定义字段
* @function
* @param {SetMemberCustomFiledParams} options 参数选项
* @example
* let promise = TUIGroupService.setGroupMemberCustomField({
* groupID: 'group1',
* memberCustomField: [{key: 'group_member_test', value: 'test'}]
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
setGroupMemberCustomField(options: SetMemberCustomFiledParams): Promise<any>;
/**
* 标记群成员
* - 注意1:仅支持直播群。
* - 注意2:只有群主才有权限标记群组中其他成员。
* - 注意3:使用该接口需要您购买旗舰版套餐。
* @function
* @param {MarkMemberParams} options 参数选项
* @example
* let promise = TUIGroupService.markGroupMemberList({
* groupID: 'group1',
* userIDList: ['user1', 'user2'],
* markType: 1000,
* enableMark: true,
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
markGroupMemberList(options: MarkMemberParams): Promise<any>;
}
@@ -0,0 +1,11 @@
/**
* @interface TUITranslateService
*/
export interface ITUIReportService {
/**
* Report key feature usage for analytics
* @param code - Event code for analytics
* @param feature - Feature name or identifier
*/
reportFeature(code: number, feature?: string): void;
}
@@ -0,0 +1,49 @@
import type TUIBase from '../../tui-base';
import type { SwitchUserStatusParams, UserIDListParams, UpdateMyProfileParams } from '../../type';
/**
* @interface TUIUserService
*/
export interface ITUIUserService extends TUIBase {
/**
* 初始化 Service
* @function
* @private
*/
init(): void;
/**
* 获取用户资料
* @function
* @param {UserIDListParams} options [options = undefined] 用户 ID 列表,不传 options 默认查询自己的资料
* @example
* // 查询自己的资料
* let promise = TUIUserService.getUserProfile();
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
* @example
* // 查询其他用户的资料
* let promise = TUIUserService.getUserProfile({ userIDList: ['user1', 'user2'] });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
getUserProfile(options?: UserIDListParams): Promise<any>;
/**
* 更新自己的资料信息
* @function
* @param {UpdateMyProfileParams} options 参数选项
* @example
* // 更新自己的昵称
* let promise = TUIUserService.updateMyProfile({
* nick: 'newNick'
* });
* promise.catch((error) => {
* // 调用异常时业务侧可以通过 promise.catch 捕获异常进行错误处理
* });
*/
updateMyProfile(options: UpdateMyProfileParams): Promise<any>;
}
@@ -0,0 +1,47 @@
export interface ITasks {
sendMessage: boolean; // 发送一条消息
revokeMessage: boolean; // 撤回一条消息
modifyNickName: boolean; // 修改一次我的昵称
groupChat: boolean; // 发起一个群聊
muteGroup: boolean; // 开启一次群禁言
dismissGroup: boolean; // 解散一个群聊
call: boolean; // 发起一次通话
searchCloudMessage: boolean; // 进行一次消息云端搜索
customerService: boolean; // 进行一次客服会话
translateTextMessage: boolean; // 进行一次文本消息翻译
}
export interface IAppStore {
store: {
enabledMessageReadReceipt: boolean; // 消息已读回执功能是否已开启
enabledEmojiPlugin: boolean; // 表情回复插件能力是否已开启
enabledOnlineStatus: boolean; // 用户在线状态能力是否已开启
enabledCustomerServicePlugin: boolean; // 客服插件能力是否已开启
enabledTranslationPlugin: boolean; // 文本消息翻译能力是否已开启
enabledVoiceToText: boolean; // 语音转文字能力是否已开启
enableTyping: boolean; // 正在输入能力开关
enableConversationDraft: boolean; // 会话草稿能力开关
enableAutoMessageRead: boolean; // 接收消息自动已读上报能力开关
isOfficial: boolean; // 是否是官网 SDKAppID
SDKVersion: string; // Chat SDK 版本号
tasks: ITasks; // sample demo 任务列表
};
/**
* 更新 store
* @param {Sting} key 待更新的 key
* @param {any} data 更新的数据
*/
update(key: string, data: any): void;
/**
* 从 store 中获取数据
* @param {Sting} key 需要获取的 key
*/
getData(key: string): any;
/**
* reset Store 内数据
* @param { Array<string>} keyList 需要 reset 的 keyList
*/
reset(keyList?: string[]): void;
}
@@ -0,0 +1,47 @@
import type { Message } from '@tencentcloud/lite-chat/basic';
import type { IMessageModel } from '../model';
interface ITextInfo {
messageID: string;
visible: boolean;
}
export interface IChatStore {
store: {
messageList: IMessageModel[];
isCompleted: boolean;
nextReqMessageID: string;
quoteMessage: Message | any;
typingStatus: boolean;
messageSource: IMessageModel | undefined;
newMessageList: Message[];
translateTextInfo: Map<string, ITextInfo[]> | undefined;
voiceToTextInfo: Map<string, ITextInfo[]> | undefined;
userInfo: Record<string, any>;
};
/**
* 更新 store
* @param {Sting} key 待更新的 key
* @param {any} data 更新的数据
*/
update(key: string, data: any): void;
/**
* 从 store 中获取数据
* @param {Sting} key 需要获取的 key
*/
getData(key: string): any;
/**
* 从 messageList 中获取 messageModel
* @param {Sting} id 需要获取的 messageID
*/
getModel(id: string): any;
/**
* reset Store 内数据
* @param { Array<string>} keyList 需要 reset 的 keyList
*/
reset(keyList?: string[]): void;
}
@@ -0,0 +1,35 @@
import type { IConversationModel } from '../model';
export interface IConversationStore {
store: {
currentConversationID: string;
currentConversation: IConversationModel | null;
totalUnreadCount: number;
conversationList: IConversationModel[];
};
/**
* 更新 store
* @param {Sting} key 待更新的 key
* @param {any} data 更新的数据
*/
update(key: string, data: any): void;
/**
* 从 store 中获取数据
* @param {Sting} key 需要获取的 key
*/
getData(key: string): any;
/**
* 从 conversationList 中获取 conversationModel
* @param {Sting} conversationID 需要获取的会话 ID
*/
getModel(id: string): any;
/**
* reset Store 内数据
* @param { Array<string>} keyList 需要 reset 的 keyList
*/
reset(keyList?: string[]): void;
}
@@ -0,0 +1,23 @@
export interface ICustomStore {
store: any; // 自定义 store,属性可根据需要进行自定义
/**
* 更新自定义 store
* @param {Sting} key 待更新的 key,没有则写入
* @param {any} value 待更新的数据
*/
update(key: string, value: any): void;
/**
* 从自定义 store 中获取数据
* @param {Sting} store store 的名称
* @param {Sting} key 待获取的 key
*/
getData(key: string): any;
/**
* reset Store 内数据
* @param { Array<string>} keyList 需要 reset 的 keyList
*/
reset(keyList?: string[]): void;
}
@@ -0,0 +1,29 @@
import type { Friend, FriendApplication, FriendGroup } from '../../type';
export interface IFriendStore {
store: {
friendList: Friend[];
friendApplicationList: FriendApplication[];
friendApplicationUnreadCount: number; // 好友申请的未读数
friendGroupList: FriendGroup[];
};
/**
* 更新 store
* @param {Sting} key 待更新的 key
* @param {any} data 更新的数据
*/
update(key: string, data: any): void;
/**
* 从 store 中获取数据
* @param {Sting} key 需要获取的 key
*/
getData(key: string): any;
/**
* reset Store 内数据
* @param { Array<string>} keyList 需要 reset 的 keyList
*/
reset(keyList?: string[]): void;
}
@@ -0,0 +1,46 @@
import type { Message } from '@tencentcloud/lite-chat/basic';
import type { IGroupModel } from '../model';
export interface GroupMember {
userID: string;
avatar: string;
nick: string;
role: string;
joinTime: number;
nameCard: string;
muteUntil: number;
memberCustomField: Record<string, any>[];
}
export interface IGroupStore {
store: {
currentGroupID: string;
currentGroup: IGroupModel | undefined;
currentGroupMemberList: GroupMember[];
currentGroupAttributes: Record<string, any>;
currentGroupCounters: Record<string, number>;
groupList: IGroupModel[];
groupSystemNoticeList: Message[];
isCompleted: boolean;
offset: number | string;
};
/**
* 更新 store
* @param {Sting} key 待更新的 key
* @param {any} data 更新的数据
*/
update(key: string, data: any): void;
/**
* 从 store 中获取数据
* @param {Sting} key 需要获取的 key
*/
getData(key: string): any;
/**
* reset Store 内数据
* @param { Array<string>} keyList 需要 reset 的 keyList
*/
reset(keyList?: string[]): void;
}
@@ -0,0 +1,9 @@
export * from './tui-store';
export * from './user';
export * from './conversation';
export * from './chat';
export * from './group';
export * from './custom';
export * from './friend';
export * from './app';
export * from './search';
@@ -0,0 +1,37 @@
import type { ISearchParamsMap, ISearchResult, ISearchType } from '../../type';
export interface ISearchStoreStore {
searchMessagesResult: ISearchResult<ISearchType.MESSAGE>;
searchChatMessagesResult: ISearchResult<ISearchType.MESSAGE>;
searchUserResult: ISearchResult<ISearchType.USER>;
searchGroupResult: ISearchResult<ISearchType.GROUP>;
searchMessageParams: ISearchParamsMap[ISearchType.MESSAGE];
searchChatMessageParams: ISearchParamsMap[ISearchType.MESSAGE];
searchUserParams: ISearchParamsMap[ISearchType.USER];
searchGroupParams: ISearchParamsMap[ISearchType.GROUP];
error: Error | null;
[key: string]: any;
}
export interface ISearchStore {
store: ISearchStoreStore;
/**
* 更新 store
* @param {Sting} key 待更新的 key
* @param {any} data 更新的数据
*/
update(key: string, data: any): void;
/**
* 从 store 中获取数据
* @param {Sting} key 需要获取的 key
*/
getData(key: string): any;
/**
* reset Store 内数据
* @param { Array<string>} keyList 需要 reset 的 keyList
*/
reset(keyList?: string[]): void;
}
@@ -0,0 +1,138 @@
/**
* @property {Boolean} enableTyping 正在输入功能是否开启,默认开启 true
* @property {Boolean} enabledMessageReadReceipt 消息已读回执功能是否已开启,默认 false,购买旗舰版套餐后开启
* @property {Boolean} enabledEmojiPlugin 表情回复插件能力是否已开启,默认 false,购买旗舰版套餐后开启
* @property {Boolean} enabledOnlineStatus 用户在线状态能力是否已开启,默认 false,购买旗舰版套餐后开启
* @property {Boolean} enabledCustomerServicePlugin 客服插件能力是否已开启,默认 false,购买客服插件后开启
* @property {Boolean} enabledTranslationPlugin 文本消息翻译能力是否已开启,默认 false,购买翻译插件后开启
* @property {Boolean} enableConversationDraft 会话草稿功能是否开启,默认开启 true
* @example
* // UI 层调用以下逻辑关闭正在输入功能
* TUIStore.update(StoreName.APP, 'enableTyping', false);
* @example
* // UI 层调用以下逻辑关闭会话草稿功能
* TUIStore.update(StoreName.APP, 'enableConversationDraft', false);
*/
export enum AppStore {}
/**
* @property {String} currentConversationID 当前会话ID
* @property {Array<IConversationModel>} conversationList 会话列表
* @property {Number} totalUnreadCount 会话未读总数
* @example
* // UI 层监听会话列表更新通知
* let onConversationListUpdated = function(conversationList) {
* console.warn(conversationList);
* }
* TUIStore.watch(StoreName.CONV, {
* conversationList: onConversationListUpdated,
* })
*/
export enum ConversationStore {}
/**
* @property {Array<IMessageModel>} messageList 消息列表
* @property {Boolean} isCompleted 漫游是否拉完(用于控制‘查看更多’按钮显示)
* @property {Message | any} quoteMessage 被引用的消息信息,引用消息时会触发更新
* @property {Boolean} typingStatus 正在输入的状态标识, 默认 false,开启正在输入状态后,输入消息时会触发更新
* @property {IMessageModel} messageSource 用于消息云端搜索结果跳转至指定消息标识
* @property {Array<Message>} newMessageList 新消息通知列表,提供给 TUINotification 组件使用
* @property {Record<string, string | undefined | boolean>} translateTextInfo 文本消息翻译信息
* @example
* // UI 层监听当前会话消息列表更新通知
* let onMessageListUpdated = function(messageList) {
* console.warn(messageList);
* }
* TUIStore.watch(StoreName.CHAT, {
* messageList: onMessageListUpdated,
* })
* @example
* // UI 层更新消息云端搜索结果跳转至指定消息标识
* TUIStore.update(StoreName.CHAT, 'messageSource', message);
* // UI 层监听消息云端搜索结果跳转至指定消息标识
* let onMessageSourceUpdated = function(message) {
* console.warn(message);
* }
* TUIStore.watch(StoreName.CHAT, {
* messageSource: onMessageSourceUpdated,
* })
* @example
* // UI 层更新文本消息翻译信息
* TUIStore.update(StoreName.CHAT, 'translateTextInfo', {
* conversationID: 'xxx',
* messageID: 'xxx',
* visible: false,
* });
* // UI 层监听文本消息翻译更新通知
* let onTranslateTextInfoUpdated = function(info) {
* // info 返回的是 map 或 undefined
* if (info) {
* const list = info.get('conversationID') || [];
* list.forEach(item => {
* const { messageID, visible } = item;
* // messageID - 当前操作的消息的 ID
* // visible - 是否显示翻译文本
* }
* }
* }
* TUIStore.watch(StoreName.CHAT, {
* translateTextInfo: onTranslateTextInfoUpdated,
* })
*/
export enum ChatStore {}
/**
* @property {String} currentGroupID 当前群组ID
* @property {Group} currentGroup 当前群组信息
* @property {Array} currentGroupMemberList 当前群组群成员列表
* @property {Object} currentGroupAttributes 当前群组群属性信息
* @property {Object} currentGroupCounters 当前群组计数器信息
* @property {Array<Group>} groupList 群组列表
* @property {Array<Message>} groupSystemNoticeList 群组系统通知列表(注意:Store 中不会存储群系统通知,即时通知)
* @example
* // UI 层监听群组列表更新通知
* let onGroupListUpdated = function(groupList) {
* console.warn(groupList);
* }
* TUIStore.watch(StoreName.GRP, {
* groupList: onGroupListUpdated,
* })
*/
export enum GroupStore {}
/**
* @property {Object} userProfile 当前登录用户的资料信息
* @property {Boolean} displayOnlineStatus 是否开启用户状态显示,默认 false:关闭
* @property {Boolean} displayMessageReadReceipt 是否开启消息阅读状态显示,默认 true:开启
* @property {String} kickedOut 用户被踢的类型信息
* @property {String} netStateChange 网络状态变更信息
* @property {Map<key, statusInfo>} userStatusList 订阅用户的状态信息的列表
* - key 用户 userID
* - statusInfo.statusType 用户当前状态
* - statusInfo.customStatus 用户自定义状态
* @property {Array<string>} userBlacklist 用户黑名单列表,UI 组件层可以通过监听该属性来获取用户黑名单列表
* @example
* // UI 层监听网络变更通知
* let onNetStateChange = function(state) {
* console.warn(state);
* }
* TUIStore.watch(StoreName.USER, {
* netStateChange: onNetStateChange,
* })
*/
export enum UserStore {}
/**
* @property {Array<Friend>} friendList 好友列表,UI 组件层可以通过监听该属性来获取好友列表
* @property {Array<FriendApplication>} friendApplicationList 好友申请列表,UI 组件层可以通过监听该属性来获取好友申请列表
* @property {number} friendApplicationUnreadCount 好友申请未读数,UI 组件层可以通过监听该属性来获取好友申请未读数
* @example
* // UI 层监听好友列表更新变更通知
* let onFriendListUpdated = function(friendList) {
* console.warn(friendList);
* }
* TUIStore.watch(StoreName.FRIEND, {
* friendList: onFriendListUpdated ,
* })
*/
export enum FriendStore {}
@@ -0,0 +1,102 @@
import type { StoreName } from '../../const';
import type { IConversationModel, IMessageModel } from '../model';
// 此处 Map 的 value = 1 为占位作用
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export type Task = Record<StoreName, Record<string, Map<(data?: unknown) => void, 1>>>;
export interface IOptions {
[key: string]: (newData?: any) => void;
}
// 自定义 store 暂不支持
// @property {ICustomStore} customStore 自定义 store,可根据业务需要通过以下 API 进行数据操作。
/**
* @class TUIStore
*/
export interface ITUIStore {
task: Task;
/**
* UI 组件注册监听
* @function
* @param {StoreName} storeName store 名称
* @param {IOptions} options UI 组件注册的监听信息
* @example
* // UI 层监听会话列表更新通知
* let onConversationListUpdated = function(conversationList) {
* console.warn(conversationList);
* }
* TUIStore.watch(StoreName.CONV, {
* conversationList: onConversationListUpdated,
* })
*/
watch(storeName: StoreName, options: IOptions): void;
/**
* UI 组件取消监听回调
* 注意:取消监听时传入的回调函数和注册监听的回调函数是同一个
* @function
* @param {StoreName} storeName store 名称
* @param {IOptions} options 监听信息,包含需要取消的回调等
* @example
* // UI 层取消监听会话列表更新通知
* TUIStore.unwatch(StoreName.CONV, {
* conversationList: onConversationListUpdated,
* })
*/
unwatch(storeName: StoreName, options: IOptions): void;
/**
* 更新 store
* - 使用自定义 store 时,可以用此 API 更新自定义数据
* @function
* @param {StoreName} storeName store 名称
* @param {String} key 需要更新的 key
* @param {any} data 待更新的数据
* @example
* // UI 层更新自定义 Store 数据
* const data: string = '自定义数据'
* TUIStore.update(StoreName.CUSTOM, 'customKey', data)
*/
update(storeName: StoreName, key: string, data: any): void;
/**
* 获取 store 中的数据
* @function
* @param {StoreName} storeName store 名称
* @param {String} key 需要获取的 key
* @private
*/
getData(storeName: StoreName, key: string): any;
/**
* 获取 conversationModel
* @function
* @param {string} conversationID 会话 ID
* @example
* // 获取 conversationModel
* const conversationID = 'C2C9241'
* const conversationModel = TUIStore.getConversationModel(conversationID);
*/
getConversationModel(conversationID: string): IConversationModel;
/**
* 获取 messageModel
* @function
* @param {string} messageID 消息 ID
* @example
* // 获取 messageModel
* const messageID = '144115225790497300-1686557023-31267600'
* const messageModel = TUIStore.getMessageModel(messageID);
*/
getMessageModel(messageID: string): IMessageModel;
/**
* 重置 store 内数据
* @function
* @param {StoreName} storeName store 名称
* @param {Array<string>} keyList 需要 reset 的 keyList
* @param {boolean} isNotificationNeeded 是否需要触发更新
* @private
*/
reset(storeName: StoreName, keyList?: string[], isNotificationNeeded?: boolean): void;
}
@@ -0,0 +1,34 @@
export interface IUserStore {
store: {
userProfile: object;
displayOnlineStatus: boolean; // 是否开启用户状态显示
displayMessageReadReceipt: boolean; // 是否开启消息阅读状态显示
userStatusList: Map<string, {
statusType: number;
customStatus: string;
}>; // 订阅用户的状态信息的列表
kickedOut: string; // 用户被踢的类型信息
netStateChange: string; // 网络状态变更信息
userBlacklist: any[]; // 用户黑名单列表
targetLanguage: string; // 文本消息翻译目标语言,内部使用
};
/**
* 更新 store
* @param {Sting} key 待更新的 key
* @param {any} data 更新的数据
*/
update(key: string, data: any): void;
/**
* 从 store 中获取数据
* @param {Sting} key 需要获取的 key
*/
getData(key: string): any;
/**
* reset Store 内数据
* @param { Array<string>} keyList 需要 reset 的 keyList
*/
reset(keyList?: any[]): void;
}