Flutter 超级群频道消息用法

本页给出 Flutter 端发送/读取超级群频道消息的完整用法:options.channelId、Message.channelId、按频道过滤历史,以及 IMKit 的频道视图入口(impaas_imkit)。路由与权限语义见 超级群频道级消息。

项内容
包 / 模块impaas_imlib
IMKitimpaas_imkit
调用风格Future<RcResult<T>>;IMKit `ChatView(channelId:)` / `ChatController(channelId:)`
频道消息条件conversationType=10 + options.channelId(空白 = 群级消息)
消息模型Message.channelId?: string(仅频道消息出现)
版本前提

需要 SDK/服务端包含 rev23(options.channelId、Message.channelId)。

未升级时:客户端会忽略/拒绝 channelId,或服务端按旧语义处理;请先升级服务端,再升级客户端。

未升级的读取端仍可读频道消息(忽略未知字段,按群级展示),但这意味着私有频道内容不会在旧端隔离。

发送频道消息​

Dart
// 1) 发送频道消息:MessageOptions(channelId: ...)(仅 SUPER_GROUP)
final res = await client.sendTextMessage(
  RongIMConversationType.SUPER_GROUP,
  'g_1001',
  '频道消息:今晚 8 点发布',
  options: const MessageOptions(channelId: 'ch_news'),
);
if (res.code != 0) throw Exception(res.msg);
print(res.data!.channelId); // ch_news

// 任意内容:sendMessage(10, groupId, content, options: MessageOptions(channelId: ...))
// channelId 为空/空白 = 群级消息

读取历史与渲染​

Dart
// 2) 历史:getHistoryMessages(..., channelId: ...)
final page = await client.getHistoryMessages(
  RongIMConversationType.SUPER_GROUP,
  'g_1001',
  channelId: 'ch_news',
  limit: 20,
);
for (final m in page.data!.messages) {
  if (m.channelId != null) renderChannelMessage(m);
  else renderGroupMessage(m);
}

IMKit 频道视图​

Dart
// 3) IMKit:ChatView(channelId:) / ChatController(channelId:) 只渲染该频道消息
final controller = ChatController(
  client: client,
  conversationType: RongIMConversationType.SUPER_GROUP,
  targetId: 'g_1001',
  channelId: 'ch_news',
  currentUserId: me,
);

ChatView(controller: controller)
// 或在页面内直接:ChatView(conversationType: 10, targetId: "g_1001", channelId: "ch_news")

接口与错误码​

操作入参返回错误码
sendMessageconversationType:ConversationType, targetId:string, content:Content, options:{clientMsgId?:string, channelId?:string}?Message1001 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1016 1021 3001 3002
sendTextMessageconversationType:ConversationType, targetId:string, text:string, options:{clientMsgId?:string, mentionedInfo?:MentionedInfo, quote?:Quote, channelId?:string}?Message1001 1007 1009 1010 1011 3001 3002
getHistoryMessagesconversationType:ConversationType, targetId:string, options:{limit?:uint32, beforeSeq?:uint64, channelId?:string}?{messages:Message[], hasMore:bool}1001 1003
错误码名称含义可重试
1001INVALID_PARAMETER参数错误否
1003FORBIDDEN无权限否
1005GROUP_NOT_FOUND群组不存在否
1006NOT_GROUP_MEMBER未加入群组否

限制​

  • 频道消息仍属于群会话(10 + groupId):未读/回执/免打扰按群会话聚合,不会出现独立频道会话行。
  • 私有频道发送/读取要求频道成员(1003);公有频道群成员发送会自动加入频道。
  • typing 未按频道收窄;客户端搜索暂未按频道裁剪(Open API 搜索已过滤)。
  • IMKit 只提供单频道会话视图,频道列表/成员管理页需宿主实现(Electron 无 IMKit)。
  • 存量 rev22 群级消息(无 channelId)永远按群级处理。

相关链接​