Files
tongxunruanjian/mobile-next/lib/pages/contacts/contacts_logic.dart
T
2b2c2d28a4 fix(mobile-next): 把加载、失败、断网接到真实 SDK 与目录请求
会话列表、通讯录、好友申请、添加同事页覆盖 CompanyLoadingView/CompanyFailView;
主页断网横幅跟随 IMSdkStatus.connectionFailed。不伪造状态。

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: multica-agent <github@multica.ai>
2026-08-20 02:52:24 +08:00

126 lines
3.5 KiB
Dart

import 'package:flutter_openim_sdk/flutter_openim_sdk.dart';
import 'package:get/get.dart';
import 'package:openim/pages/contacts/group_profile_panel/group_profile_panel_logic.dart';
import 'package:openim/routes/app_navigator.dart';
import 'package:openim_common/openim_common.dart';
import '../../core/controller/im_controller.dart';
import '../home/home_logic.dart';
import 'select_contacts/select_contacts_logic.dart';
class ContactsLogic extends GetxController
implements ViewUserProfileBridge, SelectContactsBridge, ScanBridge {
final imLogic = Get.find<IMController>();
final homeLogic = Get.find<HomeLogic>();
final friendApplicationList = <UserInfo>[];
final loading = true.obs;
final loadFailed = false.obs;
int get friendApplicationCount =>
homeLogic.unhandledFriendApplicationCount.value;
int get groupApplicationCount =>
homeLogic.unhandledGroupApplicationCount.value;
@override
void onInit() {
PackageBridge.selectContactsBridge = this;
PackageBridge.viewUserProfileBridge = this;
PackageBridge.scanBridge = this;
super.onInit();
}
@override
void onReady() {
reload();
super.onReady();
}
Future<void> reload() async {
loading.value = true;
loadFailed.value = false;
try {
await Future.wait([
OpenIM.iMManager.friendshipManager
.getFriendApplicationListAsRecipient(),
OpenIM.iMManager.groupManager.getGroupApplicationListAsRecipient(),
OpenIM.iMManager.friendshipManager.getFriendListPage(
offset: 0,
count: 1,
filterBlack: true,
),
]);
homeLogic.getUnhandledFriendApplicationCount();
homeLogic.getUnhandledGroupApplicationCount();
} catch (e, s) {
Logger.print('contacts reload e: $e $s');
loadFailed.value = true;
} finally {
loading.value = false;
}
}
@override
void onClose() {
PackageBridge.selectContactsBridge = null;
PackageBridge.viewUserProfileBridge = null;
PackageBridge.scanBridge = null;
super.onClose();
}
void newFriend() => AppNavigator.startFriendRequests();
void newGroup() => AppNavigator.startGroupRequests();
void myFriend() => AppNavigator.startFriendList();
void myGroup() => AppNavigator.startGroupList();
void searchContacts() => AppNavigator.startGlobalSearch();
void addContacts() => AppNavigator.startAddColleague();
@override
Future<T?>? selectContacts<T>(
int type, {
List<String>? defaultCheckedIDList,
List? checkedList,
List<String>? excludeIDList,
bool openSelectedSheet = false,
String? groupID,
String? ex,
}) =>
AppNavigator.startSelectContacts(
action: SelAction.values[type],
defaultCheckedIDList: defaultCheckedIDList,
checkedList: checkedList,
excludeIDList: excludeIDList,
openSelectedSheet: openSelectedSheet,
groupID: groupID,
ex: ex,
);
@override
viewUserProfile(String userID, String? nickname, String? faceURL,
[String? groupID]) =>
AppNavigator.startUserProfilePane(
userID: userID,
nickname: nickname,
faceURL: faceURL,
groupID: groupID,
);
@override
scanOutGroupID(String groupID) => AppNavigator.startGroupProfilePanel(
groupID: groupID,
joinGroupMethod: JoinGroupMethod.qrcode,
offAndToNamed: true,
);
@override
scanOutUserID(String userID) =>
AppNavigator.startUserProfilePane(userID: userID, offAndToNamed: true);
}