init
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:tencent_chat_i18n_tool/tencent_chat_i18n_tool.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/enum/message_elem_type.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/enum/offlinePushInfo.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_message.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_message.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/ui/views/TIMUIKitChat/tim_uikit_cloud_custom_data.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/business_logic/view_models/tui_chat_global_model.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/data_services/core/core_services_implements.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/data_services/services_locatar.dart';
|
||||
|
||||
class TUIChatModelTools {
|
||||
final TUIChatGlobalModel globalModel = serviceLocator<TUIChatGlobalModel>();
|
||||
final CoreServicesImpl _coreServices = serviceLocator<CoreServicesImpl>();
|
||||
|
||||
OfflinePushInfo buildMessagePushInfo(V2TimMessage message, String convID, ConvType convType) {
|
||||
String createJSON(String convID) {
|
||||
return "{\"conversationID\": \"$convID\"}";
|
||||
}
|
||||
|
||||
if (globalModel.chatConfig.offlinePushInfo != null) {
|
||||
final customData = globalModel.chatConfig.offlinePushInfo!(message, convID, convType);
|
||||
if (customData != null) {
|
||||
return customData;
|
||||
}
|
||||
}
|
||||
|
||||
String title = globalModel.chatConfig.notificationTitle;
|
||||
|
||||
// If user provides null, use default ext.
|
||||
String ext = globalModel.chatConfig.notificationExt != null
|
||||
? globalModel.chatConfig.notificationExt!(message, convID, convType) ??
|
||||
(convType == ConvType.c2c ? createJSON("c2c_${message.sender}") : createJSON("group_$convID"))
|
||||
: (convType == ConvType.c2c ? createJSON("c2c_${message.sender}") : createJSON("group_$convID"));
|
||||
|
||||
String desc = message.userID ?? message.groupID ?? "";
|
||||
String messageSummary = "";
|
||||
switch (message.elemType) {
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_CUSTOM:
|
||||
messageSummary = TIM_t("自定义消息");
|
||||
break;
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_FACE:
|
||||
messageSummary = TIM_t("表情消息");
|
||||
break;
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_FILE:
|
||||
messageSummary = TIM_t("文件消息");
|
||||
break;
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_GROUP_TIPS:
|
||||
messageSummary = TIM_t("群提示消息");
|
||||
break;
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_IMAGE:
|
||||
messageSummary = TIM_t("图片消息");
|
||||
break;
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_LOCATION:
|
||||
messageSummary = TIM_t("位置消息");
|
||||
break;
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_MERGER:
|
||||
messageSummary = TIM_t("合并转发消息");
|
||||
break;
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_SOUND:
|
||||
messageSummary = TIM_t("语音消息");
|
||||
break;
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_TEXT:
|
||||
messageSummary = message.textElem!.text!;
|
||||
break;
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_VIDEO:
|
||||
messageSummary = TIM_t("视频消息");
|
||||
break;
|
||||
}
|
||||
|
||||
if (globalModel.chatConfig.notificationBody != null) {
|
||||
desc = globalModel.chatConfig.notificationBody!(message, convID, convType) ?? messageSummary;
|
||||
} else {
|
||||
desc = messageSummary;
|
||||
}
|
||||
|
||||
return OfflinePushInfo(
|
||||
title: title,
|
||||
desc: desc,
|
||||
disablePush: false,
|
||||
ext: ext,
|
||||
iOSSound: globalModel.chatConfig.notificationIOSSound,
|
||||
androidSound: globalModel.chatConfig.notificationAndroidSound,
|
||||
ignoreIOSBadge: false,
|
||||
androidOPPOChannelID: globalModel.chatConfig.notificationOPPOChannelID,
|
||||
androidVIVOClassification: 1,
|
||||
);
|
||||
}
|
||||
|
||||
V2TimMessage setUserInfoForMessage(V2TimMessage messageInfo, String? id) {
|
||||
final loginUserInfo = _coreServices.loginUserInfo;
|
||||
if (loginUserInfo != null) {
|
||||
messageInfo.faceUrl = loginUserInfo.faceUrl;
|
||||
messageInfo.nickName = loginUserInfo.nickName;
|
||||
messageInfo.sender = loginUserInfo.userID;
|
||||
}
|
||||
messageInfo.timestamp = (DateTime.now().millisecondsSinceEpoch / 1000).ceil();
|
||||
messageInfo.isSelf = true;
|
||||
messageInfo.id = id;
|
||||
|
||||
return messageInfo;
|
||||
}
|
||||
|
||||
String getMessageSummary(V2TimMessage message, String? Function(V2TimMessage message)? abstractMessageBuilder) {
|
||||
final String? customAbstractMessage = abstractMessageBuilder != null ? abstractMessageBuilder(message) : null;
|
||||
if (customAbstractMessage != null) {
|
||||
return customAbstractMessage;
|
||||
}
|
||||
|
||||
final elemType = message.elemType;
|
||||
switch (elemType) {
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_FACE:
|
||||
return "[表情消息]";
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_CUSTOM:
|
||||
return "[自定义消息]";
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_FILE:
|
||||
return "[文件消息]";
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_GROUP_TIPS:
|
||||
return "[群消息]";
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_IMAGE:
|
||||
return "[图片消息]";
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_LOCATION:
|
||||
return "[位置消息]";
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_MERGER:
|
||||
return "[合并消息]";
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_NONE:
|
||||
return "[没有元素]";
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_SOUND:
|
||||
return "[语音消息]";
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_TEXT:
|
||||
return message.textElem?.text ?? "[文本消息]";
|
||||
case MessageElemType.V2TIM_ELEM_TYPE_VIDEO:
|
||||
return "[视频消息]";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
String getMessageAbstract(V2TimMessage message, String? Function(V2TimMessage message)? abstractMessageBuilder) {
|
||||
final messageAbstract = RepliedMessageAbstract(
|
||||
summary: TIM_t(getMessageSummary(message, abstractMessageBuilder)),
|
||||
elemType: message.elemType,
|
||||
msgID: message.msgID,
|
||||
timestamp: message.timestamp,
|
||||
seq: message.seq);
|
||||
return jsonEncode(messageAbstract.toJson());
|
||||
}
|
||||
|
||||
Future<V2TimMessage?> getExistingMessageByID(
|
||||
{required String msgID, required String conversationID, required ConvType conversationType}) async {
|
||||
final currentHistoryMsgList = globalModel.messageListMap[conversationID] ?? [];
|
||||
final int? targetIndex = currentHistoryMsgList.indexWhere((item) {
|
||||
return item.msgID == msgID;
|
||||
});
|
||||
|
||||
if (targetIndex != null && targetIndex > -1 && currentHistoryMsgList.isNotEmpty) {
|
||||
return currentHistoryMsgList[targetIndex];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> hasZeroSize(String filePath) async {
|
||||
try {
|
||||
final file = File(filePath);
|
||||
final fileSize = await file.length();
|
||||
return fileSize == 0;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,363 @@
|
||||
// ignore_for_file: unnecessary_getters_setters, avoid_print
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/enum/group_member_filter_enum.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/enum/group_member_role.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/enum/group_member_role_enum.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/enum/group_type.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/enum/receive_message_opt_enum.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_callback.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_callback.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_conversation.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_conversation.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_friend_info.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_friend_info.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_group_info.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_group_info.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_group_member_full_info.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_group_member_full_info.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_group_member_operation_result.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_group_member_operation_result.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_group_member_search_param.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_group_member_search_param.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_group_member_search_result.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_group_member_search_result.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_value_callback.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_value_callback.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/business_logic/life_cycle/group_profile_life_cycle.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/data_services/conversation/conversation_services.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/data_services/core/core_services_implements.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/data_services/friendShip/friendship_services.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/data_services/group/group_services.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/data_services/message/message_services.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/data_services/services_locatar.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/ui/utils/logger.dart';
|
||||
|
||||
class TUIGroupProfileModel extends ChangeNotifier {
|
||||
final CoreServicesImpl _coreServices = serviceLocator<CoreServicesImpl>();
|
||||
final GroupServices _groupServices = serviceLocator<GroupServices>();
|
||||
final ConversationService _conversationService = serviceLocator<ConversationService>();
|
||||
final MessageService _messageService = serviceLocator<MessageService>();
|
||||
final FriendshipServices _friendshipServices = serviceLocator<FriendshipServices>();
|
||||
GroupProfileLifeCycle? _lifeCycle;
|
||||
|
||||
V2TimConversation? _conversation;
|
||||
String _groupID = "";
|
||||
List<V2TimFriendInfo>? _contactList;
|
||||
List<V2TimGroupMemberFullInfo?>? _groupMemberList;
|
||||
String _groupMemberListSeq = "0";
|
||||
V2TimGroupInfo? _groupInfo;
|
||||
Function(V2TimGroupMemberFullInfo groupMemberFullInfo, TapDownDetails? tapDetails)? onClickUser;
|
||||
|
||||
GroupProfileLifeCycle? get lifeCycle => _lifeCycle;
|
||||
|
||||
set lifeCycle(GroupProfileLifeCycle? value) {
|
||||
_lifeCycle = value;
|
||||
}
|
||||
|
||||
V2TimConversation? get conversation => _conversation;
|
||||
|
||||
set conversation(V2TimConversation? value) {
|
||||
_conversation = value;
|
||||
}
|
||||
|
||||
String get groupID => _groupID;
|
||||
|
||||
set groupID(String value) {
|
||||
_groupID = value;
|
||||
}
|
||||
|
||||
List<V2TimFriendInfo> get contactList => _contactList ?? [];
|
||||
|
||||
set contactList(List<V2TimFriendInfo> value) {
|
||||
_contactList = value;
|
||||
}
|
||||
|
||||
List<V2TimGroupMemberFullInfo?> get groupMemberList => _groupMemberList ?? [];
|
||||
|
||||
set groupMemberList(List<V2TimGroupMemberFullInfo?> value) {
|
||||
_groupMemberList = value;
|
||||
}
|
||||
|
||||
V2TimGroupInfo? get groupInfo => _groupInfo;
|
||||
|
||||
set groupInfo(V2TimGroupInfo? value) {
|
||||
_groupInfo = value;
|
||||
}
|
||||
|
||||
void loadData(String groupID) {
|
||||
_groupID = groupID;
|
||||
loadGroupInfo(groupID);
|
||||
loadGroupMemberList(groupID: groupID);
|
||||
_loadConversation();
|
||||
_loadContactList();
|
||||
}
|
||||
|
||||
loadGroupInfo(String groupID) async {
|
||||
final groupInfo = await _groupServices.getGroupsInfo(groupIDList: [groupID]);
|
||||
if (groupInfo != null) {
|
||||
final groupRes = groupInfo.first;
|
||||
if (groupRes.resultCode == 0) {
|
||||
_groupInfo = groupRes.groupInfo;
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> loadGroupMemberList({required String groupID, int count = 100, String? seq}) async {
|
||||
final String? nextSeq = await _loadGroupMemberListFunction(groupID: groupID, seq: seq, count: count);
|
||||
if (nextSeq != null && nextSeq != "0" && nextSeq != "") {
|
||||
return await loadGroupMemberList(groupID: groupID, count: count, seq: nextSeq);
|
||||
} else {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> _loadGroupMemberListFunction({required String groupID, int count = 100, String? seq}) async {
|
||||
if (seq == null || seq == "" || seq == "0") {
|
||||
_groupMemberList?.clear();
|
||||
}
|
||||
final res = await _groupServices.getGroupMemberList(
|
||||
groupID: groupID,
|
||||
filter: GroupMemberFilterTypeEnum.V2TIM_GROUP_MEMBER_FILTER_ALL,
|
||||
count: count,
|
||||
nextSeq: seq ?? _groupMemberListSeq);
|
||||
final groupMemberListRes = res.data;
|
||||
if (res.code == 0 && groupMemberListRes != null) {
|
||||
final groupMemberListTemp = groupMemberListRes.memberInfoList ?? [];
|
||||
// TODO
|
||||
outputLogger.i(
|
||||
"loadGroupMemberListfinish,groupMemberListTemp, ${groupMemberListRes.nextSeq}, ${groupMemberListTemp.length}");
|
||||
_groupMemberList = [...?_groupMemberList, ...groupMemberListTemp];
|
||||
_groupMemberListSeq = groupMemberListRes.nextSeq ?? "0";
|
||||
}
|
||||
return groupMemberListRes?.nextSeq;
|
||||
}
|
||||
|
||||
_loadConversation() async {
|
||||
conversation = await _conversationService.getConversation(conversationID: "group_$_groupID");
|
||||
}
|
||||
|
||||
_loadContactList() async {
|
||||
final res = await _friendshipServices.getFriendList();
|
||||
_contactList = res;
|
||||
}
|
||||
|
||||
pinedConversation(bool isPined) async {
|
||||
await _conversationService.pinConversation(conversationID: "group_$_groupID", isPinned: isPined);
|
||||
conversation?.isPinned = isPined;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
setMessageDisturb(bool value) async {
|
||||
final res = await _messageService.setGroupReceiveMessageOpt(
|
||||
groupID: _groupID,
|
||||
opt: value ? ReceiveMsgOptEnum.V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE : ReceiveMsgOptEnum.V2TIM_RECEIVE_MESSAGE);
|
||||
if (res.code == 0) {
|
||||
conversation?.recvOpt =
|
||||
(value ? ReceiveMsgOptEnum.V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE : ReceiveMsgOptEnum.V2TIM_RECEIVE_MESSAGE).index;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<V2TimValueCallback<V2GroupMemberInfoSearchResult>> searchGroupMember(
|
||||
V2TimGroupMemberSearchParam searchParam) async {
|
||||
final res = await _groupServices.searchGroupMembers(searchParam: searchParam);
|
||||
|
||||
if (res.code == 0) {}
|
||||
return res;
|
||||
}
|
||||
|
||||
Future<V2TimCallback?> setGroupName(String groupName) async {
|
||||
if (_groupInfo != null) {
|
||||
String? originalGroupName = _groupInfo?.groupName;
|
||||
_groupInfo?.groupName = groupName;
|
||||
V2TimGroupInfo v2timGroupInfo = V2TimGroupInfo(groupID: _groupID, groupType: _groupInfo!.groupType);
|
||||
v2timGroupInfo.groupName = groupName;
|
||||
final response = await _groupServices.setGroupInfo(info: v2timGroupInfo);
|
||||
if (response.code != 0) {
|
||||
_groupInfo?.groupName = originalGroupName;
|
||||
}
|
||||
notifyListeners();
|
||||
return response;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
setGroupNotification(String notification) async {
|
||||
if (_groupInfo != null) {
|
||||
V2TimGroupInfo v2timGroupInfo = V2TimGroupInfo(groupID: _groupID, groupType: _groupInfo!.groupType);
|
||||
v2timGroupInfo.notification = notification;
|
||||
final response = await _groupServices.setGroupInfo(info: v2timGroupInfo);
|
||||
if (response.code == 0) {
|
||||
notifyListeners();
|
||||
_groupInfo?.notification = notification;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String getSelfNameCard() {
|
||||
try {
|
||||
final loginUserID = _coreServices.loginUserInfo?.userID;
|
||||
String nameCard = "";
|
||||
if (_groupMemberList != null) {
|
||||
nameCard = groupMemberList.firstWhere((element) => element?.userID == loginUserID)?.nameCard ?? "";
|
||||
}
|
||||
|
||||
return nameCard;
|
||||
} catch (err) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Future<V2TimCallback?> setNameCard(String nameCard) async {
|
||||
final loginUserID = _coreServices.loginUserInfo?.userID;
|
||||
if (loginUserID != null) {
|
||||
final res = await _groupServices.setGroupMemberInfo(groupID: _groupID, userID: loginUserID, nameCard: nameCard);
|
||||
if (res.code == 0) {
|
||||
final targetIndex = _groupMemberList?.indexWhere((element) => element?.userID == loginUserID);
|
||||
if (targetIndex != -1) {
|
||||
_groupMemberList![targetIndex!]!.nameCard = nameCard;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<V2TimCallback?> setGroupAddOpt(int addOpt) async {
|
||||
if (_groupInfo != null) {
|
||||
int? originalAddopt = _groupInfo?.groupAddOpt;
|
||||
_groupInfo?.groupAddOpt = addOpt;
|
||||
V2TimGroupInfo v2timGroupInfo = V2TimGroupInfo(groupID: _groupID, groupType: _groupInfo!.groupType);
|
||||
v2timGroupInfo.groupAddOpt = addOpt;
|
||||
final response = await _groupServices.setGroupInfo(info: v2timGroupInfo);
|
||||
if (response.code != 0) {
|
||||
_groupInfo?.groupAddOpt = originalAddopt;
|
||||
}
|
||||
notifyListeners();
|
||||
return response;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<V2TimCallback> setMemberToNormal(String userID) async {
|
||||
final res = await _groupServices.setGroupMemberRole(
|
||||
groupID: _groupID, userID: userID, role: GroupMemberRoleTypeEnum.V2TIM_GROUP_MEMBER_ROLE_MEMBER);
|
||||
if (res.code == 0) {
|
||||
final targetIndex = _groupMemberList!.indexWhere((e) => e!.userID == userID);
|
||||
if (targetIndex != -1) {
|
||||
final targetElem = _groupMemberList![targetIndex];
|
||||
targetElem?.role = GroupMemberRoleType.V2TIM_GROUP_MEMBER_ROLE_MEMBER;
|
||||
_groupMemberList![targetIndex] = targetElem;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Future<V2TimCallback> setMemberToAdmin(String userID) async {
|
||||
final res = await _groupServices.setGroupMemberRole(
|
||||
groupID: _groupID, userID: userID, role: GroupMemberRoleTypeEnum.V2TIM_GROUP_MEMBER_ROLE_ADMIN);
|
||||
if (res.code == 0) {
|
||||
final targetIndex = _groupMemberList!.indexWhere((e) => e!.userID == userID);
|
||||
if (targetIndex != -1) {
|
||||
final targetElem = _groupMemberList![targetIndex];
|
||||
targetElem?.role = GroupMemberRoleType.V2TIM_GROUP_MEMBER_ROLE_ADMIN;
|
||||
_groupMemberList![targetIndex] = targetElem;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void onOwnerChanged(String? userID) {
|
||||
if (userID == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 把之前的群主更新为普通成员
|
||||
final preOwnerIndex =
|
||||
_groupMemberList!.indexWhere((e) => e!.role == GroupMemberRoleType.V2TIM_GROUP_MEMBER_ROLE_OWNER);
|
||||
if (preOwnerIndex != -1) {
|
||||
final preOwnerElem = _groupMemberList![preOwnerIndex];
|
||||
preOwnerElem?.role = GroupMemberRoleType.V2TIM_GROUP_MEMBER_ROLE_MEMBER;
|
||||
|
||||
print("preOwnerUserID: ${preOwnerElem?.userID}");
|
||||
}
|
||||
|
||||
// 设置新的群主
|
||||
final targetIndex = _groupMemberList!.indexWhere((e) => e!.userID == userID);
|
||||
if (targetIndex != -1) {
|
||||
final targetElem = _groupMemberList![targetIndex];
|
||||
targetElem?.role = GroupMemberRoleType.V2TIM_GROUP_MEMBER_ROLE_OWNER;
|
||||
_groupMemberList![targetIndex] = targetElem;
|
||||
|
||||
print("newOwnerUserID: ${targetElem?.userID}");
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
bool canInviteMember() {
|
||||
final groupType = _groupInfo?.groupType;
|
||||
return groupType == GroupType.Work || groupType == "Private";
|
||||
}
|
||||
|
||||
bool canKickOffMember() {
|
||||
final isGroupOwner = _groupInfo?.role == GroupMemberRoleType.V2TIM_GROUP_MEMBER_ROLE_OWNER;
|
||||
final isAdmin = _groupInfo?.role == GroupMemberRoleType.V2TIM_GROUP_MEMBER_ROLE_ADMIN;
|
||||
if (_groupInfo?.groupType == GroupType.Work) {
|
||||
/// work 群主才能踢人
|
||||
return isGroupOwner;
|
||||
}
|
||||
|
||||
if (_groupInfo?.groupType == GroupType.Public || _groupInfo?.groupType == GroupType.Meeting) {
|
||||
/// public || meeting 群主和管理员可以踢人
|
||||
return isGroupOwner || isAdmin;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<V2TimCallback?> setMuteAll(bool muteAll) async {
|
||||
if (_groupInfo != null) {
|
||||
_groupInfo?.isAllMuted = muteAll;
|
||||
V2TimGroupInfo v2timGroupInfo = V2TimGroupInfo(groupID: _groupID, groupType: _groupInfo!.groupType);
|
||||
v2timGroupInfo.isAllMuted = muteAll;
|
||||
final response = await _groupServices.setGroupInfo(info: v2timGroupInfo);
|
||||
if (response.code != 0) {
|
||||
_groupInfo?.isAllMuted = muteAll;
|
||||
}
|
||||
notifyListeners();
|
||||
return response;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<V2TimCallback?> muteGroupMember(String userID, bool isMute, int? serverTime) async {
|
||||
const muteTime = 315360000;
|
||||
final res = await _groupServices.muteGroupMember(groupID: _groupID, userID: userID, seconds: isMute ? muteTime : 0);
|
||||
if (res.code == 0) {
|
||||
final targetIndex = _groupMemberList!.indexWhere((e) => e!.userID == userID);
|
||||
if (targetIndex != -1) {
|
||||
final targetElem = _groupMemberList![targetIndex];
|
||||
targetElem?.muteUntil = isMute ? (serverTime ?? 0) + muteTime : 0;
|
||||
_groupMemberList![targetIndex] = targetElem;
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<V2TimCallback> kickOffMember(List<String> userIDs) async {
|
||||
final res = await _groupServices.kickGroupMember(groupID: _groupID, memberList: userIDs);
|
||||
return res;
|
||||
}
|
||||
|
||||
Future<V2TimValueCallback<List<V2TimGroupMemberOperationResult>>> inviteUserToGroup(List<String> userIDS) async {
|
||||
final res = await _groupServices.inviteUserToGroup(groupID: _groupID, userList: userIDS);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
// ignore_for_file: avoid_print
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/enum/friend_type_enum.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/enum/receive_message_opt_enum.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_callback.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_callback.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_conversation.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_conversation.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_friend_info.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_friend_info.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_friend_operation_result.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_friend_operation_result.dart';
|
||||
import 'package:tencent_cloud_chat_sdk/models/v2_tim_user_full_info.dart'
|
||||
if (dart.library.html) 'package:tencent_cloud_chat_sdk/web/compatible_models/v2_tim_user_full_info.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/business_logic/life_cycle/profile_life_cycle.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/business_logic/model/profile_model.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/business_logic/view_models/tui_friendship_view_model.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/data_services/conversation/conversation_services.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/data_services/core/core_services_implements.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/data_services/friendShip/friendship_services.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/data_services/message/message_services.dart';
|
||||
import 'package:tencent_cloud_chat_uikit/data_services/services_locatar.dart';
|
||||
|
||||
class TUIProfileViewModel extends ChangeNotifier {
|
||||
final ConversationService _conversationService = serviceLocator<ConversationService>();
|
||||
final FriendshipServices _friendshipServices = serviceLocator<FriendshipServices>();
|
||||
final TUIFriendShipViewModel _friendShipViewModel = serviceLocator<TUIFriendShipViewModel>();
|
||||
final CoreServicesImpl _coreServices = serviceLocator<CoreServicesImpl>();
|
||||
final MessageService _messageService = serviceLocator<MessageService>();
|
||||
|
||||
UserProfile? _userProfile;
|
||||
ProfileLifeCycle? _lifeCycle;
|
||||
bool? _shouldAddToBlackList;
|
||||
int _friendType = 0;
|
||||
bool? _isDisturb;
|
||||
|
||||
UserProfile? get userProfile {
|
||||
return _userProfile;
|
||||
}
|
||||
|
||||
set userProfile(UserProfile? value) {
|
||||
_userProfile = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
bool? get isDisturb {
|
||||
return _isDisturb;
|
||||
}
|
||||
|
||||
bool? get isAddToBlackList {
|
||||
return _shouldAddToBlackList;
|
||||
}
|
||||
|
||||
int get friendType {
|
||||
return _friendType;
|
||||
}
|
||||
|
||||
set lifeCycle(ProfileLifeCycle? value) {
|
||||
_lifeCycle = value;
|
||||
}
|
||||
|
||||
loadData({required String userID, bool isNeedConversation = true}) async {
|
||||
if (userID.isEmpty) {
|
||||
return;
|
||||
}
|
||||
V2TimFriendInfo? friendUserInfo;
|
||||
V2TimConversation? conversation;
|
||||
final userInfoList = await _friendshipServices.getFriendsInfo(userIDList: [userID]);
|
||||
final checkFriend =
|
||||
await _friendshipServices.checkFriend(userIDList: [userID], checkType: FriendTypeEnum.V2TIM_FRIEND_TYPE_SINGLE);
|
||||
|
||||
if (checkFriend != null) {
|
||||
final res = checkFriend.first;
|
||||
if (res.resultCode == 0) {
|
||||
_friendType = res.resultType;
|
||||
}
|
||||
}
|
||||
|
||||
if (userInfoList != null) {
|
||||
friendUserInfo = userInfoList[0].friendInfo;
|
||||
}
|
||||
|
||||
if (isNeedConversation) {
|
||||
conversation = await _conversationService.getConversation(conversationID: "c2c_$userID");
|
||||
_isDisturb = conversation?.recvOpt == 2;
|
||||
}
|
||||
|
||||
final friendInfo = await _lifeCycle?.didGetFriendInfo(friendUserInfo) ?? friendUserInfo;
|
||||
|
||||
_isDisturb = conversation?.recvOpt == 2;
|
||||
_userProfile = UserProfile(friendInfo: friendInfo, conversation: conversation);
|
||||
|
||||
_shouldAddToBlackList = _friendShipViewModel.blockList.indexWhere((element) => element.userID == userID) > -1;
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<V2TimCallback> pinedConversation(bool isPined, String convID) async {
|
||||
final res = await _conversationService.pinConversation(conversationID: convID, isPinned: isPined);
|
||||
_userProfile?.conversation!.isPinned = isPined;
|
||||
notifyListeners();
|
||||
return res;
|
||||
}
|
||||
|
||||
Future<List<V2TimFriendOperationResult>?> addToBlackList(bool shouldAdd, String userID) async {
|
||||
if (_lifeCycle?.shouldAddToBlockList != null && await _lifeCycle!.shouldAddToBlockList(userID) == false) {
|
||||
return null;
|
||||
}
|
||||
if (shouldAdd) {
|
||||
final res = await _friendshipServices.addToBlackList(userIDList: [userID]);
|
||||
if (res != null && res.isNotEmpty) {
|
||||
final result = res.first;
|
||||
if (result.resultCode == 0) {
|
||||
_shouldAddToBlackList = true;
|
||||
_friendType = 0;
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
return res;
|
||||
} else {
|
||||
final res = await _friendshipServices.deleteFromBlackList(userIDList: [userID]);
|
||||
if (res != null && res.isNotEmpty) {
|
||||
final result = res.first;
|
||||
if (result.resultCode == 0) {
|
||||
_shouldAddToBlackList = false;
|
||||
final checkFriend = await _friendshipServices
|
||||
.checkFriend(userIDList: [userID], checkType: FriendTypeEnum.V2TIM_FRIEND_TYPE_SINGLE);
|
||||
if (checkFriend != null) {
|
||||
final res = checkFriend.first;
|
||||
_friendType = res.resultType;
|
||||
}
|
||||
}
|
||||
}
|
||||
_friendShipViewModel.loadBlockListData();
|
||||
notifyListeners();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
Future<V2TimFriendOperationResult?> deleteFriend(String userID, {bool needUpdateData = true}) async {
|
||||
if (_lifeCycle?.shouldDeleteFriend != null && await _lifeCycle!.shouldDeleteFriend(userID) == false) {
|
||||
return null;
|
||||
}
|
||||
final res = await _friendshipServices
|
||||
.deleteFromFriendList(userIDList: [userID], deleteType: FriendTypeEnum.V2TIM_FRIEND_TYPE_BOTH);
|
||||
if (res != null) {
|
||||
_conversationService.deleteConversation(conversationID: "c2c_$userID");
|
||||
if (needUpdateData) {
|
||||
loadData(userID: userID);
|
||||
}
|
||||
return res.first;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<V2TimCallback> changeFriendVerificationMethod(int allowType) async {
|
||||
V2TimUserFullInfo userFullInfo = V2TimUserFullInfo();
|
||||
userFullInfo.allowType = allowType;
|
||||
final res = await _coreServices.setSelfInfo(userFullInfo: userFullInfo);
|
||||
if (res.code == 0) {
|
||||
_userProfile?.friendInfo!.userProfile!.allowType = allowType;
|
||||
notifyListeners();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Future<V2TimFriendOperationResult?> addFriend(String userID) async {
|
||||
if (_lifeCycle?.shouldAddFriend != null && await _lifeCycle!.shouldAddFriend(userID) == false) {
|
||||
return null;
|
||||
}
|
||||
final res = await _friendshipServices.addFriend(userID: userID, addType: FriendTypeEnum.V2TIM_FRIEND_TYPE_BOTH);
|
||||
if (res.code == 0) {
|
||||
loadData(userID: userID);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<V2TimCallback> updateRemarks(String userID, String remark) async {
|
||||
final res = await _friendshipServices.setFriendInfo(userID: userID, friendRemark: remark);
|
||||
|
||||
if (res.code == 0) {
|
||||
_userProfile?.friendInfo!.friendRemark = remark;
|
||||
notifyListeners();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Future<V2TimCallback> setMessageDisturb(String userID, bool isDisturb) async {
|
||||
final res = await _messageService.setC2CReceiveMessageOpt(
|
||||
userIDList: [userID],
|
||||
opt: isDisturb ? ReceiveMsgOptEnum.V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE : ReceiveMsgOptEnum.V2TIM_RECEIVE_MESSAGE);
|
||||
if (res.code == 0) {
|
||||
_isDisturb = isDisturb;
|
||||
}
|
||||
notifyListeners();
|
||||
return res;
|
||||
}
|
||||
|
||||
updateUserInfo(V2TimUserFullInfo userFullInfo) {
|
||||
if (userFullInfo.nickName != null) {
|
||||
_userProfile?.friendInfo!.userProfile?.nickName = userFullInfo.nickName;
|
||||
}
|
||||
if (userFullInfo.faceUrl != null) {
|
||||
_userProfile?.friendInfo!.userProfile?.faceUrl = userFullInfo.faceUrl;
|
||||
}
|
||||
if (userFullInfo.selfSignature != null) {
|
||||
_userProfile?.friendInfo!.userProfile?.selfSignature = userFullInfo.selfSignature;
|
||||
}
|
||||
if (userFullInfo.gender != null) {
|
||||
_userProfile?.friendInfo!.userProfile?.gender = userFullInfo.gender;
|
||||
}
|
||||
if (userFullInfo.allowType != null) {
|
||||
_userProfile?.friendInfo!.userProfile?.allowType = userFullInfo.allowType;
|
||||
}
|
||||
if (userFullInfo.customInfo != null) {
|
||||
_userProfile?.friendInfo!.userProfile?.customInfo = userFullInfo.customInfo;
|
||||
}
|
||||
if (userFullInfo.role != null) {
|
||||
_userProfile?.friendInfo!.userProfile?.role = userFullInfo.role;
|
||||
}
|
||||
if (userFullInfo.level != null) {
|
||||
_userProfile?.friendInfo!.userProfile?.level = userFullInfo.level;
|
||||
}
|
||||
if (userFullInfo.birthday != null) {
|
||||
_userProfile?.friendInfo!.userProfile?.birthday = userFullInfo.birthday;
|
||||
}
|
||||
}
|
||||
|
||||
Future<V2TimCallback> updateSelfInfo(V2TimUserFullInfo userFullInfo) async {
|
||||
final res = await _coreServices.setSelfInfo(userFullInfo: userFullInfo);
|
||||
|
||||
if (res.code == 0) {
|
||||
updateUserInfo(userFullInfo);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user