Browse Source

发消息修改

wr_202303
zsw 4 months ago
parent
commit
5ffe534883
  1. 2
      lib/im/SocketClient.dart
  2. 15
      lib/im/chat_details_page.dart
  3. 25
      lib/im/im_view/im_page.dart

2
lib/im/SocketClient.dart

@ -44,6 +44,7 @@ class SocketClient {
authRequest(shared.getString("token"));
heartbeat();
}).catchError((error) {
debugPrint("socket-connect-error: $error");
reconnectTime = 1500;
@ -54,6 +55,7 @@ class SocketClient {
heartbeat() {
Timer.periodic(const Duration(milliseconds: 3000), (timer) {
debugPrint("heartbeat: ${DateTime.now().millisecondsSinceEpoch}");
Uint8List data = utf8.encode(jsonEncode({"heartbeat": DateTime.now().millisecondsSinceEpoch}));
MsgData msgData = MsgData(to: "0", from: userId, type: MsgType.TEXT, data: data);
final proto2 = Proto(5, 1, msgData.writeToBuffer());

15
lib/im/chat_details_page.dart

@ -78,8 +78,17 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
messages = await hxDatabase.queryUList(_toUser.mid, pageSize: 100);
socketClient.addCallback(_toUser.mid, (Message message) {
messages.add(message);
messages.insert(0, message);
refreshState();
if (scrollController.position != null) {
double offset = scrollController.position.maxScrollExtent;
debugPrint("offset: $offset");
Future.delayed(const Duration(milliseconds: 500), () {
scrollController.animateTo(offset + 108, duration: const Duration(milliseconds: 500), curve: Curves.easeIn);
});
}
});
refreshState();
@ -820,7 +829,9 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
if (scrollController.position != null) {
double offset = scrollController.position.maxScrollExtent;
debugPrint("offset: $offset");
scrollController.animateTo(offset + 50, duration: const Duration(milliseconds: 500), curve: Curves.easeIn);
Future.delayed(const Duration(milliseconds: 500), () {
scrollController.animateTo(offset + 108, duration: const Duration(milliseconds: 500), curve: Curves.easeIn);
});
}
});

25
lib/im/im_view/im_page.dart

@ -93,14 +93,7 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
lastMessageMap[message.fromId] = message;
sortConversation(lastMessageMap);
debugPrint("messages_records : ${message.toJson()}");
if (contactMap[message.fromId] == null) {
queryMemberInfo([message.fromId]);
return;
}
refreshState();
listenerRefresh(message);
});
loadMessageList();
@ -112,6 +105,22 @@ class _IMPage extends State<IMPage> implements OnChatMessage {
// queryMsgStats();
}
listenerRefresh(Message message) async {
SharedPreferences shared = await SharedPreferences.getInstance();
String userId = shared.getString("userId");
await sortConversation(lastMessageMap);
await queryUnreadCount(userIds, userId);
debugPrint("messages_records : ${message.toJson()}");
if (contactMap[message.fromId] == null) {
queryMemberInfo([message.fromId]);
return;
}
refreshState();
}
loadMessageList() async {
SharedPreferences shared = await SharedPreferences.getInstance();
String userId = shared.getString("userId");

Loading…
Cancel
Save