197 lines
5.5 KiB
Dart
197 lines
5.5 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:aslan/app_localizations.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_tts.dart';
|
|
import 'package:aslan/chatvibe_data/sources/local/user_manager.dart';
|
|
import 'package:aslan/chatvibe_data/sources/repositories/room_repository_imp.dart';
|
|
import 'package:aslan/chatvibe_data/sources/repositories/user_repository_impl.dart';
|
|
import 'package:aslan/chatvibe_domain/models/req/at_user_profile_cmd.dart';
|
|
import 'package:aslan/chatvibe_domain/models/res/country_res.dart';
|
|
import 'package:aslan/chatvibe_domain/models/res/login_res.dart';
|
|
import 'package:aslan/chatvibe_domain/models/res/room_user_card_res.dart';
|
|
import 'package:aslan/chatvibe_domain/models/res/at_user_identity_res.dart';
|
|
|
|
class ChatVibeUserProfileManager extends ChangeNotifier {
|
|
ATUserProfileCmd? editUser;
|
|
Function? _familyUpdateCall;
|
|
|
|
void bindFamilyUpdate(Function? familyUpdate) {
|
|
_familyUpdateCall = familyUpdate;
|
|
}
|
|
|
|
void setUserAvatar(String avatar) {
|
|
editUser ??= ATUserProfileCmd();
|
|
editUser!.setUserAvatar = avatar;
|
|
notifyListeners();
|
|
}
|
|
|
|
void setUserSex(num sex) {
|
|
editUser ??= ATUserProfileCmd();
|
|
editUser!.setUserSex = sex;
|
|
}
|
|
|
|
void setUserNickname(String nickname) {
|
|
editUser ??= ATUserProfileCmd();
|
|
editUser!.setUserNickname = nickname;
|
|
}
|
|
|
|
void setBornYear(num bornYear) {
|
|
editUser ??= ATUserProfileCmd();
|
|
editUser!.setBornYear = bornYear;
|
|
}
|
|
|
|
void setBornMonth(num bornMonth) {
|
|
editUser ??= ATUserProfileCmd();
|
|
editUser!.setBornMonth = bornMonth;
|
|
}
|
|
|
|
void setBornDay(num bornDay) {
|
|
editUser ??= ATUserProfileCmd();
|
|
editUser!.setBornDay = bornDay;
|
|
}
|
|
|
|
void setAge(num age) {
|
|
editUser ??= ATUserProfileCmd();
|
|
editUser!.setAge = age;
|
|
}
|
|
|
|
void setCountry(Country country) {
|
|
editUser ??= ATUserProfileCmd();
|
|
editUser!.setCountryCode = country.alphaTwo!;
|
|
editUser!.setCountryId = country.id!;
|
|
editUser!.setCountryName = country.countryName!;
|
|
}
|
|
|
|
void clearEditUserUser() {
|
|
editUser = null;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future getMyUserInfo({
|
|
bool needLoadUserCountGuard = true,
|
|
bool needRefreshFamily = false,
|
|
}) async {
|
|
var us = AccountStorage().getCurrentUser();
|
|
String userId = us?.userProfile?.id ?? "";
|
|
var userInfo = await AccountRepository().loadUserInfo(userId);
|
|
userProfile = userInfo;
|
|
if (needRefreshFamily) {
|
|
updateFamily(userInfo.familyId);
|
|
}
|
|
us?.setUserProfile(userInfo);
|
|
AccountStorage().setCurrentUser(us!);
|
|
notifyListeners();
|
|
}
|
|
|
|
ATUserIdentityRes? userIdentity;
|
|
|
|
void getUserIdentity() async {
|
|
userIdentity = await AccountRepository().userIdentity();
|
|
notifyListeners();
|
|
}
|
|
|
|
///用户信息详情个人页
|
|
ChatVibeUserProfile? userProfile;
|
|
|
|
void getUserInfoById(String userId) async {
|
|
userProfile = null;
|
|
userProfile = await AccountRepository().loadUserInfo(userId);
|
|
|
|
notifyListeners();
|
|
}
|
|
|
|
///房间资料卡
|
|
RoomUserCardRes? userCardInfo;
|
|
|
|
// List<UserCountGuardRes>? userCountGuardResList;
|
|
|
|
void roomUserCard(String roomId, String userId) async {
|
|
userCardInfo = null;
|
|
userCardInfo = await ChatRoomRepository().roomUserCard(roomId, userId);
|
|
notifyListeners();
|
|
}
|
|
|
|
void followUser(String userId) async {
|
|
var result = await AccountRepository().followUser(userId);
|
|
if (result) {
|
|
if (userCardInfo != null) {
|
|
userCardInfo = userCardInfo?.copyWith(follow: !userCardInfo!.follow!);
|
|
notifyListeners();
|
|
}
|
|
}
|
|
}
|
|
|
|
num myBalance = 0.0;
|
|
|
|
void balance() async {
|
|
myBalance = await AccountRepository().balance();
|
|
myBalance = myBalance.toInt();
|
|
notifyListeners();
|
|
}
|
|
|
|
updateBalance(double m) {
|
|
myBalance = m;
|
|
myBalance = myBalance.toInt();
|
|
notifyListeners();
|
|
}
|
|
|
|
updateFamily(String? familyId) {
|
|
if (AccountStorage().getCurrentUser()?.userProfile?.familyId != familyId) {
|
|
AccountStorage().getCurrentUser()?.userProfile?.setFamilyId(familyId);
|
|
_familyUpdateCall?.call();
|
|
notifyListeners();
|
|
}
|
|
}
|
|
|
|
void inviteHostOpt(BuildContext ct, String id, String status) async {
|
|
try {
|
|
await AccountRepository().inviteHost(id, status);
|
|
getUserIdentity();
|
|
ATTts.show(ATAppLocalizations.of(ct)!.operationSuccessful);
|
|
} catch (e) {}
|
|
}
|
|
|
|
void inviteAgentOpt(BuildContext ct, String id, String status) async {
|
|
try {
|
|
await AccountRepository().inviteAgent(id, status);
|
|
getUserIdentity();
|
|
ATTts.show(ATAppLocalizations.of(ct)!.operationSuccessful);
|
|
} catch (e) {}
|
|
}
|
|
|
|
void inviteBDOpt(BuildContext ct, String id, String status) async {
|
|
try {
|
|
await AccountRepository().inviteBD(id, status);
|
|
getUserIdentity();
|
|
ATTts.show(ATAppLocalizations.of(ct)!.operationSuccessful);
|
|
} catch (e) {}
|
|
}
|
|
|
|
void inviteBDLeader(BuildContext ct, String id, String status) async {
|
|
try {
|
|
await AccountRepository().inviteBDLeader(id, status);
|
|
getUserIdentity();
|
|
ATTts.show(ATAppLocalizations.of(ct)!.operationSuccessful);
|
|
} catch (e) {}
|
|
}
|
|
|
|
void inviteRechargeAgent(BuildContext ct, String id, String status) async {
|
|
try {
|
|
await AccountRepository().inviteRechargeAgent(id, status);
|
|
getUserIdentity();
|
|
ATTts.show(ATAppLocalizations.of(ct)!.operationSuccessful);
|
|
} catch (e) {}
|
|
}
|
|
|
|
void cpRlationshipProcessApply(
|
|
BuildContext ct,
|
|
String id,
|
|
bool status,
|
|
) async {
|
|
try {
|
|
await AccountRepository().cpRelationshipProcessApply(id, status);
|
|
getMyUserInfo(needLoadUserCountGuard: false);
|
|
ATTts.show(ATAppLocalizations.of(ct)!.operationSuccessful);
|
|
} catch (e) {}
|
|
}
|
|
}
|