getSelfUserInfo method
拉取当前登录用户详情(含 is_robot / is_official,来自 /user/setting)
Implementation
Future<UserInfo> getSelfUserInfo() async {
final resp = await _net.http.post('/api/v1/user/detail');
_self = UserInfo.fromJson(resp);
// detail 不含 is_robot / is_official;一并拉 setting 补齐
try {
final settingResp = await _net.http.post('/api/v1/user/setting');
final info = settingResp['user_info'];
if (info is Map) {
final map = Map<String, dynamic>.from(info);
final uid = asInt(map['uid'] ?? map['id']);
final isRobot = asInt(map['is_robot'], YesNo.no);
final isOfficial = asInt(map['is_official'], YesNo.no);
_self = _self!.copyWith(
id: uid > 0 ? uid : null,
isRobot: isRobot == 0 ? YesNo.no : isRobot,
isOfficial: isOfficial == 0 ? YesNo.no : isOfficial,
isQiye: map.containsKey('is_qiye') ? asBool(map['is_qiye']) : null,
);
}
} catch (_) {}
await _store.saveUserId(_self!.id);
await _store.setKv(LocalStorage.keyUserInfo, encodeJsonString(_self!.toJson()));
_listener?.selfInfoUpdated(_self!);
return _self!;
}