跳到主要内容

数据更新

当业务层的用户、群组或系统会话资料发生变化时,可以通过 uni.$RongKitStore.appData 提供的更新方法,将最新资料写入 IMKit 内存缓存。缓存更新后,使用对应资料的会话列表和聊天界面会通过 MobX 响应式状态同步刷新。

备注

这些方法只更新 IMKit 的内存缓存,不会修改业务服务端或融云服务端保存的数据。应用仍需先在自己的业务系统中完成资料更新,再将最新资料同步给 IMKit。

更新接口

方法作用资料类型
updateUserProfile更新用户资料IUserProfile
updateGroupProfile更新群组资料IGroupProfile
updateSystemProfile更新系统会话资料ISystemProfile

更新用户资料

调用 updateUserProfile 更新用户名称、头像或备注信息。

typescript
const userId = 'user-01';

uni.$RongKitStore.appData.updateUserProfile(userId, {
id: userId,
name: '新的用户名称',
portraitUri: 'https://example.com/avatar.png',
remark: '用户备注',
});
参数类型说明
userIdstring需要更新的用户 ID
profileIUserProfile最新的用户资料,包含 idname,可选包含 portraitUriremark

更新群组资料

调用 updateGroupProfile 更新群组名称、头像、成员数量或备注信息。该方法只更新群组资料,不会更新群成员列表。

typescript
const groupId = 'group-01';

uni.$RongKitStore.appData.updateGroupProfile(groupId, {
id: groupId,
name: '新的群组名称',
portraitUri: 'https://example.com/group-avatar.png',
memberCount: 100,
remark: '群组备注',
});
参数类型说明
groupIdstring需要更新的群组 ID
profileIGroupProfile最新的群组资料,必须包含 idnamememberCount

更新系统会话资料

调用 updateSystemProfile 更新系统会话的名称和头像。

typescript
const systemId = 'system-01';

uni.$RongKitStore.appData.updateSystemProfile(systemId, {
id: systemId,
name: '系统通知',
portraitUri: 'https://example.com/system-avatar.png',
});
参数类型说明
systemIdstring需要更新的系统会话 ID
profileISystemProfile最新的系统会话资料,包含 idname,可选包含 portraitUri

注意事项

  1. 第一个 ID 参数应与 profile.id 保持一致。IMKit 实际以 profile.id 作为缓存键写入资料。
  2. 更新接口接收完整资料对象,不是局部字段合并;只修改一个字段时,也应同时传入其他必需字段。
  3. 当前接口定义中的 profile 参数为可选参数。更新界面资料时应传入 profile;省略该参数只会触发对应的数据源请求,方法不会返回请求结果,因此不应将其作为手动刷新接口使用。
  4. 当前版本没有公开的群成员缓存更新接口,也不支持 Web IMKit 中的 updateUserOnlineStatusaddGroupMembersremoveGroupMembersupdateGroupMembers
  5. 退出登录或销毁 RCKitStore 时,内存缓存会被清理。应用再次使用相关资料时,IMKit 会通过业务数据 Hook重新获取。