浏览 SDKs · uni-app / uni-app x
SDKsuni-app

加载历史消息

按会话和 clientMsgID 游标读取历史消息。

复制

聊天页面进入会话时使用公共入口 getAdvancedHistoryMessageList() 建立第一页快照;继续加载更早消息时,把当前最早一条消息的 clientMsgID 作为下一页游标。

参数说明

参数类型是否必填说明
conversationIDstring要读取历史消息的会话 ID。
startClientMsgIDstring分页锚点消息 ID;第一页传空字符串。
countnumber本次读取的消息数量。
lastMinSeqnumbernull上一页返回的最小序号,用于连续分页。
import { getAdvancedHistoryMessageList } from '@/uni_modules/unix-openim-sdk'

const page = await getAdvancedHistoryMessageList({
  conversationID,
  startClientMsgID: oldestMessage?.clientMsgID ?? '',
  count: 30,
  lastMinSeq,
})

返回结果

Promise 成功后,结果是 OpenIMAdvancedHistoryMessageListResult | null

字段类型说明
messageListOpenIMMessageItem[]当前页消息。
lastMinSeqnumber继续读取时传回的最小序号。
isEndboolean是否到达当前加载方向的历史边界。
errCodenumber历史读取结果状态码。
errMsgstring与状态码对应的说明。

只有 errCode 表示成功时才合并 messageList;Promise 被拒绝时仍按通用错误处理。按 conversationID 限定列表,并以 clientMsgID 去重;查询不会触发新消息事件。

商业版 getHistoryMessageList()商业版 商业版 额外要求 isReverse,并支持可选 viewTypelastMinSeq。不要把它等同于已删除的单独 reverse-history 页面;方向通过参数表达。