历史消息

按会话分页拉取云端历史消息,支持向前/向后翻页与本地缓存命中。

平台调用风格

C ABI 约定:im_client_* 返回 int(0 成功,非 0 为 IDL 错误码);char** out_json 由库分配、调用方用 im_string_free 释放;char* out + size_t cap 为调用方缓冲区(0 成功 / -1 参数非法 / -2 缓冲区不足)。

接口一览​

操作语义传输返回
getHistoryMessages历史消息分页(beforeSeq 向前翻页);limit 默认 20 上限 100。rev23:channelId 过滤超级群频道消息(仅返回该频道消息)。REST(客户端){messages:Message[], hasMore:bool}

本页 1 个操作,其中 1 个在本平台绑定中声明了方法签名。

跨端方法名​

操作AndroidWebElectronmacOSFlutterNative (C ABI)iOS
getHistoryMessagesgetHistoryMessagesgetHistoryMessagesgetHistoryMessagesgetHistoryMessagesgetHistoryMessagesim_client_historyfunc

方法名在 GA 平台之间保持一致(规则 A);Native C ABI 只覆盖部分操作,其余操作以 — 标注。

getHistoryMessages​

历史消息分页(beforeSeq 向前翻页);limit 默认 20 上限 100。rev23:channelId 过滤超级群频道消息(仅返回该频道消息)。

im_client_history(im_client_t*, int conversation_type, const char* target_id, int limit, unsigned long long before_seq, char** out_json)
REST(客户端)since 1.0.0
参数
参数类型说明
conversationTypeConversationType必填;会话类型枚举(ConversationType)
targetIdstring必填;目标会话 ID:单聊为对方 userId,群聊为 groupId,聊天室为 chatroomId
options{limit?:uint32, beforeSeq?:uint64, channelId?:string}可选;选项对象(字段见类型列):{ limit?:uint32, beforeSeq?:uint64, channelId?:string }
返回

{messages:Message[], hasMore:bool} 历史消息页与是否还有更早数据

示例
C
char* history_json = NULL;
int rc = im_client_history(client, 1, "user2", 20 /* limit */, 0 /* before_seq,0=最新 */, &history_json);
if (rc == 0) { /* 解析 history_json */ }
im_string_free(history_json);
错误码
错误码名称分类HTTP可重试说明
1001INVALID_PARAMETER客户端 / 参数 / 权限400否参数错误
1003FORBIDDEN客户端 / 参数 / 权限403否无权限

相关文档​