From 77f769862e8b8cc09d86bbc70229c79332fcde0a Mon Sep 17 00:00:00 2001 From: jack ning Date: Wed, 8 Jun 2022 16:50:25 +0800 Subject: [PATCH] update --- bytedesk_demo/pubspec.yaml | 2 +- bytedesk_kefu/CHANGELOG.md | 4 ++ bytedesk_kefu/lib/model/message.dart | 7 +++ bytedesk_kefu/lib/model/thread.dart | 6 +++ .../lib/ui/chat/page/chat_kf_page.dart | 26 ++++++++--- .../lib/util/bytedesk_constants.dart | 44 +++++++++---------- bytedesk_kefu/pubspec.yaml | 2 +- 7 files changed, 60 insertions(+), 31 deletions(-) diff --git a/bytedesk_demo/pubspec.yaml b/bytedesk_demo/pubspec.yaml index 421879a..3b7446f 100644 --- a/bytedesk_demo/pubspec.yaml +++ b/bytedesk_demo/pubspec.yaml @@ -46,7 +46,7 @@ dependencies: # 请在ios/Podfile中添加:use_frameworks! vibration: ^1.7.3 # 在线客服 https://pub.dev/packages/bytedesk_kefu - bytedesk_kefu: ^1.3.2 + bytedesk_kefu: ^1.3.3 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. diff --git a/bytedesk_kefu/CHANGELOG.md b/bytedesk_kefu/CHANGELOG.md index 65815f1..ff1d6e2 100644 --- a/bytedesk_kefu/CHANGELOG.md +++ b/bytedesk_kefu/CHANGELOG.md @@ -1,5 +1,9 @@ # Upgrade Log +## 1.3.3 + +* optimize user experience + ## 1.3.2 * optimize user experience diff --git a/bytedesk_kefu/lib/model/message.dart b/bytedesk_kefu/lib/model/message.dart index 51439a3..7d79afa 100755 --- a/bytedesk_kefu/lib/model/message.dart +++ b/bytedesk_kefu/lib/model/message.dart @@ -79,6 +79,7 @@ class Message { // return Message( mid: json['mid'], + // topic: json['thread']['topic'], content: json['content'], imageUrl: json['imageUrl'], voiceUrl: json['voiceUrl'], @@ -112,6 +113,7 @@ class Message { // return Message( mid: json['mid'], + // topic: json['thread']['topic'], content: json['content'], imageUrl: json['imageUrl'], voiceUrl: json['voiceUrl'], @@ -150,6 +152,7 @@ class Message { // return Message( mid: json['mid'], + // topic: json['thread']['topic'], content: json['content'], imageUrl: json['imageUrl'], voiceUrl: json['voiceUrl'], @@ -169,7 +172,9 @@ class Message { answersJson: json['answers'].toString()); } + static Message fromJson(dynamic json) { + // List robotQaList = []; if (json['type'] == BytedeskConstants.MESSAGE_TYPE_ROBOT) { robotQaList = json['answers'] == null @@ -180,6 +185,7 @@ class Message { } return Message( mid: json['mid'], + // topic: json['thread']['topic'], content: json['content'], imageUrl: json['imageUrl'], voiceUrl: json['voiceUrl'], @@ -191,6 +197,7 @@ class Message { timestamp: json['createdAt'], client: json['client'], currentUid: SpUtil.getString(BytedeskConstants.uid), + thread: Thread.fromUnreadJson(json['thread']), answers: robotQaList, answersJson: json['answers'].toString()); } diff --git a/bytedesk_kefu/lib/model/thread.dart b/bytedesk_kefu/lib/model/thread.dart index b74ce3c..5ee7a19 100755 --- a/bytedesk_kefu/lib/model/thread.dart +++ b/bytedesk_kefu/lib/model/thread.dart @@ -236,6 +236,12 @@ class Thread extends Equatable { unreadVisitor: json['unreadVisitor']); } + static Thread fromUnreadJson(dynamic json) { + return Thread( + tid: json['tid'], + topic: json['topic']); + } + @override List get props => [topic!]; diff --git a/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart b/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart index 6d81382..8c60241 100755 --- a/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart +++ b/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart @@ -138,8 +138,8 @@ class _ChatKFPageState extends State // // 每隔 1 秒钟会调用一次,如果要结束调用 // // timer.cancel(); }); - BlocProvider.of(context) - ..add(LoadUnreadVisitorMessagesEvent(page: 0, size: 10)); + // BlocProvider.of(context) + // ..add(LoadUnreadVisitorMessagesEvent(page: 0, size: 10)); } // @@ -196,7 +196,10 @@ class _ChatKFPageState extends State }); // TODO: 加载本地历史消息 _getMessages(_page, _size); - // + // 加载未读消息 + BlocProvider.of(context) + ..add(LoadUnreadVisitorMessagesEvent(page: 0, size: 10)); + // 结果解析 if (state.threadResult.statusCode == 200 || state.threadResult.statusCode == 201) { BytedeskUtils.printLog('创建新会话'); @@ -385,9 +388,18 @@ class _ChatKFPageState extends State } } else if (state is LoadUnreadVisitorMessageSuccess) { // 插入历史聊天记录 - for (var i = 0; i < state.messageList!.length; i++) { - Message message = state.messageList![i]; - _appendMessage(message); + if (state.messageList!.length > 0) { + // for (var i = 0; i < state.messageList!.length; i++) { + for (var i = state.messageList!.length - 1; i >= 0; i--) { + Message message = state.messageList![i]; + // 本地持久化 + _messageProvider.insert(message); + // 界面显示 + _appendMessage(message); + // 发送已读回执 + _bdMqtt.sendReceiptReadMessage( + message.mid!, _currentThread!); + } } } }, @@ -1110,7 +1122,7 @@ class _ChatKFPageState extends State } if (message.status != BytedeskConstants.MESSAGE_STATUS_READ) { // 发送已读回执 - if (message.isSend == 0) { + if (message.isSend == 0 && _currentThread != null) { // BytedeskUtils.printLog('message.mid ${message.mid}'); // BytedeskUtils.printLog('_currentThread ${_currentThread!.tid}'); _bdMqtt.sendReceiptReadMessage(message.mid!, _currentThread!); diff --git a/bytedesk_kefu/lib/util/bytedesk_constants.dart b/bytedesk_kefu/lib/util/bytedesk_constants.dart index 9fb76c1..85bd7bc 100755 --- a/bytedesk_kefu/lib/util/bytedesk_constants.dart +++ b/bytedesk_kefu/lib/util/bytedesk_constants.dart @@ -8,17 +8,17 @@ class BytedeskConstants { // // TODO: 增加自定义服务器地址接口 // 公司debug - // static const bool isDebug = true; - // static const bool isSecure = false; - // static const bool isWebSocketWss = false; - // static const String webSocketWssUrl = 'wss://www.bytedesk.com/websocket'; - // static const String httpBaseUrl = 'http://' + mqttHost + ':8000'; - // static const String httpBaseUrlAndroid = 'http://' + mqttHost + ':8000'; - // static const String httpBaseUrliOS = 'http://' + mqttHost + ':8000'; - // static const String httpUploadUrl = 'http://' + mqttHost + ':8000'; - // static const String host = mqttHost + ':8000'; - // static const int mqttPort = 3883; // not secure - // static const String mqttHost = '172.20.10.7'; + static const bool isDebug = true; + static const bool isSecure = false; + static const bool isWebSocketWss = false; + static const String webSocketWssUrl = 'wss://www.bytedesk.com/websocket'; + static const String httpBaseUrl = 'http://' + mqttHost + ':8000'; + static const String httpBaseUrlAndroid = 'http://' + mqttHost + ':8000'; + static const String httpBaseUrliOS = 'http://' + mqttHost + ':8000'; + static const String httpUploadUrl = 'http://' + mqttHost + ':8000'; + static const String host = mqttHost + ':8000'; + static const int mqttPort = 3883; // not secure + static const String mqttHost = '172.16.0.78'; // 本机测试 // static const bool isDebug = true; @@ -48,17 +48,17 @@ class BytedeskConstants { // static const String mqttHost = '192.168.0.106'; // 线上 - static const bool isDebug = false; // false; - static const bool isSecure = true; // secure - static const bool isWebSocketWss = true; - static const String webSocketWssUrl = 'wss://' + mqttHost + '/websocket'; - static const int mqttPort = 13883; // secure - static const String httpBaseUrl = 'https://' + mqttHost; - static const String httpBaseUrlAndroid = 'https://' + mqttHost; - static const String httpBaseUrliOS = 'https://' + mqttHost; - static const String httpUploadUrl = 'https://upload.bytedesk.com'; - static const String host = mqttHost; - static const String mqttHost = 'flutter.bytedesk.com'; + // static const bool isDebug = false; // false; + // static const bool isSecure = true; // secure + // static const bool isWebSocketWss = true; + // static const String webSocketWssUrl = 'wss://' + mqttHost + '/websocket'; + // static const int mqttPort = 13883; // secure + // static const String httpBaseUrl = 'https://' + mqttHost; + // static const String httpBaseUrlAndroid = 'https://' + mqttHost; + // static const String httpBaseUrliOS = 'https://' + mqttHost; + // static const String httpUploadUrl = 'https://upload.bytedesk.com'; + // static const String host = mqttHost; + // static const String mqttHost = 'flutter.bytedesk.com'; // static const String WORKGROUP_WID_LIANGSHIBAO = '201808101819291'; diff --git a/bytedesk_kefu/pubspec.yaml b/bytedesk_kefu/pubspec.yaml index 8db145d..1623d0f 100644 --- a/bytedesk_kefu/pubspec.yaml +++ b/bytedesk_kefu/pubspec.yaml @@ -1,6 +1,6 @@ name: bytedesk_kefu description: the best app chat sdk in china, you can chat with the agent freely at anytime. the agent can chat with the visitor by web/pc/mac/ios/android client. -version: 1.3.2 +version: 1.3.3 homepage: https://www.weikefu.net environment: