基础页面

This commit is contained in:
2022-10-20 14:21:39 +08:00
parent 49ad269c2b
commit 42ba10ec61
62 changed files with 5132 additions and 54 deletions

View File

@@ -0,0 +1,111 @@
import 'package:chat/models/im/private_conversation_model.dart';
import 'package:chat/services/tim/conversation_service.dart';
import 'package:chat/services/tim/friend_service.dart';
import 'package:chat/services/tim_service.dart';
import 'package:chat/utils/ui_tools.dart';
import 'package:get/get.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_friend_info_result.dart';
class PrivateController extends GetxController {
static PrivateController get to => Get.find<PrivateController>();
Rx<PrivateConversationModel> currentFriend =
PrivateConversationModel(userID: '').obs;
@override
void onClose() {
currentFriend.value = PrivateConversationModel(userID: '');
TimService.to.currentConversationId.value = '';
super.onClose();
}
/// 设置当前好友
Future<void> setCurrentFriend(String userID) async {
V2TimFriendInfoResult? info = await TimFriendService.to.friendInfo(userID);
if (info != null) {
TimService.to.currentConversationId.value = 'c2c_' + userID;
currentFriend.value.userID = userID;
currentFriend.value.isFriend =
info.relation == UserRelationEnum.V2TIM_FRIEND_RELATION_TYPE_BOTH_WAY;
currentFriend.value.friendRemark = info.friendInfo!.friendRemark!;
currentFriend.value.userProfile = info.friendInfo!.userProfile;
/// 通过自定义Staffer字段判断是否是客服属于哪个店铺
if (info.friendInfo!.userProfile?.customInfo!['Staffer']?.isNotEmpty ==
true) {
currentFriend.value.shopId =
info.friendInfo!.userProfile?.customInfo!['Staffer'];
currentFriend.value.isStaffer = true;
}
/// 通过用户自定义字段,判断是否允许陌生人消息
if (info.friendInfo!.userProfile?.customInfo!['Stranger']?.isNotEmpty ==
true) {
currentFriend.value.allowStranger = false;
}
/// 设置会话
currentFriend.value.conversation =
await TimConversationService.to.getById('c2c_' + userID);
currentFriend.refresh();
}
}
Future<void> togglePinned() async {
var res = await TimConversationService.to.setOnTop(
currentFriend.value.conversation!,
);
if (res) {
currentFriend.value.conversation =
await TimConversationService.to.getById(
'c2c_' + currentFriend.value.userID,
);
currentFriend.refresh();
UiTools.toast('修改成功');
}
}
Future<void> changeReceiveOpt() async {
var res = await TimConversationService.to.setReceiveOpt(
currentFriend.value.conversation!,
);
if (res) {
currentFriend.value.conversation =
await TimConversationService.to.getById(
'c2c_' + currentFriend.value.userID,
);
currentFriend.refresh();
UiTools.toast('修改成功');
}
}
Future<void> setRemark(String remark) async {
var result = await TimFriendService.to.setFriendRemark(
currentFriend.value.userID,
remark,
);
if (result) {
currentFriend.value.friendRemark = remark;
currentFriend.value.conversation =
await TimConversationService.to.getById(
'c2c_' + currentFriend.value.userID,
);
currentFriend.refresh();
TimConversationService.to.fetchList();
UiTools.toast('备注修改成功');
Get.back();
}
}
}