消息
<p>MessageEntity对象</p>
<pre><code class="language-java">static readonly MSG_STATUS_SENDING = 0; //发送中
static readonly MSG_STATUS_SEND_OK = 1; //发送成功
static readonly MSG_STATUS_SEND_FAILED = 2; //发送失败
static readonly MSG_STATUS_SEND_ACK = 3; //对方已读
static readonly MSG_STATUS_RECEIVE = 4; //接收
static readonly DIRECTOR_OUT = 0; //发送
static readonly DIRECTOR_IN = 1; //接收
static readonly MSG_UNREAD = 0; //未读
static readonly MSG_READ = 1; //已读
static readonly FILE_STATUS_UPLOADING = 0; //上传中
static readonly FILE_STATUS_UPLOADED = 1; //已上传
static readonly FILE_STATUS_UPLOAD_CANCEL = 2; //取消上传
static readonly FILE_STATUS_UPLOAD_FAILED = 3; //上传失败
static readonly FILE_STATUS_NOT_DOWNLOAD = 4; //未下载
static readonly FILE_STATUS_HAD_DOWNLOAD = 5; //已下载
static readonly FILE_STATUS_DOWNLOAD_FAILED = 6; //下载失败
static readonly FILE_STATUS_DOWNLOAD_CANCEL = 7; //下载取消
static readonly CTYPE_USER = 0; //单聊
static readonly CTYPE_GROUP = 1; //群聊
static readonly CTYPE_APP = 3; //应用
static readonly CTYPE_SECRET = 4; //密聊
static readonly MSG_TYPE_TEXT = &#039;text&#039;; //文本消息
static readonly MSG_TYPE_IMG = &#039;image&#039;; //图片消息
static readonly MSG_TYPE_FILE = &#039;file&#039;; //文件消息
static readonly MSG_TYPE_SHOOT = &#039;video&#039;; //小视频
static readonly MSG_TYPE_VOICE = &#039;audio&#039;; //语音消息
static readonly MSG_TYPE_LOCATION = &#039;location&#039;; //位置消息
static readonly MSG_TYPE_CANCEL = &#039;cancel&#039;; // 撤回消息
static readonly MSG_TYPE_NOTIFY = &#039;notify&#039;; //通知消息
static readonly MSG_TYPE_CONFIRMED = &#039;confirmed&#039;; //已签收
static readonly MSG_TYPE_FORMVIEW = &#039;formview&#039;; //formview消息
static readonly MSG_TYPE_CUSTOM = &#039;custom&#039;; //自定义消息
static readonly MSG_TYPE_MERGE = &#039;mergeforward&#039;; //合并消息
static readonly MSG_TYPE_CMD = &#039;cmd&#039;; // 命令型消息
static readonly MSG_TYPE_EMOTS = &#039;emots&#039;; //表情包消息
/**
* 会话id
*/
cid: string = &#039;&#039;;
/**
* 会话类型 0 单聊 1 群聊 3 应用 4 密聊
*/
ctype: number = MessageEntity.CTYPE_USER
/**
* 消息id
*/
msgId: string = &#039;&#039;;
/**
* 消息序号
*/
msgNum: number = 0;
/**
* 类型
*/
type: string = &#039;&#039;;
/**
* 标题
*/
subject: string = &#039;&#039;;
/**
* 标识
*/
flag: number = 0;
/**
* 发送者id
*/
senderId: string = &#039;&#039;;
/**
* 发送者名称
*/
senderName: string = &#039;&#039;;
/**
* 发送者头像
*/
senderAvatar: string = &#039;&#039;;
/**
* 接受者id
*/
receiverId: string = &#039;&#039;;
/**
* 接收者名称
*/
receiverName: string = &#039;&#039;;
/**
* 接收者头像
*/
receiverAvatar: string = &#039;&#039;;
/**
* 文本内容
*/
text: string = &#039;&#039;;
/**
* 通知内容
*/
content: string = &#039;&#039;;
/**
* 文件信息
*/
fileInfo: string = &#039;&#039;;
/**
* 文件id
*/
fileId: string = &#039;&#039;;
/**
* 文件名称
*/
fileName: string = &#039;&#039;;
/**
* 文件时长
*/
fileDuration: number = 0;
/**
* 文件本地路径
*/
filePath: string = &#039;&#039;;
/**
* 缩略图本地路径
*/
thumbFilePath: string = &#039;&#039;;
/**
* 额外数据
*/
extData: string = &#039;&#039;;
/**
* 发送状态 0 发送中 1 发送成功 2 发送失败 3 对方已读 4 接收对方的消息
*/
status: number = 0;
/**
* 文件上传状态 0 上传中 1 上传成功 2 上传取消 3 上传失败 4 未下载 5 已下载 6 下载失败 7 下载取消
*/
fileStatus: number = 0;
/**
* 发送时间
*/
sendTime: number = 0;
/**
* 点击时间(语音消息使用)
*/
clickTime: number = 0;
/**
* 阅读时间 (发送为对方时间 接收为自己打开的时间 密聊使用)
*/
readTime: number = 0;
/**
* 撤回时间
*/
cancelTime: number = 0;
/**
* 发送或者接收 0 发送 1 接收
*/
director: number = MessageEntity.DIRECTOR_OUT;
/**
* 是否已读 0 未读 1 已读
*/
isRead: number = MessageEntity.MSG_UNREAD;
/**
* 引用的消息id
*/
citeMsgId: string = &#039;&#039;;
/**
* 是否@自己
*/
isAtSelf: number = 0;
/**
* 发送者信息
*/
senderInfo: string = &#039;&#039;;
/**
* 接受者信息
*/
receiverInfo: string = &#039;&#039;;
/**
* 预留数据1
*/
extData1: string = &#039;&#039;;
/**
* 预留数据2
*/
extData2: string = &#039;&#039;;</code></pre>
<h1>接口</h1>
<p>创建消息</p>
<pre><code class="language-java">/**
* 创建文本消息
* @param chatId 对象id(用户Id或群组id)
* @param chatName 对象名称(用户姓名或群组姓名)
* @param chatAvatar 对象头像(用户头像或群组头像)
* @param content 文本内容
* @param isGroup 是否为群组
* @returns
*/
QDClient.getInstance().createTextMessage(chatId: string, chatName: string, chatAvatar: string, content: string, isGroup: boolean): MessageEntity
/**
* 创建@消息 (只支持群组)
* @param chatId 群组id
* @param chatName 群组名称
* @param chatAvatar 群组头像
* @param content 文本内容
* @param atInfo @成员的信息
* @returns
*/
QDClient.getInstance().createAtTextMessage(chatId: string, chatName: string, chatAvatar: string, content: string, atInfo: Array&lt;Record&lt;string, Object&gt;&gt;): MessageEntity
/**
* 创建签收消息(只支持个人)
* @param chatId 用户id
* @param chatName 用户名称
* @param chatAvatar 用户头像
* @param content 文本内容
* @returns
*/
QDClient.getInstance().createSignMessage(chatId: string, chatName: string, chatAvatar: string, content: string) : MessageEntity
/**
* 创建文件消息
* @param chatId 对象id(用户Id或群组id)
* @param chatName 对象名称(用户姓名或群组姓名)
* @param chatAvatar 对象头像(用户头像或群组头像)
* @param filePath 文件路径
* @param fileName 文件名称
* @param subject 消息标题
* @param msgType 消息类型(MessageEntity.MSG_TYPE_IMG 图片 MessageEntity.MSG_TYPE_FILE 文件)
* @param isGroup 是否为群组
* @returns
*/
QDClient.getInstance().createFileMessage(chatId: string, chatName: string, chatAvatar: string, filePath: string, fileName: string,subject: string, msgType: string, isGroup: boolean): MessageEntity
/**
* 创建小视频消息
* @param chatId 对象id(用户Id或群组id)
* @param chatName 对象名称(用户姓名或群组姓名)
* @param chatAvatar 对象头像(用户头像或群组头像)
* @param imgPath 第一帧图片路径
* @param filePath 文件路径
* @param fileName 文件名称
* @param duration 视频时长
* @param subject 消息标题
* @param isGroup 是否为群组
* @returns
*/
QDClient.getInstance().createVideoMessage(chatId: string, chatName: string, chatAvatar: string, imgPath: string, filePath: string, fileName: string, duration: number, subject: string, isGroup: boolean): MessageEntity
/**
* 创建自定义消息
* @param chatId 对象id(用户Id或群组id)
* @param chatName 对象名称(用户姓名或群组姓名)
* @param chatAvatar 对象头像(用户头像或群组头像)
* @param extData 自定义内容
* @param subject 消息标题
* @param isGroup 是否为群组
* @returns
*/
QDClient.getInstance().createCustomMessage(chatId: string, chatName: string, chatAvatar: string, extData: string, subject: string,isGroup: boolean): MessageEntity
/**
* 创建合并消息
* @param title 合并消息标题
* @param chatName 对象名称
* @param chatAvatar 对象头像
* @param messageList 合并的消息列表
* @returns
*/
QDClient.getInstance().createMergeMessage(title: string, chatName: string, chatAvatar: string,messageList: Array&lt;MessageEntity&gt;): MessageEntity
/**
* 创建转发消息
* @param chatId 对象id(用户Id或群组id)
* @param chatName 对象名称(用户姓名或群组姓名)
* @param chatAvatar 对象头像(用户头像或群组头像)
* @param message 转发的原消息对象
* @param isGroup 是否为群组
* @returns
*/
QDClient.getInstance().createForwardMessage(chatId: string, chatName: string, chatAvatar: string, message: MessageEntity,isGroup: boolean): MessageEntity
/**
* 创建转发文件消息
* @param fileInfo 文件上传成功之后返回的文件信息
* @param msgType 消息类型
* @param filePath 文件路径
* @returns
*/
QDClient.getInstance().createForwardPathMessage(fileInfo : string, msgType : string, filePath : string) : MessageEntity</code></pre>
<p>消息处理</p>
<pre><code class="language-java">/**
* 获取离线消息(登录完成之后需要主动去获取离线时收到的消息)
*/
QDClient.getInstance().fetchOfflineMsg() : void
/**
* 消息签收
* @param message 签收消息
*/
QDClient.getInstance().signMessage(message: MessageEntity) : void
/**
* 发送消息
* @param message 待发送的消息
* @param isGroup 是否为群组
*/
QDClient.getInstance().sendMessage(message: MessageEntity, isGroup: boolean) : void
/**
* 发送自定义消息
* @param chatId 对象id(用户Id或群组id)
* @param chatName 对象名称(用户姓名或群组姓名)
* @param chatAvatar 对象头像(用户头像或群组头像)
* @param opType 自定义消息类型(QDConst.CMD_SHAKE 抖一抖)
* @returns
*/
QDClient.getInstance().sendCmdMessage(chatId: string, chatName: string, chatAvatar: string, opType: string): MessageEntity
/**
* 设置消息已读
* @param msgNum 消息序号
* @param cid 会话id
*/
QDClient.getInstance().readMsgAck(msgNum: number, cid: string) : void
/**
* 设置群消息已读
* @param msgNum 消息序号
* @param groupId 群id
*/
QDClient.getInstance().readGMsgAck(msgNum: number, groupId: string) : void
/**
* 撤回消息
* @param message 撤回的消息
*/
QDClient.getInstance().revokeMessage(message: MessageEntity) : void
/**
* 销毁消息
* @param message 原消息
*/
QDClient.getInstance().destroyMessage(message: MessageEntity) : void </code></pre>
<h1>消息相关数据库操作</h1>
<pre><code class="language-java">/**
* 插入一条消息
* @param message
*/
MessageDao.insertMessage(message : MessageEntity) : void
/**
* 插入多条消息
* @param messageList
*/
MessageDao.insertMessageList(messageList : Array&lt;MessageEntity&gt;) : void
/**
* 更新消息发送状态
* @param msgId
* @param status
*/
MessageDao.updateMessageStatus(msgId : string, status : number) : void
/**
* 更新消息
* @param message
*/
MessageDao.updateMessage(message : MessageEntity) : void
/**
* 将消息转为撤回消息
* @param msgId
*/
MessageDao.updateMessageTypeToCancel(msgId : string, time : number) : void
/**
* 根据msgId获取消息
* @param msgId
* @returns
*/
MessageDao.getMessageByMsgId(msgId : string) : MessageEntity | undefined
/**
* 获取和人的最近一条未读消息
* @param userId
* @returns
*/
MessageDao.getLastUnreadMessageByUserId(userId : string) : MessageEntity | undefined
/**
* 获取和人的最近一条消息
* @param userId
* @returns
*/
MessageDao.getLastMessageByUserId(userId : string) : MessageEntity | undefined
/**
* 获取应用的最近一条消息
* @param appId
* @returns
*/
MessageDao.getLastMessageByAppId(appId : string) : MessageEntity | undefined
/**
* 获取和群组的最近一条未读消息
* @param groupId
* @returns
*/
MessageDao.getLaseUnreadMessageByGroupId(groupId : string) : MessageEntity | undefined
/**
* 获取和群组的最近一条消息
* @param groupId
* @returns
*/
MessageDao.getLaseMessageByGroupId(groupId : string) : MessageEntity | undefined
/**
* 获取和人的消息列表(最近20条)
* @param userId
* @returns
*/
MessageDao.getMessageListByUserId(userId : string, limit : number = 20) : Array&lt;MessageEntity&gt;
/**
* 获取和人的图片消息
* @param userId
* @returns
*/
MessageDao.getImageMessageListByUserId(userId : string) : Array&lt;MessageEntity&gt;
/**
* 获取小于指定时间的和人的最近消息
* @param userId
* @param time
* @param limit
* @returns
*/
MessageDao.getMessageListByUserIdBeforeTime(userId : string, time : number, limit : number = 20) : Array&lt;MessageEntity&gt;
/**
* 获取大于等于指定时间的和人的消息
* @param userId
* @param time
* @param limit
* @returns
*/
MessageDao.getMessageListByUserIdAfterTime(userId : string, time : number, limit : number = -1) : Array&lt;MessageEntity&gt;
/**
* 获取应用消息
* @param appId
* @returns
*/
MessageDao.getMessageListByAppId(appId : string, limit : number = 20) : Array&lt;MessageEntity&gt;
/**
* 获取小于指定时间的应用消息列表
* @param appId
* @param time
* @param limit
* @returns
*/
MessageDao.getMessageListByAppIdBeforeTime(appId : string, time : number, limit : number = 20) : Array&lt;MessageEntity&gt;
/**
* 获取和群组的消息列表(最近20条)
* @param groupId
* @returns
*/
MessageDao.getMessageListByGroupId(groupId : string, limit : number = 20) : Array&lt;MessageEntity&gt;
/**
* 获取和群组的图片消息
* @param groupId
* @returns
*/
MessageDao.getImageMessageListByGroupId(groupId : string)
/**
* 获取小于指定时间的最近消息列表(20条)
* @param groupId
* @param time
* @returns
*/
MessageDao.getMessageListByGroupIdBeforeTime(groupId : string, time : number, limit : number = 20) : Array&lt;MessageEntity&gt;
/**
* 获取大于等于指定时间的最近消息列表
* @param groupId
* @param time
* @param limit
* @returns
*/
MessageDao.getMessageListByGroupIdAfterTime(groupId : string, time : number, limit : number = -1) : Array&lt;MessageEntity&gt;
/**
* 获取文件传输的消息列表(最近20条)
* @returns
*/
MessageDao.getMessageListBySelfId(limit : number = 20) : Array&lt;MessageEntity&gt;
/**
* 获取文件传输的图片消息
* @returns
*/
MessageDao.getImageMessageListBySelfId() : Array&lt;MessageEntity&gt;
/**
* 获取小于指定时间的文件传输的消息列表
* @param time
* @param limit
* @returns
*/
MessageDao.getMessageListBySelfIdBeforeTime(time : number, limit : number = 20) : Array&lt;MessageEntity&gt;
/**
* 获取大于等于指定时间的文件传输的消息列表
* @param time
* @param limit
* @returns
*/
MessageDao.getMessageListBySelfIdAfterTime(time : number, limit : number = -1) : Array&lt;MessageEntity&gt;
/**
* 获取文件消息
* @returns
*/
MessageDao.getFileMessageList() : Array&lt;MessageEntity&gt;
/**
* 获取和人的消息未读数量
* @param userId
* @returns
*/
MessageDao.getUnreadCountByUserId(userId : string) : number
/**
* 获取和群组的消息未读数量
* @param groupId
* @returns
*/
MessageDao.getUnreadCountByGroupId(groupId : string) : number
/**
* 获取应用未读消息
* @param appId
* @returns
*/
MessageDao.getUnreadCountByAppId(appId : string) : number
/**
* 设置小于msgNum的消息对方已读
* @param userId
*/
MessageDao.setMessageSendAckByUserIdLessMsgNum(userId : string, msgNum : number) : void
/**
* 设置和人的所有消息已读
* @param userId
*/
MessageDao.setMessageReadByUserId(userId : string) : void
/**
* 设置所有文件传输消息已读
*/
MessageDao.setMessageReadBySelf() : void
/**
* 设置应用消息已读
* @param appId
*/
MessageDao.setMessageReadByAppId(appId : string) : void
/**
* 设置和群的所有消息已读
* @param groupId
*/
MessageDao.setMessageReadByGroupId(groupId : string) : void
/**
* 根据消息id删除消息
* @param msgId
*/
MessageDao.deleteMessageByMsgId(msgId : string) : void
/**
* 根据消息id列表删除消息
* @param idList
*/
MessageDao.deleteMessagesByIdList(idList : Array&lt;string&gt;) : void
/**
* 删除指定人的所有消息
* @param userId
*/
MessageDao.deleteMessageByUserId(userId : string) : void
/**
* 删除指定群组的所有消息
* @param groupId
*/
MessageDao.deleteMessageByGroupId(groupId : string) : void
/**
* 删除消息表的所有数据
*/
MessageDao.deleteTable() : void
/**
* 搜索个人消息
* @param searchTxt
* @returns
*/
MessageDao.searchPersonMessage(searchTxt : string) : Array&lt;MessageEntity&gt;
/**
* 搜索群组消息
* @param searchTxt
* @returns
*/
MessageDao.searchGroupMessage(searchTxt : string) : Array&lt;MessageEntity&gt;
/**
* 搜索指定人原的消息
* @param userId
* @param searchTxt
* @returns
*/
MessageDao.searchPersonMessageByUserId(userId : string, searchTxt : string) : Array&lt;MessageEntity&gt;
/**
* 搜索指定群组的消息
* @param groupId
* @param searchTxt
* @returns
*/
MessageDao.searchGroupMessageByGroupId(groupId : string, searchTxt : string) : Array&lt;MessageEntity&gt;</code></pre>