业务更新User所需(企业成员、聊天室群组成员)

This commit is contained in:
Happi (哈比)
2026-03-09 19:15:51 +08:00
parent c278d1329e
commit 8f77a14818
22 changed files with 1030 additions and 238 deletions

View File

@@ -0,0 +1,66 @@
import 'package:im_app/domain/entities/user.dart';
/// 群组成员的部分 [User] 表示,数据来源于群组成员接口。
///
/// 群组 API 返回的用户信息不完整,仅保证身份和在线状态字段有效。
/// 构造函数中未列出的 [User] 字段均为 null不应依赖这些字段。
///
/// ## 何时使用 [GroupMember] vs [User]
/// - 渲染群组成员列表、成员头像等场景使用 [GroupMember]
/// - 需要联系方式、音效设置、好友关系等完整信息时,
/// 请通过用户详情接口获取完整的 [User]
///
/// ## 数据流
/// ```
/// 群组 API 响应
/// → GroupMember.fromJson() ← 群组专用字段user_id、icon…
/// → ★ GroupMember ★
/// → 仍是合法的 [User],可在任何需要 [User] 的地方使用
/// ```
class GroupMember extends User {
const GroupMember({
required super.uid,
super.nickname,
super.profilePic,
super.profilePicGaussian,
super.lastOnline,
super.deletedAt,
super.role,
super.requireUpsert = true,
});
/// 从群组成员 JSON 数据创建 [GroupMember]。
///
/// 注意群组 API 使用了与用户接口不同的字段名:
/// - `user_id` → [uid] (非 `uid`
/// - `user_name` → [nickname] (非 `nickname`
/// - `icon` → [profilePic] (非 `profile_pic`
/// - `icon_gaussian` → [profilePicGaussian]
/// - `delete_time` → [deletedAt] (非 `deleted_at`
factory GroupMember.fromJson(Map<String, dynamic> json) => GroupMember(
uid: json['user_id'] as int,
nickname: json['user_name'],
profilePic: json['icon'],
profilePicGaussian: json['icon_gaussian'],
lastOnline: json['last_online'],
deletedAt: json['delete_time'],
role: json['role'],
);
/// 序列化为群组成员 JSON 格式。
///
/// 字段名与 [fromJson] 保持对称。
/// `id`/`user_id`、`nickname`/`user_name`、`icon`/`profile_pic`
/// 同时输出两种命名,兼容不同约定的下游消费方。
Map<String, dynamic> toJson() => {
'id': uid,
'user_id': uid,
'user_name': nickname,
'nickname': nickname, // 兼容旧命名
'icon': profilePic,
'profile_pic': profilePic, // 兼容旧命名
'icon_gaussian': profilePicGaussian,
'last_online': lastOnline,
'delete_time': deletedAt,
};
}