数据更新
当业务层的用户、群组或系统会话资料发生变化时,可以通过 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: '用户备注',
});
| 参数 | 类型 | 说明 |
|---|---|---|
userId | string | 需要更新的用户 ID |
profile | IUserProfile | 最新的用户资料,包含 id、name,可选包含 portraitUri、remark |
更新群组资料
调用 updateGroupProfile 更新群组名称、头像、成员数量或备注信息。该方法只更新群组资料,不会更新群成员列表。
typescript
const groupId = 'group-01';
uni.$RongKitStore.appData.updateGroupProfile(groupId, {
id: groupId,
name: '新的群组名称',
portraitUri: 'https://example.com/group-avatar.png',
memberCount: 100,
remark: '群组备注',
});
| 参数 | 类型 | 说明 |
|---|---|---|
groupId | string | 需要更新的群组 ID |
profile | IGroupProfile | 最新的群组资料,必须包含 id、name、memberCount |
更新 系统会话资料
调用 updateSystemProfile 更新系统会话的名称和头像。
typescript
const systemId = 'system-01';
uni.$RongKitStore.appData.updateSystemProfile(systemId, {
id: systemId,
name: '系统通知',
portraitUri: 'https://example.com/system-avatar.png',
});
| 参数 | 类型 | 说明 |
|---|---|---|
systemId | string | 需要更新的系统会话 ID |
profile | ISystemProfile | 最新的系统会话资料,包含 id、name,可选包含 portraitUri |
注意事项
- 第一个 ID 参数应与
profile.id保持一致。IMKit 实际以profile.id作为缓存键写入资料。 - 更新接口接收完整资料对象,不是局部字段合并;只修改一个字段时,也应同时传入其他必需字段。
- 当前接口定义中的
profile参数为可选参数。更新界面资料时应传入profile;省略该参数只会触发对应的数据源请求,方法不会返回请求结果,因此不应将其作为手动刷新接口使用。 - 当前版本没有公开的群成员缓存更新接口,也不支持 Web IMKit 中的
updateUserOnlineStatus、addGroupMembers、removeGroupMembers或updateGroupMembers。 - 退出登录或销毁
RCKitStore时,内存缓存会被清理。应用再次使用相关资料时,IMKit 会通过业务数据 Hook重新获取。