处理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('开始获取会话列表数据'); logger.e('开始获取会话列表数据');
if (isFinished.value) { if (isFinished.value) {
// //
@ -37,12 +37,13 @@ class ChatController extends GetxController {
final List<ConversationViewModel> convList = res.data; final List<ConversationViewModel> convList = res.data;
for (var conv in convList) { for (var conv in convList) {
logger.w('基本会话: ${conv.conversation.toJson()}, 会话ID: ${conv.conversation.conversationID}'); logger.w('基本会话: ${conv.conversation.toLogString()}');
} }
chatList.addAll(convList); chatList.addAll(convList);
// noFriend才执行加载数据逻辑, // noFriend才执行加载数据逻辑,
final hasNoFriend = chatList.any((item) => item.conversation.conversationGroupList?.contains(myConversationType.ConversationType.noFriend.name) ?? false); final hasNoFriend = chatList.any((item) => item.conversation.conversationGroupList?.contains(myConversationType.ConversationType.noFriend.name) ?? false);
logger.e('开始构建陌生人入口是否包含noFriend?$hasNoFriend');
if (!hasNoFriend) { if (!hasNoFriend) {
getNoFriendData(); getNoFriendData();
} }
@ -55,6 +56,7 @@ class ChatController extends GetxController {
void getNoFriendData({V2TimConversation? csion}) async { void getNoFriendData({V2TimConversation? csion}) async {
// //
final hasNoFriend = chatList.any((item) => item.conversation.conversationGroupList?.contains(myConversationType.ConversationType.noFriend.name) ?? false); final hasNoFriend = chatList.any((item) => item.conversation.conversationGroupList?.contains(myConversationType.ConversationType.noFriend.name) ?? false);
logger.w('检测是否存在nofriend入口$hasNoFriend');
if (hasNoFriend) { if (hasNoFriend) {
// //
final ConversationViewModel matchItem = chatList.firstWhere( final ConversationViewModel matchItem = chatList.firstWhere(
@ -70,8 +72,7 @@ class ChatController extends GetxController {
matchItem.conversation.lastMessage = csion!.lastMessage; matchItem.conversation.lastMessage = csion!.lastMessage;
matchItem.conversation.unreadCount = unreadTotal.data; matchItem.conversation.unreadCount = unreadTotal.data;
chatList.refresh(); chatList.refresh();
return; } else {
}
// //
final res = await ImService.instance.getConversationListByFilter( final res = await ImService.instance.getConversationListByFilter(
filter: V2TimConversationFilter(conversationGroup: myConversationType.ConversationType.noFriend.name), filter: V2TimConversationFilter(conversationGroup: myConversationType.ConversationType.noFriend.name),
@ -110,6 +111,7 @@ class ChatController extends GetxController {
} }
} }
} }
}
/// getConversationListByFilter /// getConversationListByFilter
// void filterConversationList() async { // void filterConversationList() async {

View File

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

View File

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

View File

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

View File

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