处理push和chat SDK在安卓端异常问题

This commit is contained in:
abu 2025-08-26 21:21:59 +08:00
parent d89bbf3086
commit 535465474b
5 changed files with 67 additions and 63 deletions

View File

@ -20,7 +20,7 @@ class ChatController extends GetxController {
}
//
void getConversationList() async {
Future<void> getConversationList() async {
logger.e('开始获取会话列表数据');
if (isFinished.value) {
//
@ -37,12 +37,13 @@ class ChatController extends GetxController {
final List<ConversationViewModel> convList = res.data;
for (var conv in convList) {
logger.w('基本会话: ${conv.conversation.toJson()}, 会话ID: ${conv.conversation.conversationID}');
logger.w('基本会话: ${conv.conversation.toLogString()}');
}
chatList.addAll(convList);
// noFriend才执行加载数据逻辑,
final hasNoFriend = chatList.any((item) => item.conversation.conversationGroupList?.contains(myConversationType.ConversationType.noFriend.name) ?? false);
logger.e('开始构建陌生人入口是否包含noFriend?$hasNoFriend');
if (!hasNoFriend) {
getNoFriendData();
}
@ -55,6 +56,7 @@ class ChatController extends GetxController {
void getNoFriendData({V2TimConversation? csion}) async {
//
final hasNoFriend = chatList.any((item) => item.conversation.conversationGroupList?.contains(myConversationType.ConversationType.noFriend.name) ?? false);
logger.w('检测是否存在nofriend入口$hasNoFriend');
if (hasNoFriend) {
//
final ConversationViewModel matchItem = chatList.firstWhere(
@ -70,42 +72,42 @@ class ChatController extends GetxController {
matchItem.conversation.lastMessage = csion!.lastMessage;
matchItem.conversation.unreadCount = unreadTotal.data;
chatList.refresh();
return;
}
//
final res = await ImService.instance.getConversationListByFilter(
filter: V2TimConversationFilter(conversationGroup: myConversationType.ConversationType.noFriend.name),
nextSeq: 0,
count: 1,
);
if (res.success && res.data != null) {
final convList = res.data!.conversationList ?? [];
if (convList.isNotEmpty) {
// logger.i(res.data!.toJson());
// 1.2.converstaionviewmodel
final unread = await ImService.instance.getUnreadMessageCountByFilter(
filter: V2TimConversationFilter(
conversationGroup: myConversationType.ConversationType.noFriend.name,
hasUnreadCount: true,
),
);
if (unread.success) {
final conv = convList.first;
final faceUrl = 'assets/images/notify/msr.png';
conv.showName = '陌生人消息';
conv.unreadCount = unread.data;
final createItem = ConversationViewModel(
conversation: conv,
faceUrl: faceUrl,
} else {
//
final res = await ImService.instance.getConversationListByFilter(
filter: V2TimConversationFilter(conversationGroup: myConversationType.ConversationType.noFriend.name),
nextSeq: 0,
count: 1,
);
if (res.success && res.data != null) {
final convList = res.data!.conversationList ?? [];
if (convList.isNotEmpty) {
// logger.i(res.data!.toJson());
// 1.2.converstaionviewmodel
final unread = await ImService.instance.getUnreadMessageCountByFilter(
filter: V2TimConversationFilter(
conversationGroup: myConversationType.ConversationType.noFriend.name,
hasUnreadCount: true,
),
);
final newList = List<ConversationViewModel>.from(chatList);
newList.add(createItem);
newList.sort((a, b) {
final atime = a.conversation.lastMessage?.timestamp ?? 0;
final btime = b.conversation.lastMessage?.timestamp ?? 0;
return btime.compareTo(atime); //
});
chatList.value = newList;
if (unread.success) {
final conv = convList.first;
final faceUrl = 'assets/images/notify/msr.png';
conv.showName = '陌生人消息';
conv.unreadCount = unread.data;
final createItem = ConversationViewModel(
conversation: conv,
faceUrl: faceUrl,
);
final newList = List<ConversationViewModel>.from(chatList);
newList.add(createItem);
newList.sort((a, b) {
final atime = a.conversation.lastMessage?.timestamp ?? 0;
final btime = b.conversation.lastMessage?.timestamp ?? 0;
return btime.compareTo(atime); //
});
chatList.value = newList;
}
}
}
}

View File

@ -8,8 +8,7 @@ class ImUserInfoController extends GetxController {
@override
void onInit() {
super.onInit();
refreshUserInfo();
logger.i('IM用户信息初始化');
logger.i('开始IM用户信息初始化');
}
V2TimUserFullInfo? rawUserInfo;
@ -52,7 +51,7 @@ class ImUserInfoController extends GetxController {
birthday.value = userInfo.birthday ?? 0;
}
void refreshUserInfo() async {
Future<void> refreshUserInfo() async {
try {
final updatedUserInfo = await ImService.instance.selfInfo();
if (updatedUserInfo.success) {

View File

@ -38,7 +38,7 @@ class GlobalBadge extends GetxController {
onConversationChanged: (List<V2TimConversation> conversationList) async {
logger.w('会话变更:会话分组:${conversationList.first.conversationGroupList},会话内容${conversationList.first.toLogString()}');
final ctl = Get.find<ChatController>();
logger.w('当前会话列表内容:${ctl.chatList.toJson()}');
logger.w('当前会话列表内容:${ctl.chatList.length}');
final updatedIds = conversationList.map((e) => e.conversationID).toSet();
logger.w('要变更的会话id$updatedIds');
@ -88,8 +88,8 @@ class GlobalBadge extends GetxController {
ctl.chatList.refresh();
},
);
final ctl = Get.find<ChatController>();
ctl.getConversationList();
// final ctl = Get.find<ChatController>();
// ctl.getConversationList();
_initUnreadCount();
_addListener();
}

View File

@ -63,19 +63,20 @@ class ImService {
if (result.success) {
logger.i("IM 登录成功:$userID");
// push服务
PushService().initPush(
sdkAppId: 1600080789,
appKey: 'vkFpe55aYqfV7Sk5uGaoxhEstJ3tcI9dquk7JwG1GloDSLD2HeMWeQweWWXgNlhC',
);
// SDK
//
final ctl = Get.find<ChatController>();
await ctl.getConversationList();
/// SDK
await Wxsdk.init();
// (+)
if (!Get.isRegistered<ImUserInfoController>()) {
Get.put(ImUserInfoController(), permanent: true);
final imInfo = Get.put(ImUserInfoController(), permanent: true);
await imInfo.refreshUserInfo();
} else {
Get.find<ImUserInfoController>().refreshUserInfo();
await Get.find<ImUserInfoController>().refreshUserInfo();
}
//
@ -91,6 +92,12 @@ class ImService {
///
Get.put(GlobalBadge(), permanent: true);
// push服务
PushService().initPush(
sdkAppId: 1600080789,
appKey: 'vkFpe55aYqfV7Sk5uGaoxhEstJ3tcI9dquk7JwG1GloDSLD2HeMWeQweWWXgNlhC',
);
} else {
logger.i("IM 登录失败:${result.code} - ${result.desc}");
Get.snackbar(

View File

@ -325,6 +325,10 @@ class ChatPageState extends State<ChatPage> {
physics: BouncingScrollPhysics(),
itemCount: chatList.length,
itemBuilder: (context, index) {
final isNoFriend = chatList[index].conversation.conversationGroupList?.contains(ConversationType.noFriend.name) ?? false;
final isAdmin = chatList[index].isCustomAdmin != null && chatList[index].isCustomAdmin != '0';
logger.e(chatList[index].isCustomAdmin);
return Ink(
// color: chatList[index]['topMost'] == null ? Colors.white : Colors.grey[100], //
child: InkWell(
@ -351,14 +355,8 @@ class ChatPageState extends State<ChatPage> {
Text(
chatList[index].conversation.showName ?? '未知',
style: TextStyle(
fontSize: (chatList[index].conversation.conversationGroupList!.contains(ConversationType.noFriend.name)) ||
chatList[index].isCustomAdmin != '0'
? 20
: 16,
fontWeight: (chatList[index].conversation.conversationGroupList!.contains(ConversationType.noFriend.name)) ||
chatList[index].isCustomAdmin != '0'
? FontWeight.bold
: FontWeight.normal),
fontSize: (isAdmin || isNoFriend) ? 20 : 16,
fontWeight: (isAdmin || isNoFriend) ? FontWeight.bold : FontWeight.normal),
),
const SizedBox(height: 2.0),
Text(
@ -377,8 +375,7 @@ class ChatPageState extends State<ChatPage> {
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Visibility(
visible: !(chatList[index].isCustomAdmin != '0' ||
chatList[index].conversation.conversationGroupList!.contains(ConversationType.noFriend.name)),
visible: !(isAdmin || isNoFriend),
child: Text(
//
DateTime.fromMillisecondsSinceEpoch(
@ -396,8 +393,7 @@ class ChatPageState extends State<ChatPage> {
],
),
Visibility(
visible: chatList[index].isCustomAdmin != '0' ||
chatList[index].conversation.conversationGroupList!.contains(ConversationType.noFriend.name),
visible: (isAdmin || isNoFriend),
child: const Icon(
Icons.arrow_forward_ios,
color: Colors.blueGrey,