数据更新
当业务层的用户、群组或系统会话资料发生变化时,可以通过 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 |