fix(mobile-next): 把加载、失败、断网接到真实 SDK 与目录请求
会话列表、通讯录、好友申请、添加同事页覆盖 CompanyLoadingView/CompanyFailView; 主页断网横幅跟随 IMSdkStatus.connectionFailed。不伪造状态。 Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
co-authored by
Cursor
multica-agent
parent
092f513708
commit
2b2c2d28a4
@@ -14,10 +14,14 @@ class ContactsLogic extends GetxController
|
||||
final homeLogic = Get.find<HomeLogic>();
|
||||
|
||||
final friendApplicationList = <UserInfo>[];
|
||||
final loading = true.obs;
|
||||
final loadFailed = false.obs;
|
||||
|
||||
int get friendApplicationCount => homeLogic.unhandledFriendApplicationCount.value;
|
||||
int get friendApplicationCount =>
|
||||
homeLogic.unhandledFriendApplicationCount.value;
|
||||
|
||||
int get groupApplicationCount => homeLogic.unhandledGroupApplicationCount.value;
|
||||
int get groupApplicationCount =>
|
||||
homeLogic.unhandledGroupApplicationCount.value;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
@@ -28,6 +32,36 @@ class ContactsLogic extends GetxController
|
||||
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;
|
||||
@@ -69,7 +103,8 @@ class ContactsLogic extends GetxController
|
||||
);
|
||||
|
||||
@override
|
||||
viewUserProfile(String userID, String? nickname, String? faceURL, [String? groupID]) =>
|
||||
viewUserProfile(String userID, String? nickname, String? faceURL,
|
||||
[String? groupID]) =>
|
||||
AppNavigator.startUserProfilePane(
|
||||
userID: userID,
|
||||
nickname: nickname,
|
||||
@@ -85,5 +120,6 @@ class ContactsLogic extends GetxController
|
||||
);
|
||||
|
||||
@override
|
||||
scanOutUserID(String userID) => AppNavigator.startUserProfilePane(userID: userID, offAndToNamed: true);
|
||||
scanOutUserID(String userID) =>
|
||||
AppNavigator.startUserProfilePane(userID: userID, offAndToNamed: true);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:get/get.dart';
|
||||
import 'package:openim_common/openim_common.dart';
|
||||
|
||||
import '../../company/brand/app_tokens.dart';
|
||||
import '../../company/ui/state_views.dart';
|
||||
import 'contacts_logic.dart';
|
||||
|
||||
class ContactsPage extends StatelessWidget {
|
||||
@@ -19,12 +20,19 @@ class ContactsPage extends StatelessWidget {
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: logic.addContacts,
|
||||
icon: const Icon(Icons.person_add_alt, size: AppIconSize.md, color: AppColors.textPrimary),
|
||||
icon: const Icon(Icons.person_add_alt,
|
||||
size: AppIconSize.md, color: AppColors.textPrimary),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Obx(
|
||||
() => Column(
|
||||
body: Obx(() {
|
||||
if (logic.loading.value) {
|
||||
return const CompanyLoadingView();
|
||||
}
|
||||
if (logic.loadFailed.value) {
|
||||
return CompanyFailView(onRetry: logic.reload);
|
||||
}
|
||||
return Column(
|
||||
children: [
|
||||
_entry(
|
||||
icon: Icons.person_add_alt,
|
||||
@@ -44,8 +52,8 @@ class ContactsPage extends StatelessWidget {
|
||||
onTap: logic.myFriend,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,10 +79,13 @@ class ContactsPage extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(AppRadius.control),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Icon(icon, size: AppIconSize.sm, color: AppColors.primary),
|
||||
child:
|
||||
Icon(icon, size: AppIconSize.sm, color: AppColors.primary),
|
||||
),
|
||||
const SizedBox(width: AppGap.x3),
|
||||
Text(label, style: const TextStyle(fontSize: AppFont.body, color: AppColors.textPrimary)),
|
||||
Text(label,
|
||||
style: const TextStyle(
|
||||
fontSize: AppFont.body, color: AppColors.textPrimary)),
|
||||
const Spacer(),
|
||||
if (count > 0) UnreadCountView(count: count),
|
||||
],
|
||||
|
||||
@@ -11,6 +11,8 @@ class FriendRequestsLogic extends GetxController {
|
||||
final imLogic = Get.find<IMController>();
|
||||
final homeLogic = Get.find<HomeLogic>();
|
||||
final applicationList = <FriendApplicationInfo>[].obs;
|
||||
final loading = true.obs;
|
||||
final loadFailed = false.obs;
|
||||
late StreamSubscription faSub;
|
||||
|
||||
@override
|
||||
@@ -27,6 +29,8 @@ class FriendRequestsLogic extends GetxController {
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
void retry() => _getFriendRequestsList();
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
faSub.cancel();
|
||||
@@ -35,43 +39,56 @@ class FriendRequestsLogic extends GetxController {
|
||||
}
|
||||
|
||||
void _getFriendRequestsList() async {
|
||||
final list = await Future.wait([
|
||||
OpenIM.iMManager.friendshipManager.getFriendApplicationListAsRecipient(),
|
||||
OpenIM.iMManager.friendshipManager.getFriendApplicationListAsApplicant(),
|
||||
]);
|
||||
loading.value = true;
|
||||
loadFailed.value = false;
|
||||
try {
|
||||
final list = await Future.wait([
|
||||
OpenIM.iMManager.friendshipManager
|
||||
.getFriendApplicationListAsRecipient(),
|
||||
OpenIM.iMManager.friendshipManager
|
||||
.getFriendApplicationListAsApplicant(),
|
||||
]);
|
||||
|
||||
final allList = <FriendApplicationInfo>[];
|
||||
allList
|
||||
..addAll(list[0])
|
||||
..addAll(list[1]);
|
||||
final allList = <FriendApplicationInfo>[];
|
||||
allList
|
||||
..addAll(list[0])
|
||||
..addAll(list[1]);
|
||||
|
||||
allList.sort((a, b) {
|
||||
if (a.createTime! > b.createTime!) {
|
||||
return -1;
|
||||
} else if (a.createTime! < b.createTime!) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
allList.sort((a, b) {
|
||||
if (a.createTime! > b.createTime!) {
|
||||
return -1;
|
||||
} else if (a.createTime! < b.createTime!) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
var haveReadList = DataSp.getHaveReadUnHandleFriendApplication();
|
||||
haveReadList ??= <String>[];
|
||||
for (var e in list[0]) {
|
||||
var id = IMUtils.buildFriendApplicationID(e);
|
||||
if (!haveReadList.contains(id)) {
|
||||
haveReadList.add(id);
|
||||
var haveReadList = DataSp.getHaveReadUnHandleFriendApplication();
|
||||
haveReadList ??= <String>[];
|
||||
for (var e in list[0]) {
|
||||
var id = IMUtils.buildFriendApplicationID(e);
|
||||
if (!haveReadList.contains(id)) {
|
||||
haveReadList.add(id);
|
||||
}
|
||||
}
|
||||
DataSp.putHaveReadUnHandleFriendApplication(haveReadList);
|
||||
applicationList.assignAll(allList);
|
||||
} catch (e, s) {
|
||||
Logger.print('friend requests e: $e $s');
|
||||
loadFailed.value = true;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
DataSp.putHaveReadUnHandleFriendApplication(haveReadList);
|
||||
applicationList.assignAll(allList);
|
||||
}
|
||||
|
||||
bool isISendRequest(FriendApplicationInfo info) => info.fromUserID == OpenIM.iMManager.userID;
|
||||
bool isISendRequest(FriendApplicationInfo info) =>
|
||||
info.fromUserID == OpenIM.iMManager.userID;
|
||||
|
||||
void acceptFriendApplication(FriendApplicationInfo info) async {
|
||||
try {
|
||||
await LoadingView.singleton.wrap(
|
||||
asyncFunction: () => OpenIM.iMManager.friendshipManager.acceptFriendApplication(userID: info.fromUserID!),
|
||||
asyncFunction: () => OpenIM.iMManager.friendshipManager
|
||||
.acceptFriendApplication(userID: info.fromUserID!),
|
||||
);
|
||||
IMViews.showToast(StrRes.addSuccessfully);
|
||||
_getFriendRequestsList();
|
||||
@@ -83,7 +100,8 @@ class FriendRequestsLogic extends GetxController {
|
||||
void refuseFriendApplication(FriendApplicationInfo info) async {
|
||||
try {
|
||||
await LoadingView.singleton.wrap(
|
||||
asyncFunction: () => OpenIM.iMManager.friendshipManager.refuseFriendApplication(userID: info.fromUserID!),
|
||||
asyncFunction: () => OpenIM.iMManager.friendshipManager
|
||||
.refuseFriendApplication(userID: info.fromUserID!),
|
||||
);
|
||||
IMViews.showToast(StrRes.rejectSuccessfully);
|
||||
_getFriendRequestsList();
|
||||
|
||||
@@ -18,6 +18,12 @@ class FriendRequestsPage extends StatelessWidget {
|
||||
appBar: AppBar(title: const Text('新的同事')),
|
||||
backgroundColor: AppColors.pageBg,
|
||||
body: Obx(() {
|
||||
if (logic.loading.value) {
|
||||
return const CompanyLoadingView();
|
||||
}
|
||||
if (logic.loadFailed.value) {
|
||||
return CompanyFailView(onRetry: logic.retry);
|
||||
}
|
||||
if (logic.applicationList.isEmpty) {
|
||||
return const CompanyEmptyView(
|
||||
icon: Icons.person_outline,
|
||||
@@ -27,7 +33,8 @@ class FriendRequestsPage extends StatelessWidget {
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: logic.applicationList.length,
|
||||
itemBuilder: (_, index) => _buildItemView(logic.applicationList[index]),
|
||||
itemBuilder: (_, index) =>
|
||||
_buildItemView(logic.applicationList[index]),
|
||||
);
|
||||
}),
|
||||
);
|
||||
@@ -43,10 +50,12 @@ class FriendRequestsPage extends StatelessWidget {
|
||||
|
||||
return Container(
|
||||
constraints: const BoxConstraints(minHeight: 72),
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppGap.x4, vertical: AppGap.x3),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppGap.x4, vertical: AppGap.x3),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.pageBg,
|
||||
border: Border(bottom: BorderSide(color: AppColors.divider, width: 0.5)),
|
||||
border:
|
||||
Border(bottom: BorderSide(color: AppColors.divider, width: 0.5)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
@@ -61,21 +70,25 @@ class FriendRequestsPage extends StatelessWidget {
|
||||
name ?? '',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: AppFont.body, color: AppColors.textPrimary),
|
||||
style: const TextStyle(
|
||||
fontSize: AppFont.body, color: AppColors.textPrimary),
|
||||
),
|
||||
if (IMUtils.isNotNullEmptyStr(info.reqMsg))
|
||||
Text(
|
||||
info.reqMsg ?? '',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: AppFont.sub, color: AppColors.textSecondary),
|
||||
style: const TextStyle(
|
||||
fontSize: AppFont.sub, color: AppColors.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppGap.x2),
|
||||
if (waiting && isISendRequest)
|
||||
const Text('等待对方通过', style: TextStyle(fontSize: AppFont.sub, color: AppColors.textSecondary)),
|
||||
const Text('等待对方通过',
|
||||
style: TextStyle(
|
||||
fontSize: AppFont.sub, color: AppColors.textSecondary)),
|
||||
if (waiting && !isISendRequest)
|
||||
SizedBox(
|
||||
width: 132,
|
||||
@@ -87,11 +100,15 @@ class FriendRequestsPage extends StatelessWidget {
|
||||
style: OutlinedButton.styleFrom(
|
||||
minimumSize: const Size(0, 32),
|
||||
padding: EdgeInsets.zero,
|
||||
side: const BorderSide(color: AppColors.textSecondary, width: 0.5),
|
||||
side: const BorderSide(
|
||||
color: AppColors.textSecondary, width: 0.5),
|
||||
foregroundColor: AppColors.textPrimary,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(AppRadius.control)),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(AppRadius.control)),
|
||||
),
|
||||
child: const Text('拒绝', style: TextStyle(fontSize: AppFont.sub)),
|
||||
child: const Text('拒绝',
|
||||
style: TextStyle(fontSize: AppFont.sub)),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppGap.x2),
|
||||
@@ -102,16 +119,26 @@ class FriendRequestsPage extends StatelessWidget {
|
||||
minimumSize: const Size(0, 32),
|
||||
padding: EdgeInsets.zero,
|
||||
backgroundColor: AppColors.primary,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(AppRadius.control)),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(AppRadius.control)),
|
||||
),
|
||||
child: const Text('接受', style: TextStyle(fontSize: AppFont.sub, color: Colors.white)),
|
||||
child: const Text('接受',
|
||||
style: TextStyle(
|
||||
fontSize: AppFont.sub, color: Colors.white)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (agreed) const Text('已添加', style: TextStyle(fontSize: AppFont.sub, color: AppColors.textSecondary)),
|
||||
if (rejected) const Text('已拒绝', style: TextStyle(fontSize: AppFont.sub, color: AppColors.textSecondary)),
|
||||
if (agreed)
|
||||
const Text('已添加',
|
||||
style: TextStyle(
|
||||
fontSize: AppFont.sub, color: AppColors.textSecondary)),
|
||||
if (rejected)
|
||||
const Text('已拒绝',
|
||||
style: TextStyle(
|
||||
fontSize: AppFont.sub, color: AppColors.textSecondary)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user