处理push和chat SDK在安卓端异常问题
This commit is contained in:
parent
d89bbf3086
commit
535465474b
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user