Browse Source

socketclient

wr_202303
zsw 4 months ago
parent
commit
d684ecf625
  1. 7
      lib/im/SocketClient.dart
  2. 2
      lib/im/chat_details_page.dart
  3. 2
      lib/im/database/hx_database.dart

7
lib/im/SocketClient.dart

@ -33,7 +33,12 @@ class SocketClient {
Map<String, dynamic> messageMap = createMessage(userId, utf8.decode(dataResult.data), msgType: dataResult.type.value, userId: dataResult.from);
Message message = Message.fromJson(messageMap);
callbacks[userId]?.call(message); /// user self conversation callback
callbacks[dataResult.from]?.call(message); /// user conversation callback
if (callbacks[dataResult.from] != null) {
messageMap["state"] = 1;
message.state = 1;
callbacks[dataResult.from].call(message); /// user conversation callback
}
hxDatabase.insert(messageMap);

2
lib/im/chat_details_page.dart

@ -88,7 +88,7 @@ class _ChatDetailsPage extends State<ChatDetailsPage>
await refresh();
socketClient.addCallback(_toUser.mid, (Message message) {
messages.insert(0, message..state = 1);
messages.insert(0, message);
refreshState();
jumpToBottom();
});

2
lib/im/database/hx_database.dart

@ -24,7 +24,7 @@ class HxDatabase {
db.execute(
'CREATE TABLE IF NOT EXISTS `Message` (`id` INTEGER, `fromId` VARCHAR(20), `toId` VARCHAR(20), `replyId` VARCHAR(20), `content` TEXT, `attach` TEXT, `msgType` INTEGER, `time` VARCHAR(20), `state` INTEGER, `isDelete` INTEGER, PRIMARY KEY (`id`))');
db.execute(
'CREATE TABLE IF NOT EXISTS `ImUser` (`id` INTEGER, `mid` VARCHAR(20), `nickname` VARCHAR(20), `avatar` VARCHAR(200), `phone` VARCHAR(200), `isDelete` INTEGER, PRIMARY KEY (`id`))');
'CREATE TABLE IF NOT EXISTS `ImUser` (`id` INTEGER, `mid` VARCHAR(20), `nickname` VARCHAR(20), `avatar` VARCHAR(200), `phone` VARCHAR(200), `isDelete` INTEGER, `isTop` INTEGER, PRIMARY KEY (`id`))');
}, onConfigure: (database) async {
await database.execute('PRAGMA foreign_keys = ON');
try {

Loading…
Cancel
Save