feat(mobile-next): 通讯录按部门分组并补齐职务行与申请窄屏

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
编码工程师
2026-08-20 03:51:27 +08:00
co-authored by Cursor multica-agent
parent 7f131457f7
commit 49b346d375
3 changed files with 294 additions and 106 deletions
@@ -4,18 +4,45 @@ import 'package:openim/pages/contacts/group_profile_panel/group_profile_panel_lo
import 'package:openim/routes/app_navigator.dart';
import 'package:openim_common/openim_common.dart';
import '../../company/directory/directory_api.dart';
import '../../core/controller/im_controller.dart';
import '../home/home_logic.dart';
import 'select_contacts/select_contacts_logic.dart';
class ColleagueRow {
ColleagueRow({
required this.userID,
required this.nickname,
required this.faceURL,
required this.department,
required this.title,
});
final String userID;
final String nickname;
final String faceURL;
final String department;
final String title;
String get subtitle {
if (title.isNotEmpty && department.isNotEmpty) {
return '$title · $department';
}
if (title.isNotEmpty) return title;
return department;
}
}
class ContactsLogic extends GetxController
implements ViewUserProfileBridge, SelectContactsBridge, ScanBridge {
final imLogic = Get.find<IMController>();
final homeLogic = Get.find<HomeLogic>();
final _directory = DirectoryApi();
final friendApplicationList = <UserInfo>[];
final loading = true.obs;
final loadFailed = false.obs;
final colleagues = <ColleagueRow>[].obs;
int get friendApplicationCount =>
homeLogic.unhandledFriendApplicationCount.value;
@@ -23,6 +50,21 @@ class ContactsLogic extends GetxController
int get groupApplicationCount =>
homeLogic.unhandledGroupApplicationCount.value;
Map<String, List<ColleagueRow>> get groupedColleagues {
final map = <String, List<ColleagueRow>>{};
for (final row in colleagues) {
final key = row.department.isEmpty ? '未分组' : row.department;
map.putIfAbsent(key, () => []).add(row);
}
final keys = map.keys.toList()
..sort((a, b) {
if (a == '未分组') return 1;
if (b == '未分组') return -1;
return a.compareTo(b);
});
return {for (final k in keys) k: map[k]!};
}
@override
void onInit() {
PackageBridge.selectContactsBridge = this;
@@ -46,11 +88,7 @@ class ContactsLogic extends GetxController
OpenIM.iMManager.friendshipManager
.getFriendApplicationListAsRecipient(),
OpenIM.iMManager.groupManager.getGroupApplicationListAsRecipient(),
OpenIM.iMManager.friendshipManager.getFriendListPage(
offset: 0,
count: 1,
filterBlack: true,
),
_loadColleagues(),
]);
homeLogic.getUnhandledFriendApplicationCount();
homeLogic.getUnhandledGroupApplicationCount();
@@ -62,6 +100,47 @@ class ContactsLogic extends GetxController
}
}
Future<void> _loadColleagues() async {
final friends = <FriendInfo>[];
const page = 1000;
while (true) {
final temp = await OpenIM.iMManager.friendshipManager.getFriendListPage(
offset: friends.length,
count: page,
filterBlack: true,
);
friends.addAll(temp);
if (temp.length < page) break;
}
var dirById = <String, DirectoryUser>{};
try {
final items = await _directory.search(keyword: '', limit: 100);
dirById = {for (final e in items) e.userID: e};
} catch (e, s) {
Logger.print('contacts directory e: $e $s');
}
colleagues.assignAll(friends.where((e) => e.userID != null).map((e) {
final dir = dirById[e.userID];
return ColleagueRow(
userID: e.userID!,
nickname: (e.remark?.isNotEmpty == true)
? e.remark!
: (e.nickname?.isNotEmpty == true ? e.nickname! : e.userID!),
faceURL: e.faceURL ?? dir?.faceURL ?? '',
department: dir?.department ?? '',
title: dir?.title ?? '',
);
}));
}
void openColleague(ColleagueRow row) => AppNavigator.startUserProfilePane(
userID: row.userID,
nickname: row.nickname,
faceURL: row.faceURL,
);
@override
void onClose() {
PackageBridge.selectContactsBridge = null;