处理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('开始获取会话列表数据');
|
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 {
|
||||||
|
@ -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) {
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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(
|
||||||
|
@ -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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user