fix(mobile): 通讯录进会话空对方 + 登录后会话列表空态(B-52 无法发送消息根因)
- contacts_screen 用 f.friendUserID(SDK 恒为空)打开会话,导致建出 si__<空对方> 会话,所有消息发给空 userID 全部失败;改用 f.userID - login 后补一次 refreshConversations:SDK 登录期间同步回调先于 loggedIn=true 触发,refreshConversations 因登录态守卫提前返回, 会话列表永久停在空态 双机实测:修复前 sendMessage userID='' 失败;修复后 A→B 消息 正常送达(B 端 onRecvNewMessage 收到 fixverify999) Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -238,7 +238,7 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
|
||||
String _displayName(FriendInfo f) {
|
||||
if (f.remark?.isNotEmpty == true) return f.remark!;
|
||||
return f.nickname ?? f.friendUserID ?? '';
|
||||
return f.nickname ?? f.userID ?? f.friendUserID ?? '';
|
||||
}
|
||||
|
||||
Widget _contactTile(FriendInfo f) {
|
||||
@@ -254,11 +254,21 @@ class _ContactsScreenState extends State<ContactsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 点联系人直接进单聊
|
||||
/// 点联系人直接进单聊。
|
||||
/// 注意:OpenIM 好友接口返回的字段是 `userID`(`friendUserID` 恒为空),
|
||||
/// 必须用 `userID` 作为会话源,否则会建出「空对方」会话导致所有消息发不出去。
|
||||
Future<void> _openChat(FriendInfo f, String name) async {
|
||||
final peerID = f.userID ?? f.friendUserID ?? '';
|
||||
if (peerID.isEmpty) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('对方信息不完整,无法打开会话'), duration: Duration(seconds: 2)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final conversation = await OpenIM.iMManager.conversationManager.getOneConversation(
|
||||
sourceID: f.friendUserID ?? '',
|
||||
sourceID: peerID,
|
||||
sessionType: ConversationType.single,
|
||||
);
|
||||
conversation.showName = name;
|
||||
|
||||
@@ -253,6 +253,9 @@ class IMService extends ChangeNotifier {
|
||||
selfInfo = user;
|
||||
loggedIn = true;
|
||||
notifyListeners();
|
||||
// SDK 登录期间会话同步回调可能先于 loggedIn=true 触发,refreshConversations
|
||||
// 会因登录态守卫而提前返回,导致会话列表停在空态。登录完成后主动补一次刷新。
|
||||
await refreshConversations();
|
||||
}
|
||||
|
||||
/// 刷新自己的资料(我的页面展示用)
|
||||
|
||||
Reference in New Issue
Block a user