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
@@ -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