diff --git a/bytedesk_demo/pubspec.yaml b/bytedesk_demo/pubspec.yaml index 0f06cbe..421879a 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.1 + bytedesk_kefu: ^1.3.2 # 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 3a2ec34..65815f1 100644 --- a/bytedesk_kefu/CHANGELOG.md +++ b/bytedesk_kefu/CHANGELOG.md @@ -1,5 +1,9 @@ # Upgrade Log +## 1.3.2 + +* optimize user experience + ## 1.3.1 * optimize user experience diff --git a/bytedesk_kefu/example/lib/page/history_thread_page.dart b/bytedesk_kefu/example/lib/page/history_thread_page.dart index 339e099..a0d2cd4 100755 --- a/bytedesk_kefu/example/lib/page/history_thread_page.dart +++ b/bytedesk_kefu/example/lib/page/history_thread_page.dart @@ -41,8 +41,9 @@ class _HistoryThreadPageState extends State { subtitle: Text('${_historyThreadList[index].content}'), onTap: () { // 进入客服页面 - BytedeskKefu.startChatThread( - context, _historyThreadList[index]); + // BytedeskKefu.startChatThread( + // context, _historyThreadList[index]); + BytedeskKefu.startChatThreadIM(context, _historyThreadList[index]); }, ), itemCount: _historyThreadList.length, diff --git a/bytedesk_kefu/lib/blocs/contact_bloc/contact_bloc.dart b/bytedesk_kefu/lib/blocs/contact_bloc/contact_bloc.dart index e9e3e03..12d8fa9 100755 --- a/bytedesk_kefu/lib/blocs/contact_bloc/contact_bloc.dart +++ b/bytedesk_kefu/lib/blocs/contact_bloc/contact_bloc.dart @@ -2,6 +2,7 @@ import 'package:bloc/bloc.dart'; import 'package:bytedesk_kefu/blocs/contact_bloc/bloc.dart'; import 'package:bytedesk_kefu/repositories/contact_repository.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; class ContactBloc extends Bloc { final ContactRepository contactRepository = new ContactRepository(); @@ -27,7 +28,7 @@ class ContactBloc extends Bloc { // final List contactList = await contactRepository.getContacts(); // yield ContactLoadSuccess(contactList); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ContactLoadError()); } } diff --git a/bytedesk_kefu/lib/blocs/feedback_bloc/feedback_bloc.dart b/bytedesk_kefu/lib/blocs/feedback_bloc/feedback_bloc.dart index 34a508b..2088b9b 100755 --- a/bytedesk_kefu/lib/blocs/feedback_bloc/feedback_bloc.dart +++ b/bytedesk_kefu/lib/blocs/feedback_bloc/feedback_bloc.dart @@ -2,6 +2,7 @@ import 'package:bytedesk_kefu/blocs/feedback_bloc/bloc.dart'; import 'package:bytedesk_kefu/model/helpCategory.dart'; // import 'package:bytedesk_kefu/model/jsonResult.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; import 'package:bytedesk_kefu/repositories/feedback_repository.dart'; import 'package:bloc/bloc.dart'; @@ -36,7 +37,7 @@ class FeedbackBloc extends Bloc { await feedbackRepository.getHelpFeedbackCategories(event.uid); emit(FeedbackCategoryState(categoryList)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(FeedbackLoadError()); } } @@ -48,18 +49,19 @@ class FeedbackBloc extends Bloc { await feedbackRepository.submitFeedback(event.content, event.imageUrls); emit(FeedbackSubmitSuccess()); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(FeedbackSubmitError()); } } - void _mapUploadImageToState(UploadImageEvent event, Emitter emit) async { + void _mapUploadImageToState( + UploadImageEvent event, Emitter emit) async { emit(ImageUploading()); try { final String url = await feedbackRepository.upload(event.filePath); emit(UploadImageSuccess(url)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } diff --git a/bytedesk_kefu/lib/blocs/friend_bloc/friend_bloc.dart b/bytedesk_kefu/lib/blocs/friend_bloc/friend_bloc.dart index edb9c28..b4e2c3c 100755 --- a/bytedesk_kefu/lib/blocs/friend_bloc/friend_bloc.dart +++ b/bytedesk_kefu/lib/blocs/friend_bloc/friend_bloc.dart @@ -2,6 +2,7 @@ import 'package:bloc/bloc.dart'; import 'package:bytedesk_kefu/blocs/friend_bloc/bloc.dart'; import 'package:bytedesk_kefu/model/friend.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; import 'package:bytedesk_kefu/repositories/friend_repository.dart'; class FriendBloc extends Bloc { @@ -31,14 +32,15 @@ class FriendBloc extends Bloc { // } // } - void _mapQueryFriendToState(QueryFriendEvent event, Emitter emit) async { + void _mapQueryFriendToState( + QueryFriendEvent event, Emitter emit) async { emit(FriendLoading()); try { final List friendList = await friendRepository.getFriends(event.page, event.size); emit(FriendLoadSuccess(friendList)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ErrorFriendState('friend error')); } } @@ -51,7 +53,7 @@ class FriendBloc extends Bloc { await friendRepository.getFriendsAddress(event.page, event.size); emit(FriendLoadSuccess(friendList)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ErrorFriendState('friend error')); } } @@ -64,7 +66,7 @@ class FriendBloc extends Bloc { await friendRepository.uploadAddress(event.nickname, event.mobile); emit(FriendCreateSuccess(friend: friend)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ErrorFriendState('friend error')); } } @@ -77,7 +79,7 @@ class FriendBloc extends Bloc { await friendRepository.getFriendsNearby(event.page, event.size); emit(FriendLoadSuccess(friendList)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ErrorFriendState('friend error')); } } @@ -89,7 +91,7 @@ class FriendBloc extends Bloc { await friendRepository.updateLocation(event.latitude, event.longtitude); emit(FriendUpdateSuccess()); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ErrorFriendState('friend error')); } } diff --git a/bytedesk_kefu/lib/blocs/help_bloc/help_bloc.dart b/bytedesk_kefu/lib/blocs/help_bloc/help_bloc.dart index fb16b23..1bb47bd 100755 --- a/bytedesk_kefu/lib/blocs/help_bloc/help_bloc.dart +++ b/bytedesk_kefu/lib/blocs/help_bloc/help_bloc.dart @@ -3,6 +3,7 @@ import 'package:bytedesk_kefu/blocs/help_bloc/bloc.dart'; import 'package:bytedesk_kefu/model/helpArticle.dart'; import 'package:bytedesk_kefu/model/helpCategory.dart'; import 'package:bytedesk_kefu/repositories/help_repository.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; import 'package:bloc/bloc.dart'; class HelpBloc extends Bloc { @@ -31,7 +32,7 @@ class HelpBloc extends Bloc { await helpRepository.getHelpCategories(event.uid); emit(HelpCategoryState(categoryList)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(HelpLoadError()); } } @@ -44,7 +45,7 @@ class HelpBloc extends Bloc { await helpRepository.getCategoryArticles(event.categoryId); emit(HelpArticleState(categoryList)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(HelpLoadError()); } } diff --git a/bytedesk_kefu/lib/blocs/leavemsg_bloc/leavemsg_bloc.dart b/bytedesk_kefu/lib/blocs/leavemsg_bloc/leavemsg_bloc.dart index 5b67632..9681456 100755 --- a/bytedesk_kefu/lib/blocs/leavemsg_bloc/leavemsg_bloc.dart +++ b/bytedesk_kefu/lib/blocs/leavemsg_bloc/leavemsg_bloc.dart @@ -2,6 +2,7 @@ import 'package:bytedesk_kefu/blocs/leavemsg_bloc/bloc.dart'; import 'package:bloc/bloc.dart'; import 'package:bytedesk_kefu/repositories/leavemsg_repository.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; class LeaveMsgBloc extends Bloc { // @@ -27,21 +28,23 @@ class LeaveMsgBloc extends Bloc { SubmitLeaveMsgEvent event, Emitter emit) async { emit(LeaveMsgSubmiting()); try { - await leaveMsgRepository.submitLeaveMsg(event.wid, event.aid, event.type, event.mobile, event.email, event.content); + await leaveMsgRepository.submitLeaveMsg(event.wid, event.aid, event.type, + event.mobile, event.email, event.content); emit(LeaveMsgSubmitSuccessState()); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(LeaveMsgSubmitError()); } } - void _mapUploadImageToState(UploadImageEvent event, Emitter emit) async { + void _mapUploadImageToState( + UploadImageEvent event, Emitter emit) async { emit(ImageUploading()); try { final String url = await leaveMsgRepository.upload(event.filePath); emit(UploadImageSuccess(url)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } diff --git a/bytedesk_kefu/lib/blocs/message_bloc/message_bloc.dart b/bytedesk_kefu/lib/blocs/message_bloc/message_bloc.dart index 2ebb095..d051bf9 100755 --- a/bytedesk_kefu/lib/blocs/message_bloc/message_bloc.dart +++ b/bytedesk_kefu/lib/blocs/message_bloc/message_bloc.dart @@ -5,6 +5,7 @@ import 'package:bytedesk_kefu/model/requestAnswer.dart'; import 'package:bytedesk_kefu/model/requestCategory.dart'; import 'package:bytedesk_kefu/model/uploadJsonResult.dart'; import 'package:bytedesk_kefu/repositories/message_repository.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; import 'package:bloc/bloc.dart'; import './bloc.dart'; @@ -18,6 +19,9 @@ class MessageBloc extends Bloc { on(_mapUploadVideoToState); on(_mapSendMessageRestToState); on(_mapLoadHistoryMessageToState); + on(_mapLoadUnreadMessageToState); + on(_mapLoadUnreadVisitorMessageToState); + on(_mapLoadUnreadAgentMessageToState); on(_mapLoadTopicMessageToState); on(_mapLoadChannelMessageToState); @@ -52,95 +56,143 @@ class MessageBloc extends Bloc { // } // } - void _mapRefreshCourseToState(ReceiveMessageEvent event, Emitter emit) async { + void _mapRefreshCourseToState( + ReceiveMessageEvent event, Emitter emit) async { try { emit(ReceiveMessageState(message: event.message)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); } } - void _mapUploadImageToState(UploadImageEvent event, Emitter emit) async { + void _mapUploadImageToState( + UploadImageEvent event, Emitter emit) async { emit(MessageUpLoading()); try { final UploadJsonResult uploadJsonResult = await messageRepository.uploadImage(event.filePath); emit(UploadImageSuccess(uploadJsonResult)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } - void _mapUploadVideoToState(UploadVideoEvent event, Emitter emit) async { + void _mapUploadVideoToState( + UploadVideoEvent event, Emitter emit) async { emit(MessageUpLoading()); try { final UploadJsonResult uploadJsonResult = await messageRepository.uploadVideo(event.filePath); emit(UploadVideoSuccess(uploadJsonResult)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } - void _mapSendMessageRestToState(SendMessageRestEvent event, Emitter emit) async { + void _mapSendMessageRestToState( + SendMessageRestEvent event, Emitter emit) async { emit(RestMessageSending()); try { final JsonResult jsonResult = await messageRepository.sendMessageRest(event.json); emit(SendMessageRestSuccess(jsonResult)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(SendMessageRestError()); } } - void _mapLoadHistoryMessageToState(LoadHistoryMessageEvent event, Emitter emit) async { + void _mapLoadHistoryMessageToState( + LoadHistoryMessageEvent event, Emitter emit) async { emit(MessageLoading()); try { final List messageList = await messageRepository .loadHistoryMessages(event.uid, event.page, event.size); emit(LoadHistoryMessageSuccess(messageList: messageList)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(LoadHistoryMessageError()); } } - void _mapLoadTopicMessageToState(LoadTopicMessageEvent event, Emitter emit) async { + void _mapLoadTopicMessageToState( + LoadTopicMessageEvent event, Emitter emit) async { emit(MessageLoading()); try { final List messageList = await messageRepository .loadTopicMessages(event.topic, event.page, event.size); emit(LoadTopicMessageSuccess(messageList: messageList)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(LoadTopicMessageError()); } } - void _mapLoadChannelMessageToState(LoadChannelMessageEvent event, Emitter emit) async { + void _mapLoadChannelMessageToState( + LoadChannelMessageEvent event, Emitter emit) async { emit(MessageLoading()); try { final List messageList = await messageRepository .loadChannelMessages(event.cid, event.page, event.size); emit(LoadChannelMessageSuccess(messageList: messageList)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(LoadChannelMessageError()); } } - void _mapQueryAnswerToState(QueryAnswerEvent event, Emitter emit) async { + void _mapLoadUnreadMessageToState( + LoadUnreadMessagesEvent event, Emitter emit) async { + emit(MessageLoading()); + try { + final List messageList = await messageRepository + .loadUnreadMessages(event.wid, event.page, event.size); + emit(LoadUnreadMessageSuccess(messageList: messageList)); + } catch (error) { + BytedeskUtils.printLog(error); + emit(LoadUnreadMessageError()); + } + } + + void _mapLoadUnreadVisitorMessageToState( + LoadUnreadVisitorMessagesEvent event, Emitter emit) async { + emit(MessageLoading()); + try { + final List messageList = await messageRepository + .loadUnreadVisitorMessages(event.page, event.size); + emit(LoadUnreadVisitorMessageSuccess(messageList: messageList)); + } catch (error) { + BytedeskUtils.printLog(error); + emit(LoadUnreadMessageError()); + } + } + + void _mapLoadUnreadAgentMessageToState( + LoadUnreadAgentMessagesEvent event, Emitter emit) async { + emit(MessageLoading()); + try { + final List messageList = await messageRepository + .loadUnreadAgentMessages(event.page, event.size); + emit(LoadUnreadAgentMessageSuccess(messageList: messageList)); + } catch (error) { + BytedeskUtils.printLog(error); + emit(LoadUnreadAgentMessageError()); + } + } + + void _mapQueryAnswerToState( + QueryAnswerEvent event, Emitter emit) async { emit(MessageLoading()); try { final RequestAnswerResult requestAnswerResult = await messageRepository.queryAnswer(event.tid, event.aid, event.mid); emit(QueryAnswerSuccess( - query: requestAnswerResult.query, answer: requestAnswerResult.anwser)); + query: requestAnswerResult.query, + answer: requestAnswerResult.anwser)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } @@ -155,32 +207,35 @@ class MessageBloc extends Bloc { query: requestAnswerResult.query, answer: requestAnswerResult.anwser)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } - void _mapMessageAnswerToState(MessageAnswerEvent event, Emitter emit) async { + void _mapMessageAnswerToState( + MessageAnswerEvent event, Emitter emit) async { emit(MessageLoading()); try { - final RequestAnswerResult requestAnswerResult = await messageRepository - .messageAnswer(event.wid, event.content); + final RequestAnswerResult requestAnswerResult = + await messageRepository.messageAnswer(event.wid, event.content); emit(MessageAnswerSuccess( - query: requestAnswerResult.query, answer: requestAnswerResult.anwser)); + query: requestAnswerResult.query, + answer: requestAnswerResult.anwser)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } - void _mapRateAnswerToState(RateAnswerEvent event, Emitter emit) async { + void _mapRateAnswerToState( + RateAnswerEvent event, Emitter emit) async { emit(MessageLoading()); try { final RequestAnswerResult requestAnswerResult = await messageRepository.rateAnswer(event.aid, event.mid, event.rate); emit(RateAnswerSuccess(result: requestAnswerResult.anwser)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } diff --git a/bytedesk_kefu/lib/blocs/message_bloc/message_event.dart b/bytedesk_kefu/lib/blocs/message_bloc/message_event.dart index e408d98..c056e4e 100755 --- a/bytedesk_kefu/lib/blocs/message_bloc/message_event.dart +++ b/bytedesk_kefu/lib/blocs/message_bloc/message_event.dart @@ -64,6 +64,33 @@ class LoadChannelMessageEvent extends MessageEvent { : super(); } +class LoadUnreadMessagesEvent extends MessageEvent { + final String? wid; + final int? page; + final int? size; + + LoadUnreadMessagesEvent( + {@required this.wid, @required this.page, @required this.size}) + : super(); +} + +class LoadUnreadVisitorMessagesEvent extends MessageEvent { + final int? page; + final int? size; + + LoadUnreadVisitorMessagesEvent( + {@required this.page, @required this.size}) + : super(); +} + +class LoadUnreadAgentMessagesEvent extends MessageEvent { + final int? page; + final int? size; + + LoadUnreadAgentMessagesEvent({@required this.page, @required this.size}) + : super(); +} + class QueryAnswerEvent extends MessageEvent { final String? tid; final String? aid; diff --git a/bytedesk_kefu/lib/blocs/message_bloc/message_state.dart b/bytedesk_kefu/lib/blocs/message_bloc/message_state.dart index 7686dfe..666a3d7 100755 --- a/bytedesk_kefu/lib/blocs/message_bloc/message_state.dart +++ b/bytedesk_kefu/lib/blocs/message_bloc/message_state.dart @@ -84,6 +84,21 @@ class LoadChannelMessageError extends MessageState { String toString() => 'LoadChannelMessageError'; } +class LoadUnreadMessageError extends MessageState { + @override + String toString() => 'LoadUnreadMessageError'; +} + +class LoadUnreadVisitorMessageError extends MessageState { + @override + String toString() => 'LoadUnreadVisitorMessageError'; +} + +class LoadUnreadAgentMessageError extends MessageState { + @override + String toString() => 'LoadUnreadAgentMessageError'; +} + class UploadVideoSuccess extends MessageState { final UploadJsonResult uploadJsonResult; @@ -119,6 +134,24 @@ class LoadChannelMessageSuccess extends MessageState { LoadChannelMessageSuccess({@required this.messageList}) : super(); } +class LoadUnreadMessageSuccess extends MessageState { + final List? messageList; + + LoadUnreadMessageSuccess({@required this.messageList}) : super(); +} + +class LoadUnreadVisitorMessageSuccess extends MessageState { + final List? messageList; + + LoadUnreadVisitorMessageSuccess({@required this.messageList}) : super(); +} + +class LoadUnreadAgentMessageSuccess extends MessageState { + final List? messageList; + + LoadUnreadAgentMessageSuccess({@required this.messageList}) : super(); +} + class QueryAnswerSuccess extends MessageState { final Message? query; final Message? answer; diff --git a/bytedesk_kefu/lib/blocs/profile_bloc/profile_bloc.dart b/bytedesk_kefu/lib/blocs/profile_bloc/profile_bloc.dart index ffe2c30..1ae166d 100755 --- a/bytedesk_kefu/lib/blocs/profile_bloc/profile_bloc.dart +++ b/bytedesk_kefu/lib/blocs/profile_bloc/profile_bloc.dart @@ -3,6 +3,7 @@ import 'package:bytedesk_kefu/model/jsonResult.dart'; import 'package:bytedesk_kefu/model/user.dart'; import 'package:bytedesk_kefu/repositories/user_repository.dart'; import 'package:bloc/bloc.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; import './bloc.dart'; class ProfileBloc extends Bloc { @@ -24,7 +25,6 @@ class ProfileBloc extends Bloc { on(_mapUserFollowToState); on(_mapUserUnfollowToState); - } // @override @@ -57,7 +57,8 @@ class ProfileBloc extends Bloc { // } // } - void _mapProfileState(GetProfileEvent event, Emitter emit) async { + void _mapProfileState( + GetProfileEvent event, Emitter emit) async { emit(ProfileInProgress()); try { User user = await userRepository.getProfile(); @@ -68,124 +69,135 @@ class ProfileBloc extends Bloc { } } - void _mapUploadImageToState(UploadImageEvent event, Emitter emit) async { + void _mapUploadImageToState( + UploadImageEvent event, Emitter emit) async { emit(ProfileInProgress()); try { final String url = await userRepository.upload(event.filePath); emit(UploadImageSuccess(url)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } - void _mapUpdateAvatarToState(UpdateAvatarEvent event, Emitter emit) async { + void _mapUpdateAvatarToState( + UpdateAvatarEvent event, Emitter emit) async { emit(ProfileInProgress()); try { final User user = await userRepository.updateAvatar(event.avatar); emit(UpdateAvatarSuccess(user)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } - void _mapUpdateNicknameToState(UpdateNicknameEvent event, Emitter emit) async { + void _mapUpdateNicknameToState( + UpdateNicknameEvent event, Emitter emit) async { emit(ProfileInProgress()); try { final User user = await userRepository.updateNickname(event.nickname); emit(UpdateNicknameSuccess(user)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } - void _mapUpdateDescriptionToState(UpdateDescriptionEvent event, Emitter emit) async { + void _mapUpdateDescriptionToState( + UpdateDescriptionEvent event, Emitter emit) async { emit(ProfileInProgress()); try { final User user = await userRepository.updateDescription(event.description); emit(UpdateDescriptionSuccess(user)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } - void _mapUpdateMobileToState(UpdateMobileEvent event, Emitter emit) async { + void _mapUpdateMobileToState( + UpdateMobileEvent event, Emitter emit) async { emit(ProfileInProgress()); try { final User user = await userRepository.updateMobile(event.mobile); emit(UpdateMobileSuccess(user)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } - void _mapUpdateSexToState(UpdateSexEvent event, Emitter emit) async { + void _mapUpdateSexToState( + UpdateSexEvent event, Emitter emit) async { emit(ProfileInProgress()); try { final User user = await userRepository.updateSex(event.sex); emit(UpdateSexSuccess(user)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } - void _mapUpdateLocationToState(UpdateLocationEvent event, Emitter emit) async { + void _mapUpdateLocationToState( + UpdateLocationEvent event, Emitter emit) async { emit(ProfileInProgress()); try { final User user = await userRepository.updateLocation(event.location); emit(UpdateLocationSuccess(user)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } - void _mapUpdateBirthdayToState(UpdateBirthdayEvent event, Emitter emit) async { + void _mapUpdateBirthdayToState( + UpdateBirthdayEvent event, Emitter emit) async { emit(ProfileInProgress()); try { final User user = await userRepository.updateBirthday(event.birthday); emit(UpdateBirthdaySuccess(user)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } - void _mapQueryFollowToState(QueryFollowEvent event, Emitter emit) async { + void _mapQueryFollowToState( + QueryFollowEvent event, Emitter emit) async { emit(QueryFollowing()); try { final bool isFollowed = await userRepository.isFollowed(event.uid); emit(QueryFollowSuccess(isFollowed)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(QueryFollowError()); } } - void _mapUserFollowToState(UserFollowEvent event, Emitter emit) async { + void _mapUserFollowToState( + UserFollowEvent event, Emitter emit) async { emit(Following()); try { final JsonResult jsonResult = await userRepository.follow(event.uid); emit(FollowResultSuccess(jsonResult)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(FollowError()); } } - void _mapUserUnfollowToState(UserUnfollowEvent event, Emitter emit) async { + void _mapUserUnfollowToState( + UserUnfollowEvent event, Emitter emit) async { emit(Following()); try { final JsonResult jsonResult = await userRepository.unfollow(event.uid); emit(UnfollowResultSuccess(jsonResult)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UnFollowError()); } } diff --git a/bytedesk_kefu/lib/blocs/thread_bloc/thread_bloc.dart b/bytedesk_kefu/lib/blocs/thread_bloc/thread_bloc.dart index 9bb42f5..6584837 100755 --- a/bytedesk_kefu/lib/blocs/thread_bloc/thread_bloc.dart +++ b/bytedesk_kefu/lib/blocs/thread_bloc/thread_bloc.dart @@ -4,6 +4,7 @@ import 'package:bloc/bloc.dart'; import './bloc.dart'; import 'package:bytedesk_kefu/repositories/repositories.dart'; import 'package:bytedesk_kefu/model/model.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; class ThreadBloc extends Bloc { // @@ -39,7 +40,7 @@ class ThreadBloc extends Bloc { final List threadList = await threadRepository.getThreads(); emit(ThreadLoadSuccess(threadList)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ThreadLoadError()); } } @@ -52,7 +53,7 @@ class ThreadBloc extends Bloc { await threadRepository.getHistoryThreads(event.page, event.size); emit(ThreadLoadSuccess(threadList)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ThreadLoadError()); } } @@ -65,7 +66,7 @@ class ThreadBloc extends Bloc { await threadRepository.getVisitorThreads(event.page, event.size); emit(ThreadLoadSuccess(threadList)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ThreadLoadError()); } } @@ -78,7 +79,7 @@ class ThreadBloc extends Bloc { await threadRepository.getVisitorThreadsAll(); emit(ThreadLoadSuccess(threadList)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ThreadLoadError()); } } @@ -91,7 +92,7 @@ class ThreadBloc extends Bloc { event.wid, event.type, event.aid, event.isV2Robot); emit(RequestThreadSuccess(thread)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(RequestThreadError()); } } @@ -104,7 +105,7 @@ class ThreadBloc extends Bloc { await threadRepository.requestAgent(event.wid, event.type, event.aid); emit(RequestAgentSuccess(thread)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(RequestAgentThreadError()); } } @@ -117,7 +118,7 @@ class ThreadBloc extends Bloc { await threadRepository.requestContactThread(event.cid); emit(RequestContactThreadSuccess(thread)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ThreadLoadError()); } } @@ -130,7 +131,7 @@ class ThreadBloc extends Bloc { await threadRepository.requestGroupThread(event.gid); emit(RequestGroupThreadSuccess(thread)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ThreadLoadError()); } } @@ -142,7 +143,7 @@ class ThreadBloc extends Bloc { final MarkThreadResult thread = await threadRepository.markTop(event.tid); emit(MarkTopThreadSuccess(thread)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ThreadLoadError()); } } @@ -155,7 +156,7 @@ class ThreadBloc extends Bloc { await threadRepository.unmarkTop(event.tid); emit(UnMarkTopThreadSuccess(thread)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ThreadLoadError()); } } @@ -168,7 +169,7 @@ class ThreadBloc extends Bloc { await threadRepository.markNodisturb(event.tid); emit(MarkNodisturbThreadSuccess(thread)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ThreadLoadError()); } } @@ -181,7 +182,7 @@ class ThreadBloc extends Bloc { await threadRepository.unmarkNodisturb(event.tid); emit(UnMarkNodisturbThreadSuccess(thread)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ThreadLoadError()); } } @@ -194,7 +195,7 @@ class ThreadBloc extends Bloc { await threadRepository.markUnread(event.tid); emit(MarkUnreadThreadSuccess(thread)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ThreadLoadError()); } } @@ -207,7 +208,7 @@ class ThreadBloc extends Bloc { await threadRepository.unmarkUnread(event.tid); emit(UnMarkUnreadThreadSuccess(thread)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ThreadLoadError()); } } @@ -219,7 +220,7 @@ class ThreadBloc extends Bloc { final MarkThreadResult thread = await threadRepository.delete(event.tid); emit(DeleteThreadSuccess(thread)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(ThreadLoadError()); } } diff --git a/bytedesk_kefu/lib/blocs/ticket_bloc/ticket_bloc.dart b/bytedesk_kefu/lib/blocs/ticket_bloc/ticket_bloc.dart index f2cc81c..16074ef 100755 --- a/bytedesk_kefu/lib/blocs/ticket_bloc/ticket_bloc.dart +++ b/bytedesk_kefu/lib/blocs/ticket_bloc/ticket_bloc.dart @@ -1,6 +1,7 @@ // import 'dart:async'; import 'package:bytedesk_kefu/blocs/ticket_bloc/bloc.dart'; import 'package:bloc/bloc.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; import 'package:bytedesk_kefu/repositories/ticket_repository.dart'; class TicketBloc extends Bloc { @@ -26,37 +27,40 @@ class TicketBloc extends Bloc { // } // } - void _mapGetTicketCategoryToState(GetTicketCategoryEvent event, Emitter emit) async { + void _mapGetTicketCategoryToState( + GetTicketCategoryEvent event, Emitter emit) async { emit(TicketLoading()); try { // final List categoryList = // await feedbackRepository.getHelpTicketCategories(); // emit(TicketCategoryState(categoryList); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(TicketLoadError()); } } - void _mapSubmitTicketToState(SubmitTicketEvent event, Emitter emit) async { + void _mapSubmitTicketToState( + SubmitTicketEvent event, Emitter emit) async { emit(TicketLoading()); try { // final List categoryList = // await feedbackRepository.getHelpTicketCategories(); // emit(TicketCategoryState(categoryList); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(TicketLoadError()); } } - void _mapUploadImageToState(UploadImageEvent event, Emitter emit) async { + void _mapUploadImageToState( + UploadImageEvent event, Emitter emit) async { emit(TicketLoading()); try { final String url = await feedbackRepository.upload(event.filePath); emit(UploadImageSuccess(url)); } catch (error) { - print(error); + BytedeskUtils.printLog(error); emit(UpLoadImageError()); } } diff --git a/bytedesk_kefu/lib/http/bytedesk_faq_api.dart b/bytedesk_kefu/lib/http/bytedesk_faq_api.dart index c36c39c..138f54c 100755 --- a/bytedesk_kefu/lib/http/bytedesk_faq_api.dart +++ b/bytedesk_kefu/lib/http/bytedesk_faq_api.dart @@ -4,6 +4,7 @@ import 'package:bytedesk_kefu/http/bytedesk_base_api.dart'; import 'package:bytedesk_kefu/model/helpArticle.dart'; import 'package:bytedesk_kefu/model/helpCategory.dart'; import 'package:bytedesk_kefu/util/bytedesk_constants.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; class BytedeskFaqHttpApi extends BytedeskBaseHttpApi { // @@ -12,7 +13,7 @@ class BytedeskFaqHttpApi extends BytedeskBaseHttpApi { // final categoriesUrl = Uri.http(BytedeskConstants.host, '/visitor/api/category/support', {'uid': uid, 'client': client}); - print("categories Url $categoriesUrl"); + BytedeskUtils.printLog("categories Url $categoriesUrl"); final initResponse = await this.httpClient.get(categoriesUrl); // //解决json解析中的乱码问题 @@ -20,7 +21,7 @@ class BytedeskFaqHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // List categories = (responseJson['data'] as List) .map((item) => HelpCategory.fromJson(item)) @@ -38,7 +39,7 @@ class BytedeskFaqHttpApi extends BytedeskBaseHttpApi { BytedeskConstants.host, '/visitor/api/category/articles', {'categoryId': categoryId, 'client': client}); - print("categories Url $categoriesUrl"); + BytedeskUtils.printLog("categories Url $categoriesUrl"); final initResponse = await this.httpClient.get(categoriesUrl); // //解决json解析中的乱码问题 @@ -46,7 +47,7 @@ class BytedeskFaqHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // List articles = (responseJson['data'] as List) .map((item) => HelpArticle.fromJson(item)) diff --git a/bytedesk_kefu/lib/http/bytedesk_feedback_api.dart b/bytedesk_kefu/lib/http/bytedesk_feedback_api.dart index 74dd00e..21a8a9d 100755 --- a/bytedesk_kefu/lib/http/bytedesk_feedback_api.dart +++ b/bytedesk_kefu/lib/http/bytedesk_feedback_api.dart @@ -5,6 +5,7 @@ import 'package:bytedesk_kefu/model/helpCategory.dart'; import 'package:bytedesk_kefu/model/jsonResult.dart'; import 'package:bytedesk_kefu/util/bytedesk_constants.dart'; import 'package:bytedesk_kefu/util/bytedesk_events.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; import 'package:sp_util/sp_util.dart'; import 'package:http/http.dart' as http; @@ -17,7 +18,7 @@ class BytedeskFeedbackHttpApi extends BytedeskBaseHttpApi { // '$baseUrl/visitor/api/category/feedback?uid=$uid&client=$client'; final categoriesUrl = Uri.http(BytedeskConstants.host, '/visitor/api/category/feedback', {'uid': uid, 'client': client}); - print("categories Url $categoriesUrl"); + BytedeskUtils.printLog("categories Url $categoriesUrl"); final initResponse = await this.httpClient.get(categoriesUrl); // //解决json解析中的乱码问题 @@ -25,7 +26,7 @@ class BytedeskFeedbackHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // List categories = (responseJson['data'] as List) .map((item) => HelpCategory.fromJson(item)) @@ -49,7 +50,7 @@ class BytedeskFeedbackHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -65,7 +66,8 @@ class BytedeskFeedbackHttpApi extends BytedeskBaseHttpApi { String? username = SpUtil.getString(BytedeskConstants.uid); final uploadUrl = '$baseUrl/visitor/api/upload/image'; - print("fileName $fileName, username $username, upload Url $uploadUrl"); + BytedeskUtils.printLog( + "fileName $fileName, username $username, upload Url $uploadUrl"); var uri = Uri.parse(uploadUrl); var request = http.MultipartRequest('POST', uri) @@ -75,16 +77,16 @@ class BytedeskFeedbackHttpApi extends BytedeskBaseHttpApi { http.Response response = await http.Response.fromStream(await request.send()); - // print("Result: ${response.body}"); + // BytedeskUtils.printLog("Result: ${response.body}"); //解决json解析中的乱码问题 Utf8Decoder utf8decoder = Utf8Decoder(); // fix 中文乱码 //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(response.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); String url = responseJson['data']; - print('url:' + url); + BytedeskUtils.printLog('url:' + url); return url; } } diff --git a/bytedesk_kefu/lib/http/bytedesk_friend_api.dart b/bytedesk_kefu/lib/http/bytedesk_friend_api.dart index ca72fab..4da2a86 100755 --- a/bytedesk_kefu/lib/http/bytedesk_friend_api.dart +++ b/bytedesk_kefu/lib/http/bytedesk_friend_api.dart @@ -14,7 +14,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi { // '$baseUrl/api/friend/query?page=$page&size=$size&client=$client'; final friendsUrl = Uri.http(BytedeskConstants.host, '/api/friend/query', {'page': page.toString(), 'size': size.toString(), 'client': client}); - print("get friends Url $friendsUrl"); + BytedeskUtils.printLog("get friends Url $friendsUrl"); final initResponse = await this.httpClient.get(friendsUrl, headers: getHeaders()); @@ -23,7 +23,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -45,7 +45,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi { BytedeskConstants.host, '/api/friend/address/query', {'page': page.toString(), 'size': size.toString(), 'client': client}); - print("address Url $addressUrl"); + BytedeskUtils.printLog("address Url $addressUrl"); final initResponse = await this.httpClient.get(addressUrl, headers: getHeaders()); @@ -54,7 +54,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -83,7 +83,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -108,7 +108,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi { 'size': size.toString(), 'client': client }); - print("address Url $addressUrl"); + BytedeskUtils.printLog("address Url $addressUrl"); final initResponse = await this.httpClient.get(addressUrl, headers: getHeaders()); @@ -117,7 +117,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); diff --git a/bytedesk_kefu/lib/http/bytedesk_leavemsg_api.dart b/bytedesk_kefu/lib/http/bytedesk_leavemsg_api.dart index d176aa9..94f02e6 100755 --- a/bytedesk_kefu/lib/http/bytedesk_leavemsg_api.dart +++ b/bytedesk_kefu/lib/http/bytedesk_leavemsg_api.dart @@ -5,7 +5,7 @@ import 'package:bytedesk_kefu/model/helpCategory.dart'; import 'package:bytedesk_kefu/model/jsonResult.dart'; import 'package:bytedesk_kefu/util/bytedesk_constants.dart'; import 'package:bytedesk_kefu/util/bytedesk_events.dart'; -// import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; import 'package:http/http.dart' as http; import 'package:sp_util/sp_util.dart'; @@ -17,7 +17,7 @@ class BytedeskLeaveMsgHttpApi extends BytedeskBaseHttpApi { // '$baseUrl/visitor/api/category/feedback?uid=$uid&client=$client'; final categoriesUrl = Uri.http(BytedeskConstants.host, '/visitor/api/category/feedback', {'uid': uid, 'client': client}); - print("categories Url $categoriesUrl"); + BytedeskUtils.printLog("categories Url $categoriesUrl"); final initResponse = await this.httpClient.get(categoriesUrl); // //解决json解析中的乱码问题 @@ -37,7 +37,15 @@ class BytedeskLeaveMsgHttpApi extends BytedeskBaseHttpApi { Future submitLeaveMsg(String? wid, String? aid, String? type, String? mobile, String? email, String? content) async { // - var body = json.encode({"wid": wid, "aid": aid, "type": type, "mobile": mobile, "email": email,"content": content, "client": client}); + var body = json.encode({ + "wid": wid, + "aid": aid, + "type": type, + "mobile": mobile, + "email": email, + "content": content, + "client": client + }); final initUrl = Uri.http(BytedeskConstants.host, '/api/leavemsg/save'); final initResponse = await this.httpClient.post(initUrl, headers: getHeaders(), body: body); @@ -46,8 +54,8 @@ class BytedeskLeaveMsgHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("submitLeaveMsg:"); - print(responseJson); + BytedeskUtils.printLog("submitLeaveMsg:"); + BytedeskUtils.printLog(responseJson); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -63,7 +71,8 @@ class BytedeskLeaveMsgHttpApi extends BytedeskBaseHttpApi { String? username = SpUtil.getString(BytedeskConstants.uid); final uploadUrl = '$baseUrl/visitor/api/upload/image'; - print("fileName $fileName, username $username, upload Url $uploadUrl"); + BytedeskUtils.printLog( + "fileName $fileName, username $username, upload Url $uploadUrl"); var uri = Uri.parse(uploadUrl); var request = http.MultipartRequest('POST', uri) @@ -73,16 +82,16 @@ class BytedeskLeaveMsgHttpApi extends BytedeskBaseHttpApi { http.Response response = await http.Response.fromStream(await request.send()); - // print("Result: ${response.body}"); + // BytedeskUtils.printLog("Result: ${response.body}"); //解决json解析中的乱码问题 Utf8Decoder utf8decoder = Utf8Decoder(); // fix 中文乱码 //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(response.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); String url = responseJson['data']; - print('url:' + url); + BytedeskUtils.printLog('url:' + url); return url; } } diff --git a/bytedesk_kefu/lib/http/bytedesk_message_api.dart b/bytedesk_kefu/lib/http/bytedesk_message_api.dart index 23271e0..1ebc828 100755 --- a/bytedesk_kefu/lib/http/bytedesk_message_api.dart +++ b/bytedesk_kefu/lib/http/bytedesk_message_api.dart @@ -9,6 +9,7 @@ import 'package:bytedesk_kefu/model/requestCategory.dart'; import 'package:bytedesk_kefu/model/uploadJsonResult.dart'; import 'package:bytedesk_kefu/util/bytedesk_constants.dart'; import 'package:bytedesk_kefu/util/bytedesk_events.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; import 'package:sp_util/sp_util.dart'; import 'package:http/http.dart' as http; import 'package:http_parser/http_parser.dart'; @@ -30,7 +31,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(sendMessageResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -49,7 +50,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { 'uid': uid, 'client': client }); - // print("loadHistoryMessages Url $loadHistoryMessages"); + // BytedeskUtils.printLog("loadHistoryMessages Url $loadHistoryMessages"); final initResponse = await this .httpClient .get(loadHistoryMessagesUrl, headers: getHeaders()); @@ -75,8 +76,6 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { Future> loadTopicMessages( String? topic, int? page, int? size) async { // - // final loadTopicMessagesUrl = - // '$baseUrl/api/messages/topic?topic=$topic&page=$page&size=$size&client=$client'; final loadTopicMessagesUrl = Uri.http(BytedeskConstants.host, '/api/messages/topic', { 'page': page.toString(), @@ -84,7 +83,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { 'topic': topic, 'client': client }); - // print("loadHistoryMessages Url $loadHistoryMessages"); + // BytedeskUtils.printLog("loadHistoryMessages Url $loadHistoryMessages"); final initResponse = await this.httpClient.get(loadTopicMessagesUrl, headers: getHeaders()); // @@ -118,7 +117,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { 'cid': cid, 'client': client }); - // print("loadChannelMessagesUrl Url $loadHistoryMessages"); + // BytedeskUtils.printLog("loadChannelMessagesUrl Url $loadHistoryMessages"); final initResponse = await this .httpClient .get(loadChannelMessagesUrl, headers: getHeaders()); @@ -141,12 +140,108 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { return messageList; } + /// 查询当前用户-某技能组wid或指定客服未读消息 + /// 注意:技能组wid或指定客服唯一id + /// 适用于 访客 和 客服 + Future> loadUnreadMessages( + String? wid, int? page, int? size) async { + // + final loadUnreadMessagesUrl = Uri.http( + BytedeskConstants.host, '/api/messages/unread/message', { + 'page': page.toString(), + 'size': size.toString(), + 'wid': wid, + 'client': client + }); + // BytedeskUtils.printLog("loadHistoryMessages Url $loadHistoryMessages"); + final initResponse = await this + .httpClient + .get(loadUnreadMessagesUrl, headers: getHeaders()); + // + //解决json解析中的乱码问题 + Utf8Decoder utf8decoder = Utf8Decoder(); // fix 中文乱码 + //将string类型数据 转换为json类型的数据 + final responseJson = + json.decode(utf8decoder.convert(initResponse.bodyBytes)); + // 判断token是否过期 + if (responseJson.toString().contains('invalid_token')) { + bytedeskEventBus.fire(InvalidTokenEventBus()); + } + // + List messageList = + (responseJson['data']['content'] as List) + .map((item) => Message.fromJson(item)) + .toList(); + + return messageList; + } + + // 访客端-查询访客所有未读消息 + Future> loadUnreadMessagesVisitor(int? page, int? size) async { + // + final loadUnreadMessagesUrl = Uri.http( + BytedeskConstants.host, '/api/messages/unread/message/visitor', { + 'page': page.toString(), + 'size': size.toString(), + 'client': client + }); + // BytedeskUtils.printLog("loadHistoryMessages Url $loadHistoryMessages"); + final initResponse = + await this.httpClient.get(loadUnreadMessagesUrl, headers: getHeaders()); + // + //解决json解析中的乱码问题 + Utf8Decoder utf8decoder = Utf8Decoder(); // fix 中文乱码 + //将string类型数据 转换为json类型的数据 + final responseJson = + json.decode(utf8decoder.convert(initResponse.bodyBytes)); + // 判断token是否过期 + if (responseJson.toString().contains('invalid_token')) { + bytedeskEventBus.fire(InvalidTokenEventBus()); + } + // + List messageList = + (responseJson['data']['content'] as List) + .map((item) => Message.fromJson(item)) + .toList(); + + return messageList; + } + + // 客服端-查询客服所有未读消息 + Future> loadUnreadMessagesAgent(int? page, int? size) async { + // + final loadUnreadMessagesAgentUrl = Uri.http( + BytedeskConstants.host, + '/api/messages/unread/message/agent', + {'page': page.toString(), 'size': size.toString(), 'client': client}); + // BytedeskUtils.printLog("loadHistoryMessages Url $loadHistoryMessages"); + final initResponse = + await this.httpClient.get(loadUnreadMessagesAgentUrl, headers: getHeaders()); + // + //解决json解析中的乱码问题 + Utf8Decoder utf8decoder = Utf8Decoder(); // fix 中文乱码 + //将string类型数据 转换为json类型的数据 + final responseJson = + json.decode(utf8decoder.convert(initResponse.bodyBytes)); + // 判断token是否过期 + if (responseJson.toString().contains('invalid_token')) { + bytedeskEventBus.fire(InvalidTokenEventBus()); + } + // + List messageList = + (responseJson['data']['content'] as List) + .map((item) => Message.fromJson(item)) + .toList(); + + return messageList; + } + // Future queryAnswer(String? tid, String? aid) async { // final queryAnswerUrl = Uri.http(BytedeskConstants.host, '/api/answer/query', {'tid': tid, 'aid': aid, 'client': client}); - print("query Url $queryAnswerUrl"); + BytedeskUtils.printLog("query Url $queryAnswerUrl"); final initResponse = await this.httpClient.get(queryAnswerUrl, headers: getHeaders()); // @@ -171,7 +266,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { BytedeskConstants.host, '/api/v2/answer/query', {'tid': tid, 'aid': aid, 'mid': mid, 'client': client}); - print("query Url $queryAnswerUrl"); + BytedeskUtils.printLog("query Url $queryAnswerUrl"); final initResponse = await this.httpClient.get(queryAnswerUrl, headers: getHeaders()); // @@ -189,14 +284,11 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { } // - Future queryCategory( - String? tid, String? cid) async { + Future queryCategory(String? tid, String? cid) async { // - final queryCategoryUrl = Uri.http( - BytedeskConstants.host, - '/api/v2/answer/category', - {'tid': tid, 'cid': cid, 'client': client}); - print("query Url $queryCategoryUrl"); + final queryCategoryUrl = Uri.http(BytedeskConstants.host, + '/api/v2/answer/category', {'tid': tid, 'cid': cid, 'client': client}); + BytedeskUtils.printLog("query Url $queryCategoryUrl"); final initResponse = await this.httpClient.get(queryCategoryUrl, headers: getHeaders()); // @@ -225,7 +317,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { 'content': content, 'client': client }); - print("message Url $messageAnswerUrl"); + BytedeskUtils.printLog("message Url $messageAnswerUrl"); final initResponse = await this.httpClient.get(messageAnswerUrl, headers: getHeaders()); // @@ -234,8 +326,8 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("messageAnswer:"); - print(responseJson); + BytedeskUtils.printLog("messageAnswer:"); + BytedeskUtils.printLog(responseJson); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -252,7 +344,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { // '$baseUrl/api/answer/rate?aid=$aid&mid=$mid&rate=$rate&client=$client'; final rateAnswerUrl = Uri.http(BytedeskConstants.host, '/api/answer/rate', {'aid': aid, 'mid': mid, 'rate': rate, 'client': client}); - print("rate Url $rateAnswerUrl"); + BytedeskUtils.printLog("rate Url $rateAnswerUrl"); final initResponse = await this.httpClient.get(rateAnswerUrl, headers: getHeaders()); // @@ -277,7 +369,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { final uploadUrl = '${BytedeskConstants.httpUploadUrl}/visitor/api/upload/image'; - print( + BytedeskUtils.printLog( "uploadImage fileName $fileName, username $username, upload Url $uploadUrl"); var uri = Uri.parse(uploadUrl); @@ -288,13 +380,13 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { http.Response response = await http.Response.fromStream(await request.send()); - // print("Result: ${response.body}"); + // BytedeskUtils.printLog("Result: ${response.body}"); //解决json解析中的乱码问题 Utf8Decoder utf8decoder = Utf8Decoder(); // fix 中文乱码 //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(response.bodyBytes)); - print("upload image responseJson $responseJson"); + BytedeskUtils.printLog("upload image responseJson $responseJson"); // return UploadJsonResult.fromJson(responseJson); } @@ -306,7 +398,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { String? username = SpUtil.getString(BytedeskConstants.uid); final uploadUrl = '${BytedeskConstants.httpUploadUrl}/visitor/api/upload/video'; - print( + BytedeskUtils.printLog( "uploadVideo fileName $fileName, username $username, upload Url $uploadUrl"); // Map headers = { @@ -323,13 +415,13 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi { http.Response response = await http.Response.fromStream(await request.send()); - // print("Result: ${response.body}"); + // BytedeskUtils.printLog("Result: ${response.body}"); //解决json解析中的乱码问题 Utf8Decoder utf8decoder = Utf8Decoder(); // fix 中文乱码 //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(response.bodyBytes)); - print("upload Video responseJson $responseJson"); + BytedeskUtils.printLog("upload Video responseJson $responseJson"); // return UploadJsonResult.fromJson(responseJson); } diff --git a/bytedesk_kefu/lib/http/bytedesk_thread_api.dart b/bytedesk_kefu/lib/http/bytedesk_thread_api.dart index 7a51854..84c47ab 100755 --- a/bytedesk_kefu/lib/http/bytedesk_thread_api.dart +++ b/bytedesk_kefu/lib/http/bytedesk_thread_api.dart @@ -7,6 +7,7 @@ import 'package:bytedesk_kefu/model/requestThread.dart'; import 'package:bytedesk_kefu/model/thread.dart'; import 'package:bytedesk_kefu/util/bytedesk_constants.dart'; import 'package:bytedesk_kefu/util/bytedesk_events.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; import 'package:sp_util/sp_util.dart'; class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { @@ -16,7 +17,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { // final threadUrl = '$baseUrl/api/thread/get?client=$client'; final threadUrl = Uri.http(BytedeskConstants.host, '/api/thread/get', {'client': client}); - // print("thread Url $threadUrl"); + // BytedeskUtils.printLog("thread Url $threadUrl"); final initResponse = await this.httpClient.get(threadUrl, headers: getHeaders()); @@ -25,7 +26,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -63,7 +64,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { BytedeskConstants.host, '/api/thread/history/records', {'page': page.toString(), 'size': size.toString(), 'client': client}); - // print("thread Url $threadUrl"); + // BytedeskUtils.printLog("thread Url $threadUrl"); final initResponse = await this.httpClient.get(threadUrl, headers: getHeaders()); @@ -72,7 +73,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -104,7 +105,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("getVisitorThreads responseJson $responseJson"); + // BytedeskUtils.printLog("getVisitorThreads responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -130,7 +131,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("getVisitorThreadsAll responseJson $responseJson"); + BytedeskUtils.printLog("getVisitorThreadsAll responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -149,7 +150,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { // final threadUrl = Uri.http(BytedeskConstants.host, '/api/thread/request', {'wId': wid, 'type': type, 'aId': aid, 'client': client}); - print(threadUrl); + BytedeskUtils.printLog(threadUrl); final initResponse = await this.httpClient.get(threadUrl, headers: getHeaders()); @@ -158,8 +159,8 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("requestThread:"); - // print(responseJson); + // BytedeskUtils.printLog("requestThread:"); + // BytedeskUtils.printLog(responseJson); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -173,7 +174,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { // final threadUrl = Uri.http(BytedeskConstants.host, '/api/v2/thread/workGroup', {'wId': wid, 'client': client}); - print(threadUrl); + BytedeskUtils.printLog(threadUrl); final initResponse = await this.httpClient.get(threadUrl, headers: getHeaders()); @@ -182,8 +183,8 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("requestWorkGroupThreadV2:"); - print(responseJson); + BytedeskUtils.printLog("requestWorkGroupThreadV2:"); + BytedeskUtils.printLog(responseJson); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -200,7 +201,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { BytedeskConstants.host, '/api/thread/request/agent', {'wId': wid, 'type': type, 'aId': aid, 'client': client}); - print("request agent Url $threadUrl"); + BytedeskUtils.printLog("request agent Url $threadUrl"); final initResponse = await this.httpClient.get(threadUrl, headers: getHeaders()); @@ -209,7 +210,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -223,7 +224,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { // final threadUrl = Uri.http(BytedeskConstants.host, '/api/thread/contact', {'cid': cid, 'client': client}); - print("request contact thread Url $threadUrl"); + BytedeskUtils.printLog("request contact thread Url $threadUrl"); final initResponse = await this.httpClient.get(threadUrl, headers: getHeaders()); @@ -232,7 +233,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -246,7 +247,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { // final threadUrl = Uri.http(BytedeskConstants.host, '/api/thread/group', {'gid': gid, 'client': client}); - print("request contact thread Url $threadUrl"); + BytedeskUtils.printLog("request contact thread Url $threadUrl"); final initResponse = await this.httpClient.get(threadUrl, headers: getHeaders()); @@ -255,7 +256,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -283,7 +284,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -311,7 +312,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -339,7 +340,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -367,7 +368,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -395,7 +396,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -423,7 +424,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -445,7 +446,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { diff --git a/bytedesk_kefu/lib/http/bytedesk_user_api.dart b/bytedesk_kefu/lib/http/bytedesk_user_api.dart index 96a9430..d215d2e 100755 --- a/bytedesk_kefu/lib/http/bytedesk_user_api.dart +++ b/bytedesk_kefu/lib/http/bytedesk_user_api.dart @@ -18,7 +18,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { // 授权 Future oauth(String? username, String? password) async { var oauthUrl = Uri.http(BytedeskConstants.host, '/oauth/token'); - // print("http api client: oauthUrl $oauthUrl"); + // BytedeskUtils.printLog("http api client: oauthUrl $oauthUrl"); Map headers = { "Authorization": "Basic Y2xpZW50OnNlY3JldA==" }; @@ -30,14 +30,14 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { }; final oauthResponse = await this.httpClient.post(oauthUrl, headers: headers, body: bodyMap); - // print('oauth result: $oauthResponse'); + // BytedeskUtils.printLog('oauth result: $oauthResponse'); // check the status code for the result int statusCode = oauthResponse.statusCode; - // print("statusCode $statusCode"); + // BytedeskUtils.printLog("statusCode $statusCode"); // 200: 授权成功,否则授权失败 final oauthJson = jsonDecode(oauthResponse.body); - // print('oauth:'); - // print(oauthJson); + BytedeskUtils.printLog('oauth:'); + BytedeskUtils.printLog(oauthJson); SpUtil.putBool(BytedeskConstants.isLogin, true); SpUtil.putString(BytedeskConstants.accessToken, oauthJson['access_token']); // @@ -50,7 +50,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { // final oauthUrl = '$baseUrl/mobile/token'; // final oauthUrl = Uri.http(BytedeskConstants.host, '/mobile/token'); final oauthUrl = Uri.http(BytedeskConstants.host, '/mobile/token'); - // print("http api client: oauthUrl $oauthUrl"); + // BytedeskUtils.printLog("http api client: oauthUrl $oauthUrl"); Map headers = { "Authorization": "Basic Y2xpZW50OnNlY3JldA==" }; @@ -63,12 +63,12 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { // final oauthResponse = await this.httpClient.post(oauthUrl, headers: headers, body: bodyMap); - // print('oauth result: $oauthResponse'); + // BytedeskUtils.printLog('oauth result: $oauthResponse'); int statusCode = oauthResponse.statusCode; // 200: 授权成功,否则授权失败 final oauthJson = jsonDecode(oauthResponse.body); - print('smsOAuth:'); - print(oauthJson); + BytedeskUtils.printLog('smsOAuth:'); + BytedeskUtils.printLog(oauthJson); if (statusCode == 200) { SpUtil.putBool(BytedeskConstants.isLogin, true); SpUtil.putBool(BytedeskConstants.isAuthenticated, true); @@ -84,7 +84,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { // // final oauthUrl = '$baseUrl/wechat/token'; final oauthUrl = Uri.http(BytedeskConstants.host, '/wechat/token'); - // print("http api client: oauthUrl $oauthUrl"); + // BytedeskUtils.printLog("http api client: oauthUrl $oauthUrl"); Map headers = { "Authorization": "Basic Y2xpZW50OnNlY3JldA==" }; @@ -96,14 +96,14 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { // final oauthResponse = await this.httpClient.post(oauthUrl, headers: headers, body: bodyMap); - // print('oauth result: $oauthResponse'); + // BytedeskUtils.printLog('oauth result: $oauthResponse'); // check the status code for the result int statusCode = oauthResponse.statusCode; - // print("statusCode $statusCode"); + // BytedeskUtils.printLog("statusCode $statusCode"); // 200: 授权成功,否则授权失败 final oauthJson = jsonDecode(oauthResponse.body); - print('unionIdOAuth:'); - print(oauthJson); + BytedeskUtils.printLog('unionIdOAuth:'); + BytedeskUtils.printLog(oauthJson); if (statusCode == 200) { SpUtil.putBool(BytedeskConstants.isLogin, true); SpUtil.putBool(BytedeskConstants.isAuthenticated, true); @@ -137,8 +137,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("register:"); - // print(responseJson); + // BytedeskUtils.printLog("register:"); + // BytedeskUtils.printLog(responseJson); return JsonResult.fromJson(responseJson); } @@ -157,8 +157,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("registerAnonymous:"); - // print(responseJson); + // BytedeskUtils.printLog("registerAnonymous:"); + // BytedeskUtils.printLog(responseJson); // User user = User.fromJson(responseJson['data']); // @@ -196,8 +196,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("registerUser:"); - print(responseJson); + BytedeskUtils.printLog("registerUser:"); + BytedeskUtils.printLog(responseJson); // int statusCode = responseJson['status_code']; if (statusCode == 200) { @@ -243,8 +243,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); // final responseJson = json.decode(initResponse.body); - // print("changePassword"); - // print(responseJson); + // BytedeskUtils.printLog("changePassword"); + // BytedeskUtils.printLog(responseJson); return JsonResult.fromJson(responseJson); } @@ -261,8 +261,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("requestCode:"); - // print(responseJson); + // BytedeskUtils.printLog("requestCode:"); + // BytedeskUtils.printLog(responseJson); SpUtil.putBool(BytedeskConstants.exist, responseJson['data']['exist']); SpUtil.putString(BytedeskConstants.code, responseJson['data']['code']); @@ -284,7 +284,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); int statusCode = responseJson['status_code']; if (statusCode == 200) { SpUtil.putBool(BytedeskConstants.isAuthenticated, true); @@ -306,8 +306,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("getProfile:"); - // print(responseJson); + // BytedeskUtils.printLog("getProfile:"); + // BytedeskUtils.printLog(responseJson); // User user = User.fromJson(responseJson['data']); // @@ -334,8 +334,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("updateNickname:"); - print(responseJson); + BytedeskUtils.printLog("updateNickname:"); + BytedeskUtils.printLog(responseJson); // 更新本地数据 SpUtil.putString(BytedeskConstants.nickname, nickname!); @@ -356,8 +356,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("updateAvatar:"); - print(responseJson); + BytedeskUtils.printLog("updateAvatar:"); + BytedeskUtils.printLog(responseJson); // 更新本地数据 SpUtil.putString(BytedeskConstants.avatar, avatar!); @@ -378,8 +378,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("updateDescription:"); - print(responseJson); + BytedeskUtils.printLog("updateDescription:"); + BytedeskUtils.printLog(responseJson); // 更新本地数据 SpUtil.putString(BytedeskConstants.description, description!); @@ -406,8 +406,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("updateProfile:"); - print(responseJson); + BytedeskUtils.printLog("updateProfile:"); + BytedeskUtils.printLog(responseJson); // 更新本地数据 SpUtil.putString(BytedeskConstants.nickname, nickname!); SpUtil.putString(BytedeskConstants.avatar, avatar!); @@ -430,7 +430,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("updateSex $responseJson"); + // BytedeskUtils.printLog("updateSex $responseJson"); // 更新本地数据 SpUtil.putBool(BytedeskConstants.sex, sex!); @@ -451,7 +451,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("updateLocation $responseJson"); + // BytedeskUtils.printLog("updateLocation $responseJson"); // 更新本地数据 SpUtil.putString(BytedeskConstants.location, location!); @@ -472,7 +472,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("updateBirthday $responseJson"); + // BytedeskUtils.printLog("updateBirthday $responseJson"); // 更新本地数据 SpUtil.putString(BytedeskConstants.birthday, birthday!); @@ -493,7 +493,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("updateMobile $responseJson"); + // BytedeskUtils.printLog("updateMobile $responseJson"); // 更新本地数据 SpUtil.putString(BytedeskConstants.mobile, mobile!); @@ -507,7 +507,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { String? username = SpUtil.getString(BytedeskConstants.uid); final uploadUrl = '$baseUrl/visitor/api/upload/image'; - print("fileName $fileName, username $username, upload Url $uploadUrl"); + BytedeskUtils.printLog("fileName $fileName, username $username, upload Url $uploadUrl"); var uri = Uri.parse(uploadUrl); var request = http.MultipartRequest('POST', uri) @@ -517,17 +517,17 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { http.Response response = await http.Response.fromStream(await request.send()); - // print("Result: ${response.body}"); + // BytedeskUtils.printLog("Result: ${response.body}"); //解决json解析中的乱码问题 Utf8Decoder utf8decoder = Utf8Decoder(); // fix 中文乱码 //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(response.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // TODO: 根据status_code判断结果,并解析 String? url = responseJson['data']; - // print('url:' + url); + // BytedeskUtils.printLog('url:' + url); return url!; } @@ -545,7 +545,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // TODO: 根据status_code判断结果,并解析 // 解析 return responseJson['data']['status'].toString(); @@ -563,7 +563,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // TODO: 根据status_code判断结果,并解析 // 解析 return responseJson['data']['status'].toString(); @@ -583,7 +583,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // TODO: 根据status_code判断结果,并解析 // 解析 return responseJson['data'].toString(); @@ -601,7 +601,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // TODO: 根据status_code判断结果,并解析 // 解析 return responseJson['data'].toString(); @@ -619,7 +619,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // TODO: 根据status_code判断结果,并解析 // 解析 return responseJson['data'].toString(); @@ -637,8 +637,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("checkAppVersion:"); - print(responseJson); + BytedeskUtils.printLog("checkAppVersion:"); + BytedeskUtils.printLog(responseJson); // 判断token是否过期 if (responseJson.toString().contains('invalid_token')) { bytedeskEventBus.fire(InvalidTokenEventBus()); @@ -663,7 +663,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // 解析 return responseJson['data'].toString(); } @@ -682,7 +682,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // 解析 return WeChatResult.fromJson(responseJson); } @@ -714,7 +714,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // UserJsonResult userJsonResult = UserJsonResult.fromJson(responseJson); if (userJsonResult.statusCode == 200) { @@ -749,7 +749,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // UserJsonResult userJsonResult = UserJsonResult.fromJson(responseJson); if (userJsonResult.statusCode == 200) { @@ -773,7 +773,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("responseJson $responseJson"); + // BytedeskUtils.printLog("responseJson $responseJson"); // 解析 return responseJson['data']; } @@ -790,7 +790,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("responseJson $responseJson"); + BytedeskUtils.printLog("responseJson $responseJson"); // return JsonResult.fromJson(responseJson); } @@ -807,8 +807,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - // print("unfollow:"); - // print(responseJson); + // BytedeskUtils.printLog("unfollow:"); + // BytedeskUtils.printLog(responseJson); return JsonResult.fromJson(responseJson); } @@ -827,8 +827,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi { //将string类型数据 转换为json类型的数据 final responseJson = json.decode(utf8decoder.convert(initResponse.bodyBytes)); - print("logout:"); - print(responseJson); + BytedeskUtils.printLog("logout:"); + BytedeskUtils.printLog(responseJson); BytedeskUtils.clearUserCache(); } } diff --git a/bytedesk_kefu/lib/model/answer.dart b/bytedesk_kefu/lib/model/answer.dart index 781d02b..4df80d8 100755 --- a/bytedesk_kefu/lib/model/answer.dart +++ b/bytedesk_kefu/lib/model/answer.dart @@ -9,8 +9,8 @@ class Answer extends Equatable { Answer({this.aid, this.question, this.answer}) : super(); // static Answer fromJson(dynamic json) { - // print('aid:' + json['aid']); - // print('question:' + json['question']); + // BytedeskUtils.printLog('aid:' + json['aid']); + // BytedeskUtils.printLog('question:' + json['question']); return Answer( aid: json['aid'], question: json['question'], answer: json['answer']); } diff --git a/bytedesk_kefu/lib/model/messageProvider.dart b/bytedesk_kefu/lib/model/messageProvider.dart index e1da2d7..9aa1a11 100755 --- a/bytedesk_kefu/lib/model/messageProvider.dart +++ b/bytedesk_kefu/lib/model/messageProvider.dart @@ -70,7 +70,7 @@ class MessageProvider { version: 10, ); // database path:/Users/ningjinpeng/Library/Developer/CoreSimulator/Devices/715CBA02-A602-4DE1-8C57-75A64B53BF03/data/Containers/Data/Application/8F46273D-9492-4C42-A618-4DF3815562BA/Documents/bytedesk-message-v9.db - // print('database path:' + database!.path); + BytedeskUtils.printLog('database path:' + database!.path); } Future insert(Message message) async { @@ -78,19 +78,19 @@ class MessageProvider { if (BytedeskUtils.isWeb) { return 0; } - // print('insert avatar:' + message.avatar + ' conten:' + message.content + ' timestamp:' + message.timestamp); + // BytedeskUtils.printLog('insert avatar:' + message.avatar + ' conten:' + message.content + ' timestamp:' + message.timestamp); return await database!.insert(tableMessage!, message.toMap()); } // Future> getTopicMessages( String? topic, String? currentUid, int? page, int? size) async { - // print('1: ' + topic! + ' currentUid:' + currentUid!); + // BytedeskUtils.printLog('1: ' + topic! + ' currentUid:' + currentUid!); // FIXME: 暂不支持web if (BytedeskUtils.isWeb) { return []; } - // print('2'); + // BytedeskUtils.printLog('2'); // List maps = await database!.query(tableMessage!, columns: [ @@ -117,8 +117,8 @@ class MessageProvider { limit: size, offset: page! * size!); // - // print('3'); - // print(maps.length); + // BytedeskUtils.printLog('3'); + // BytedeskUtils.printLog(maps.length); // return List.generate(maps.length, (i) { // @@ -140,7 +140,7 @@ class MessageProvider { // .map((item) => Category.fromJson(item)) // .toList(); // } - // print('4'); + // BytedeskUtils.printLog('4'); return Message( mid: maps[i]['mid'], content: maps[i]['content'], diff --git a/bytedesk_kefu/lib/model/threadProvider.dart b/bytedesk_kefu/lib/model/threadProvider.dart index 2edc3df..07ded74 100644 --- a/bytedesk_kefu/lib/model/threadProvider.dart +++ b/bytedesk_kefu/lib/model/threadProvider.dart @@ -58,7 +58,7 @@ class ThreadProvider { } Future insert(Thread thread) async { - // print('insert avatar:' + message.avatar + ' conten:' + message.content + ' timestamp:' + message.timestamp); + // BytedeskUtils.printLog('insert avatar:' + message.avatar + ' conten:' + message.content + ' timestamp:' + message.timestamp); return await database!.insert(tableThread!, thread.toMap()); } diff --git a/bytedesk_kefu/lib/mqtt/bytedesk_mqtt.dart b/bytedesk_kefu/lib/mqtt/bytedesk_mqtt.dart index 47ee193..62add9c 100755 --- a/bytedesk_kefu/lib/mqtt/bytedesk_mqtt.dart +++ b/bytedesk_kefu/lib/mqtt/bytedesk_mqtt.dart @@ -117,9 +117,7 @@ class BytedeskMqtt { // .withWillMessage('My Will message') // .startClean() // Non persistent session for testing // .withWillQos(MqttQos.atLeastOnce); - if (BytedeskConstants.isDebug) { - print('mqttClient connecting....'); - } + BytedeskUtils.printLog('mqttClient connecting....'); mqttClient.connectionMessage = connMessage; /// Connect the client, any errors here are communicated by raising of the appropriate exception. Note @@ -128,16 +126,16 @@ class BytedeskMqtt { try { await mqttClient.connect(); } on Exception catch (e) { - print('mqttClient exception - $e'); + BytedeskUtils.printLog('mqttClient exception - $e'); mqttClient.disconnect(); } /// Check we are connected if (mqttClient.connectionStatus.state == MqttConnectionState.connected) { - print('mqttClient connected'); + BytedeskUtils.printLog('mqttClient connected'); } else { /// Use status here rather than state if you also want the broker return code. - print( + BytedeskUtils.printLog( 'ERROR mqttClient connection failed - disconnecting, status is ${mqttClient.connectionStatus}'); mqttClient.disconnect(); // exit(-1); @@ -149,14 +147,14 @@ class BytedeskMqtt { // final MqttPublishMessage recMess = c[0].payload; // final String pt = // MqttPublishPayload.bytesToStringAsString(recMess.payload.message); - // // print('Change notification:: topic is <${c[0].topic}>, payload is <-- $pt -->'); + // // BytedeskUtils.printLog('Change notification:: topic is <${c[0].topic}>, payload is <-- $pt -->'); // }); /// 收到的消息 // if (mqttClient != null && mqttClient.published != null) { // mqttClient.published!.listen((MqttPublishMessage messageBinary) { - // print('Published notification:: topic is ${messageBinary.variableHeader.topicName}, with Qos ${messageBinary.header.qos}'); + // BytedeskUtils.printLog('Published notification:: topic is ${messageBinary.variableHeader.topicName}, with Qos ${messageBinary.header.qos}'); // protomsg.Message messageProto = protomsg.Message.fromBuffer(messageBinary.payload.message); @@ -177,14 +175,12 @@ class BytedeskMqtt { var timestamp = messageProto.timestamp; var client = messageProto.client; // - if (BytedeskConstants.isDebug) { - print('bytedesk_mqtt.dart receive type:' + - type + - ' client:' + - client + - ' mid:' + - mid); - } + BytedeskUtils.printLog('bytedesk_mqtt.dart receive type:' + + type + + ' client:' + + client + + ' mid:' + + mid); // 非会话消息,如:会议通知等, 另行处理 if (type == BytedeskConstants.MESSAGE_TYPE_NOTIFICATION_NOTICE) { // TODO: 待处理 @@ -232,6 +228,7 @@ class BytedeskMqtt { sendReceipt = true; // TODO: 判断是否加密,暂时不需要 message.content = messageProto.text.content; + BytedeskUtils.printLog('receive text:' + message.content!); break; } case BytedeskConstants.MESSAGE_TYPE_IMAGE: @@ -550,7 +547,7 @@ class BytedeskMqtt { return; } default: - print('other message type:' + type); + BytedeskUtils.printLog('other message type:' + type); } // 客服端使用 // if (autoReply) { @@ -564,7 +561,7 @@ class BytedeskMqtt { // // final encrypter = Encrypter(AES(key, mode: AESMode.cbc)); // final decrypted = encrypter.decrypt64(messageProto.text.content, iv: iv); - // print('content: ' + decrypted); + // BytedeskUtils.printLog('content: ' + decrypted); // // 忽略连接信息 if (message.content == 'visitorConnect' || @@ -579,18 +576,18 @@ class BytedeskMqtt { bytedeskEventBus.fire(ReceiveMessageEventBus(message)); // 接收消息播放提示音,放到SDK外实现,迁移到demo中 if (BytedeskKefu.getPlayAudioOnReceiveMessage()! && message.isSend == 0) { - // print('play audio'); + // BytedeskUtils.printLog('play audio'); SystemSound.play(SystemSoundType.click); } // 振动,放到SDK外实现,迁移到demo中 if (BytedeskKefu.getVibrateOnReceiveMessage()! && message.isSend == 0) { - // print('should vibrate'); + // BytedeskUtils.printLog('should vibrate'); vibrate(); } }); // // } else { - // print('mqttClient.published is null'); + // BytedeskUtils.printLog('mqttClient.published is null'); // } } @@ -602,7 +599,7 @@ class BytedeskMqtt { } void subscribe(String topic) { - // print('Subscribing to the hello topic'); + // BytedeskUtils.printLog('Subscribing to the hello topic'); mqttClient.subscribe(topic, MqttQos.exactlyOnce); } @@ -673,16 +670,16 @@ class BytedeskMqtt { void publish(String content, String type, Thread currentThread, ExtraParam? extraParam) { // if (currentThread == null) { - // print('连接客服失败,请退出页面重新进入。注意: 请在App启动的时候,调用init接口'); + // BytedeskUtils.printLog('连接客服失败,请退出页面重新进入。注意: 请在App启动的时候,调用init接口'); // Fluttertoast.showToast(msg: '连接客服失败,请退出页面重新进入'); // return; // } // https://pub.dev/packages/encrypt#aes // final encrypter = Encrypter(AES(key, mode: AESMode.cbc)); // final encrypted = encrypter.encrypt(content, iv: iv); - // print(encrypted.base64); + // BytedeskUtils.printLog(encrypted.base64); // final decrypted = encrypter.decrypt(encrypted, iv: iv); - // print(decrypted); + // BytedeskUtils.printLog(decrypted); // thread protothread.Thread thread = new protothread.Thread(); thread.tid = currentThread.tid!; @@ -958,8 +955,8 @@ class BytedeskMqtt { // return; } else { - // TODO: 其他类型消息 - print('other type:' + type); + // 其他类型消息 + BytedeskUtils.printLog('other type:' + type); } // messageProto.user = user; @@ -992,46 +989,46 @@ class BytedeskMqtt { /// The subscribed callback void _onSubscribed(String? topic) { - // print('Subscription confirmed for topic $topic'); + // BytedeskUtils.printLog('Subscription confirmed for topic $topic'); } /// The unsubscribed callback void _onUnSubscribed(String? topic) { - // print('UnSubscription confirmed for topic $topic'); + // BytedeskUtils.printLog('UnSubscription confirmed for topic $topic'); } /// The subscribed callback void _onSubscribeFailed(String? topic) { - // print('Subscribe Failed confirmed for topic $topic'); + // BytedeskUtils.printLog('Subscribe Failed confirmed for topic $topic'); } /// The unsolicited disconnect callback void _onDisconnected() { // _isConnected = false; - // print('OnDisconnected client callback - Client disconnection'); + // BytedeskUtils.printLog('OnDisconnected client callback - Client disconnection'); // eventbus发广播,通知长连接断开 bytedeskEventBus .fire(ConnectionEventBus(BytedeskConstants.USER_STATUS_DISCONNECTED)); // if (mqttClient.connectionStatus.returnCode == MqttConnectReturnCode.solicited) { - // print('OnDisconnected callback is solicited, this is correct'); + // BytedeskUtils.printLog('OnDisconnected callback is solicited, this is correct'); // } // 延时10s执行重连 Future.delayed(Duration(seconds: 10), () { - // print('start reconnecting'); + // BytedeskUtils.printLog('start reconnecting'); // reconnect(); }); } /// The unsolicited disconnect callback // void _onAutoReconnect() { - // // print('EXAMPLE::onAutoReconnect client callback - Client auto reconnection sequence will start'); + // // BytedeskUtils.printLog('EXAMPLE::onAutoReconnect client callback - Client auto reconnection sequence will start'); // // connect(); // } /// The successful connect callback void _onConnected() { // _isConnected = true; - // print('OnConnected client callback - Client connection was sucessful'); + // BytedeskUtils.printLog('OnConnected client callback - Client connection was sucessful'); // TODO: eventbus发广播,通知长连接建立 bytedeskEventBus .fire(ConnectionEventBus(BytedeskConstants.USER_STATUS_CONNECTED)); @@ -1039,7 +1036,7 @@ class BytedeskMqtt { /// Pong callback void _onPong() { - // print('Ping response client callback invoked'); + // BytedeskUtils.printLog('Ping response client callback invoked'); } bool isConnected() { diff --git a/bytedesk_kefu/lib/mqtt/lib/src/connectionhandling/server/mqtt_client_mqtt_server_connection.dart b/bytedesk_kefu/lib/mqtt/lib/src/connectionhandling/server/mqtt_client_mqtt_server_connection.dart index ec5454b..08459fe 100644 --- a/bytedesk_kefu/lib/mqtt/lib/src/connectionhandling/server/mqtt_client_mqtt_server_connection.dart +++ b/bytedesk_kefu/lib/mqtt/lib/src/connectionhandling/server/mqtt_client_mqtt_server_connection.dart @@ -38,7 +38,8 @@ class MqttServerConnection extends MqttConnectionBase { try { listener = client.listen(_onData, onError: onError, onDone: onDone); } on Exception catch (e) { - print('MqttServerConnection::_startListening - exception raised $e'); + print( + 'MqttServerConnection::_startListening - exception raised $e'); } } diff --git a/bytedesk_kefu/lib/repositories/message_repository.dart b/bytedesk_kefu/lib/repositories/message_repository.dart index 3ac8ac0..0966795 100755 --- a/bytedesk_kefu/lib/repositories/message_repository.dart +++ b/bytedesk_kefu/lib/repositories/message_repository.dart @@ -29,6 +29,19 @@ class MessageRepository { return await bytedeskHttpApi.loadChannelMessages(cid, page, size); } + Future> loadUnreadMessages( + String? wid, int? page, int? size) async { + return await bytedeskHttpApi.loadUnreadMessages(wid, page, size); + } + + Future> loadUnreadVisitorMessages(int? page, int? size) async { + return await bytedeskHttpApi.loadUnreadMessagesVisitor(page, size); + } + + Future> loadUnreadAgentMessages(int? page, int? size) async { + return await bytedeskHttpApi.loadUnreadMessagesAgent(page, size); + } + Future queryAnswer(String? tid, String? aid, String? mid) async { return await bytedeskHttpApi.queryAnswer2(tid, aid, mid); } diff --git a/bytedesk_kefu/lib/repositories/user_repository.dart b/bytedesk_kefu/lib/repositories/user_repository.dart index c0a61df..1768530 100755 --- a/bytedesk_kefu/lib/repositories/user_repository.dart +++ b/bytedesk_kefu/lib/repositories/user_repository.dart @@ -85,12 +85,12 @@ class UserRepository { } Future logout() { - // print("user_repository logout"); + // BytedeskUtils.printLog("user_repository logout"); return Future.wait([bytedeskHttpApi.logout()]); } // Future isLogin() { - // print("user_repository isSignedIn"); + // BytedeskUtils.printLog("user_repository isSignedIn"); // // final currentUser = BytedeskHttpApi.currentUser(); // // return currentUser != null; // } @@ -100,7 +100,7 @@ class UserRepository { } // Future getUsername() { - // print("user_repository getUsername"); + // BytedeskUtils.printLog("user_repository getUsername"); // return (BytedeskHttpApi.currentUser()).username; // } diff --git a/bytedesk_kefu/lib/ui/chat/page/chat_im_page.dart b/bytedesk_kefu/lib/ui/chat/page/chat_im_page.dart index c90676f..1084cdc 100755 --- a/bytedesk_kefu/lib/ui/chat/page/chat_im_page.dart +++ b/bytedesk_kefu/lib/ui/chat/page/chat_im_page.dart @@ -102,7 +102,7 @@ class _ChatIMPageState extends State // @override void initState() { - // print('chat_kf_page init'); + // BytedeskUtils.printLog('chat_kf_page init'); SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, true); // 从历史会话或者顶部通知栏进入 if (widget.isThread! && widget.thread != null) { @@ -116,14 +116,14 @@ class _ChatIMPageState extends State WidgetsBinding.instance!.addObserver(this); // 监听build完成,https://blog.csdn.net/baoolong/article/details/85097318 // WidgetsBinding.instance.addPostFrameCallback((_) { - // print('addPostFrameCallback'); + // BytedeskUtils.printLog('addPostFrameCallback'); // }); // Fluttertoast.showToast(msg: "请求中, 请稍后..."); _listener(); super.initState(); // 定时拉取聊天记录 10s _loadHistoryTimer = Timer.periodic(Duration(seconds: 10), (timer) { - // print('从服务器 load history'); + // BytedeskUtils.printLog('从服务器 load history'); BlocProvider.of(context) ..add(LoadHistoryMessageEvent(uid: _currentUid, page: 0, size: 10)); // 每隔 1 秒钟会调用一次,如果要结束调用 @@ -186,7 +186,7 @@ class _ChatIMPageState extends State // if (state.threadResult.statusCode == 200 || state.threadResult.statusCode == 201) { - print('创建新会话'); + BytedeskUtils.printLog('创建新会话'); // 插入本地 // _messageProvider.insert(state.threadResult.msg!); // TODO: 参考拼多多,在发送按钮上方显示pop商品信息,用户确认之后才会发送商品信息 @@ -203,7 +203,7 @@ class _ChatIMPageState extends State widget.postscript!, _currentThread!); } } else if (state.threadResult.statusCode == 202) { - print('提示排队中'); + BytedeskUtils.printLog('提示排队中'); // 插入本地 _messageProvider.insert(state.threadResult.msg!); // 加载本地历史消息 @@ -222,7 +222,7 @@ class _ChatIMPageState extends State widget.postscript!, _currentThread!); } } else if (state.threadResult.statusCode == 203) { - print('当前非工作时间,请自助查询或留言'); + BytedeskUtils.printLog('当前非工作时间,请自助查询或留言'); // TODO: 显示留言页面 setState(() { _currentThread = state.threadResult.msg!.thread; @@ -233,7 +233,7 @@ class _ChatIMPageState extends State _getMessages(_page, _size); _appendMessage(state.threadResult.msg!); } else if (state.threadResult.statusCode == 204) { - print('当前无客服在线,请自助查询或留言'); + BytedeskUtils.printLog('当前无客服在线,请自助查询或留言'); // TODO: 显示留言页面 setState(() { _currentThread = state.threadResult.msg!.thread; @@ -244,7 +244,7 @@ class _ChatIMPageState extends State _getMessages(_page, _size); _appendMessage(state.threadResult.msg!); } else if (state.threadResult.statusCode == 205) { - print('咨询前问卷'); + BytedeskUtils.printLog('咨询前问卷'); setState(() { _currentThread = state.threadResult.msg!.thread; }); @@ -255,7 +255,7 @@ class _ChatIMPageState extends State _appendMessage(state.threadResult.msg!); // } else if (state.threadResult.statusCode == 206) { - print('返回机器人初始欢迎语 + 欢迎问题列表'); + BytedeskUtils.printLog('返回机器人初始欢迎语 + 欢迎问题列表'); // TODO: 显示问题列表 setState(() { _isRobot = true; @@ -290,9 +290,10 @@ class _ChatIMPageState extends State ), BlocListener( listener: (context, state) { - // print('message state change'); + // BytedeskUtils.printLog('message state change'); if (state is ReceiveMessageState) { - print('receive message:' + state.message!.content!); + BytedeskUtils.printLog( + 'receive message:' + state.message!.content!); } else if (state is UploadImageSuccess) { _bdMqtt.sendImageMessage( state.uploadJsonResult.url!, _currentThread!); @@ -327,14 +328,15 @@ class _ChatIMPageState extends State // TODO: } else if (state is LoadHistoryMessageSuccess) { // TODO: 插入历史聊天记录 - // print('history ${state.messageList!.length}'); + // BytedeskUtils.printLog('history ${state.messageList!.length}'); for (var i = 0; i < state.messageList!.length; i++) { // Message message = state.messageList[i]; // _appendMessage(message); } } else if (state is LoadTopicMessageSuccess) { // TODO: 插入历史聊天记录 - print('topic history ${state.messageList!.length}'); + BytedeskUtils.printLog( + 'topic history ${state.messageList!.length}'); for (var i = 0; i < state.messageList!.length; i++) { // Message message = state.messageList[i]; // _appendMessage(message); @@ -375,7 +377,7 @@ class _ChatIMPageState extends State child: SmartRefresher( enablePullDown: false, onLoading: () async { - print('TODO: 下拉刷新'); // 注意:方向跟默认是反着的 + BytedeskUtils.printLog('TODO: 下拉刷新'); // 注意:方向跟默认是反着的 // await Future.delayed(Duration(milliseconds: 1000)); _getMessages(_page, _size); setState(() {}); @@ -457,7 +459,7 @@ class _ChatIMPageState extends State if (_debounce?.isActive ?? false) _debounce!.cancel(); // 积累500毫秒,再发送。否则发送过于频繁 _debounce = Timer(const Duration(milliseconds: 500), () { - print('send preview $value'); + BytedeskUtils.printLog('send preview $value'); // 发送预知消息 value != null && if (value.trim().length > 0) { _bdMqtt.sendPreviewMessage(value, _currentThread!); @@ -512,7 +514,7 @@ class _ChatIMPageState extends State // 长连接正常情况下,调用长连接接口 _bdMqtt.sendTextMessage(text, _currentThread!); } else { - print('长连接断开的情况下,调用rest接口'); + BytedeskUtils.printLog('长连接断开的情况下,调用rest接口'); String? mid = BytedeskUuid.generateV4(); String? timestamp = BytedeskUtils.formatedDateNow(); String? client = BytedeskUtils.getClient(); @@ -574,7 +576,7 @@ class _ChatIMPageState extends State _listener() { // 更新消息状态 bytedeskEventBus.on().listen((event) { - // print('更新状态:' + event.status); + // BytedeskUtils.printLog('更新状态:' + event.status); if (!this.mounted) { return; } @@ -591,7 +593,7 @@ class _ChatIMPageState extends State } }); bytedeskEventBus.on().listen((event) { - // print('消息预知'); + // BytedeskUtils.printLog('消息预知'); if (this.mounted) { setState(() { // TODO: 国际化,支持英文 @@ -602,7 +604,7 @@ class _ChatIMPageState extends State Timer( Duration(seconds: 3), () { - // print('timer'); + // BytedeskUtils.printLog('timer'); if (this.mounted) { setState(() { _title = widget.title; @@ -613,11 +615,11 @@ class _ChatIMPageState extends State }); // 同 DeleteMessageEventBus 事件 // bytedeskEventBus.on().listen((event) { - // print('消息撤回'); + // BytedeskUtils.printLog('消息撤回'); // }); // 接收到新消息 bytedeskEventBus.on().listen((event) { - // print('receive message:' + event.message!.content); + // BytedeskUtils.printLog('receive message:' + event.message!.content); if (_currentThread != null && (event.message.thread!.topic != _currentThread!.topic)) { return; @@ -656,7 +658,7 @@ class _ChatIMPageState extends State bytedeskEventBus.on().listen((event) { // if (this.mounted) { - print( + BytedeskUtils.printLog( 'aid ${event.aid}, question ${event.question}, answer ${event.answer}'); // 可以直接将问题和答案插入本地,并显示,但为了服务器保存查询记录,特将请求发送给服务器 // BlocProvider.of(context) @@ -673,7 +675,7 @@ class _ChatIMPageState extends State // 如果滑动到底部 // if (_scrollController.position.pixels == // _scrollController.position.maxScrollExtent) { - // print('已经到底了'); + // BytedeskUtils.printLog('已经到底了'); // } }); } @@ -685,7 +687,7 @@ class _ChatIMPageState extends State source: ImageSource.gallery, maxWidth: 800, imageQuality: 95); // if (pickedFile != null) { - print('pick image path: ${pickedFile.path}'); + BytedeskUtils.printLog('pick image path: ${pickedFile.path}'); // TODO: 将图片显示到对话消息中 // TODO: 显示处理中loading // 压缩 @@ -694,7 +696,7 @@ class _ChatIMPageState extends State // "/" + // BytedeskUtils.currentTimeMillis().toString() + // ".jpg"; - // print('targetPath: $targetPath'); + // BytedeskUtils.printLog('targetPath: $targetPath'); // await BytedeskUtils.compressImage(File(pickedFile.path), targetPath); // // 上传压缩后图片 // BlocProvider.of(context) @@ -706,7 +708,7 @@ class _ChatIMPageState extends State Fluttertoast.showToast(msg: '未选取图片'); } } catch (e) { - print('pick image error ${e.toString()}'); + BytedeskUtils.printLog('pick image error ${e.toString()}'); Fluttertoast.showToast(msg: "未选取图片"); } } @@ -718,7 +720,7 @@ class _ChatIMPageState extends State source: ImageSource.camera, maxWidth: 800, imageQuality: 95); // if (pickedFile != null) { - print('take image path: ${pickedFile.path}'); + BytedeskUtils.printLog('take image path: ${pickedFile.path}'); // TODO: 将图片显示到对话消息中 // TODO: 显示处理中loading // 压缩 @@ -727,7 +729,7 @@ class _ChatIMPageState extends State // "/" + // BytedeskUtils.currentTimeMillis().toString() + // ".jpg"; - // print('targetPath: $targetPath'); + // BytedeskUtils.printLog('targetPath: $targetPath'); // await BytedeskUtils.compressImage(File(pickedFile.path), targetPath); // // 上传压缩后图片 // BlocProvider.of(context) @@ -739,7 +741,7 @@ class _ChatIMPageState extends State Fluttertoast.showToast(msg: '未拍照'); } } catch (e) { - print('take image error ${e.toString()}'); + BytedeskUtils.printLog('take image error ${e.toString()}'); Fluttertoast.showToast(msg: "未选取图片"); } } @@ -751,7 +753,7 @@ class _ChatIMPageState extends State try { // final PickedFile videoFile = await _picker.getVideo( // source: ImageSource.gallery, maxDuration: const Duration(seconds: 10)); - // print('pick video path: ${videoFile.path}'); + // BytedeskUtils.printLog('pick video path: ${videoFile.path}'); // if (videoFile != null) { // BlocProvider.of(context) // ..add(UploadVideoEvent(filePath: videoFile.path)); @@ -775,9 +777,9 @@ class _ChatIMPageState extends State // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) // deleteOrigin: false, // default(false) // ); - // // debugPrint(info.toJson().toString()); + // // debugBytedeskUtils.printLog(info.toJson().toString()); // String? afterPath = info.toJson()['path']; - // // print('video path: ${_paths[0].path}, compress path: $afterPath'); + // // BytedeskUtils.printLog('video path: ${_paths[0].path}, compress path: $afterPath'); // // 上传 // BlocProvider.of(context) // ..add(UploadVideoEvent(filePath: afterPath)); @@ -786,7 +788,7 @@ class _ChatIMPageState extends State ..add(UploadVideoEvent(filePath: _paths[0].path)); } } catch (e) { - print('pick video error ${e.toString()}'); + BytedeskUtils.printLog('pick video error ${e.toString()}'); Fluttertoast.showToast(msg: "未选取视频"); } } @@ -798,7 +800,7 @@ class _ChatIMPageState extends State source: ImageSource.camera, maxDuration: const Duration(seconds: 10)); // if (pickedFile != null) { - print('take video path: ${pickedFile.path}'); + BytedeskUtils.printLog('take video path: ${pickedFile.path}'); // TODO: 将图片显示到对话消息中 // TODO: 显示处理中loading // 压缩 @@ -808,9 +810,9 @@ class _ChatIMPageState extends State // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) // deleteOrigin: false, // default(false) // ); - // // debugPrint(info.toJson().toString()); + // // debugBytedeskUtils.printLog(info.toJson().toString()); // String? afterPath = info.toJson()['path']; - // // print('video path: ${pickedFile.path}, compress path: $afterPath'); + // // BytedeskUtils.printLog('video path: ${pickedFile.path}, compress path: $afterPath'); // // 上传 // BlocProvider.of(context) // ..add(UploadVideoEvent(filePath: afterPath)); @@ -821,14 +823,14 @@ class _ChatIMPageState extends State Fluttertoast.showToast(msg: '未录制视频'); } } catch (e) { - print('take video error ${e.toString()}'); + BytedeskUtils.printLog('take video error ${e.toString()}'); Fluttertoast.showToast(msg: "未录制视频"); } } // 加载更多聊天记录 // Future _loadMoreMessages() async { - // print('load more'); + // BytedeskUtils.printLog('load more'); // // TODO: 从服务器加载 // _getMessages(_page, _size); // } @@ -857,7 +859,7 @@ class _ChatIMPageState extends State } Future _appendMessage(Message message) async { - // print('append:' + message!.mid); + // BytedeskUtils.printLog('append:' + message!.mid); bool contains = false; for (var i = 0; i < _messages.length; i++) { Message? element = _messages[i].message; @@ -895,7 +897,7 @@ class _ChatIMPageState extends State @override void didChangeAppLifecycleState(AppLifecycleState state) { - // print("didChangeAppLifecycleState:" + state.toString()); + // BytedeskUtils.printLog("didChangeAppLifecycleState:" + state.toString()); switch (state) { case AppLifecycleState.inactive: // 处于这种状态的应用程序应该假设它们可能在任何时候暂停。 break; @@ -913,7 +915,7 @@ class _ChatIMPageState extends State @override void dispose() { - // print('chat_kf_page dispose'); + // BytedeskUtils.printLog('chat_kf_page dispose'); SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, false); WidgetsBinding.instance!.removeObserver(this); _debounce?.cancel(); 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 0d4948d..6d81382 100755 --- a/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart +++ b/bytedesk_kefu/lib/ui/chat/page/chat_kf_page.dart @@ -100,14 +100,14 @@ class _ChatKFPageState extends State // 延迟发送preview消息 Timer? _debounce; // 定时拉取聊天记录 - // Timer? _loadHistoryTimer; + Timer? _loadHistoryTimer; // 视频压缩 // final _flutterVideoCompress = FlutterVideoCompress(); bool _isRequestingThread = true; // @override void initState() { - // print('chat_kf_page init'); + // BytedeskUtils.printLog('chat_kf_page init'); SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, true); // 从历史会话或者顶部通知栏进入 if (widget.isThread! && widget.thread != null) { @@ -124,20 +124,22 @@ class _ChatKFPageState extends State WidgetsBinding.instance!.addObserver(this); // 监听build完成,https://blog.csdn.net/baoolong/article/details/85097318 // WidgetsBinding.instance.addPostFrameCallback((_) { - // print('addPostFrameCallback'); + // BytedeskUtils.printLog('addPostFrameCallback'); // }); // Fluttertoast.showToast(msg: "请求中, 请稍后..."); _listener(); super.initState(); // 定时拉取聊天记录 10s - // _loadHistoryTimer = Timer.periodic(Duration(seconds: 10), (timer) { - // // print('从服务器 load history'); - // // TODO: 暂时禁用从服务器加载历史记录 - // // BlocProvider.of(context) - // // ..add(LoadHistoryMessageEvent(uid: _currentUid, page: 0, size: 10)); - // // 每隔 1 秒钟会调用一次,如果要结束调用 - // // timer.cancel(); - // }); + _loadHistoryTimer = Timer.periodic(Duration(seconds: 15), (timer) { + // BytedeskUtils.printLog('从服务器 load history'); + // // TODO: 暂时禁用从服务器加载历史记录 + // BlocProvider.of(context) + // ..add(LoadHistoryMessageEvent(uid: _currentUid, page: 0, size: 10)); + // // 每隔 1 秒钟会调用一次,如果要结束调用 + // // timer.cancel(); + }); + BlocProvider.of(context) + ..add(LoadUnreadVisitorMessagesEvent(page: 0, size: 10)); } // @@ -197,7 +199,7 @@ class _ChatKFPageState extends State // if (state.threadResult.statusCode == 200 || state.threadResult.statusCode == 201) { - print('创建新会话'); + BytedeskUtils.printLog('创建新会话'); // TODO: 参考拼多多,在发送按钮上方显示pop商品信息,用户确认之后才会发送商品信息 // 发送商品信息 if (widget.custom != null && @@ -212,7 +214,7 @@ class _ChatKFPageState extends State widget.postscript!, _currentThread!); } } else if (state.threadResult.statusCode == 202) { - print('提示排队中'); + BytedeskUtils.printLog('提示排队中'); // 插入本地 _messageProvider.insert(state.threadResult.msg!); // 加载本地历史消息 @@ -230,7 +232,7 @@ class _ChatKFPageState extends State widget.postscript!, _currentThread!); } } else if (state.threadResult.statusCode == 203) { - print('当前非工作时间,请自助查询或留言'); + BytedeskUtils.printLog('当前非工作时间,请自助查询或留言'); setState(() { _currentThread = state.threadResult.msg!.thread; }); @@ -248,7 +250,7 @@ class _ChatKFPageState extends State tip: state.threadResult.msg!.content); })); } else if (state.threadResult.statusCode == 204) { - print('当前无客服在线,请自助查询或留言'); + BytedeskUtils.printLog('当前无客服在线,请自助查询或留言'); setState(() { _currentThread = state.threadResult.msg!.thread; }); @@ -267,7 +269,7 @@ class _ChatKFPageState extends State tip: state.threadResult.msg!.content); })); } else if (state.threadResult.statusCode == 205) { - print('咨询前问卷'); + BytedeskUtils.printLog('咨询前问卷'); setState(() { _currentThread = state.threadResult.msg!.thread; }); @@ -278,7 +280,7 @@ class _ChatKFPageState extends State _appendMessage(state.threadResult.msg!); // } else if (state.threadResult.statusCode == 206) { - // print('返回机器人初始欢迎语 + 欢迎问题列表'); + // BytedeskUtils.printLog('返回机器人初始欢迎语 + 欢迎问题列表'); // TODO: 显示问题列表 setState(() { _isRobot = true; @@ -329,9 +331,9 @@ class _ChatKFPageState extends State ), BlocListener( listener: (context, state) { - // print('message state change'); + // BytedeskUtils.printLog('message state change'); if (state is ReceiveMessageState) { - // print('receive message:' + state.message!.content!); + // BytedeskUtils.printLog('receive message:' + state.message!.content!); } else if (state is MessageUpLoading) { Fluttertoast.showToast(msg: '上传中...'); } else if (state is UploadImageSuccess) { @@ -375,7 +377,13 @@ class _ChatKFPageState extends State } else if (state is RateAnswerSuccess) { // TODO: } else if (state is LoadHistoryMessageSuccess) { - // print('LoadHistoryMessageSuccess'); + // BytedeskUtils.printLog('LoadHistoryMessageSuccess'); + // 插入历史聊天记录 + for (var i = 0; i < state.messageList!.length; i++) { + Message message = state.messageList![i]; + _appendMessage(message); + } + } else if (state is LoadUnreadVisitorMessageSuccess) { // 插入历史聊天记录 for (var i = 0; i < state.messageList!.length; i++) { Message message = state.messageList![i]; @@ -406,7 +414,7 @@ class _ChatKFPageState extends State child: SmartRefresher( enablePullDown: false, onLoading: () async { - // print('TODO: 下拉刷新'); // 注意:方向跟默认是反着的 + // BytedeskUtils.printLog('TODO: 下拉刷新'); // 注意:方向跟默认是反着的 // await Future.delayed(Duration(milliseconds: 1000)); _getMessages(_page, _size); setState(() {}); @@ -490,7 +498,7 @@ class _ChatKFPageState extends State if (_debounce?.isActive ?? false) _debounce!.cancel(); // 积累500毫秒,再发送。否则发送过于频繁 _debounce = Timer(const Duration(milliseconds: 500), () { - // print('send preview $value'); + // BytedeskUtils.printLog('send preview $value'); // 发送预知消息 if (value.trim().length > 0) { _bdMqtt.sendPreviewMessage(value, _currentThread!); @@ -547,7 +555,7 @@ class _ChatKFPageState extends State // 长连接正常情况下,调用长连接接口 _bdMqtt.sendTextMessage(text, _currentThread!); } else { - // print('长连接断开的情况下,调用rest接口'); + // BytedeskUtils.printLog('长连接断开的情况下,调用rest接口'); sendTextMessageRest(text); } } @@ -744,7 +752,7 @@ class _ChatKFPageState extends State _listener() { // 更新消息状态 bytedeskEventBus.on().listen((event) { - // print('更新状态:' + event.mid + '-' + event.status); + // BytedeskUtils.printLog('更新状态:' + event.mid + '-' + event.status); if (this.mounted) { // 更新界面 for (var i = 0; i < _messages.length; i++) { @@ -752,7 +760,7 @@ class _ChatKFPageState extends State if (messageWidget.message!.mid == event.mid && _messages[i].message!.status != BytedeskConstants.MESSAGE_STATUS_READ) { - // print('do update status:' + messageWidget.message!.mid!); + // BytedeskUtils.printLog('do update status:' + messageWidget.message!.mid!); // setState(() { // _messages[i].message!.status = event.status; // 不更新 // }); @@ -772,7 +780,7 @@ class _ChatKFPageState extends State } }); bytedeskEventBus.on().listen((event) { - // print('消息预知'); + // BytedeskUtils.printLog('消息预知'); if (this.mounted) { setState(() { // TODO: 国际化,支持英文 @@ -783,7 +791,7 @@ class _ChatKFPageState extends State Timer( Duration(seconds: 3), () { - // print('timer'); + // BytedeskUtils.printLog('timer'); if (this.mounted) { setState(() { _title = widget.title; @@ -794,7 +802,7 @@ class _ChatKFPageState extends State }); // 接收到新消息 bytedeskEventBus.on().listen((event) { - // print('receive message:' + event.message!.content); + // BytedeskUtils.printLog('receive message:' + event.message!.content); if (_currentThread != null && (event.message.thread!.topic != _currentThread!.topic)) { return; @@ -834,7 +842,7 @@ class _ChatKFPageState extends State // 查询机器人消息 bytedeskEventBus.on().listen((event) { if (this.mounted) { - // print('aid ${event.aid}, question ${event.question}, answer ${event.answer}'); + // BytedeskUtils.printLog('aid ${event.aid}, question ${event.question}, answer ${event.answer}'); // 可以直接将问题和答案插入本地,并显示,但为了服务器保存查询记录,特将请求发送给服务器 appendQueryMessage(event.question); // @@ -849,7 +857,7 @@ class _ChatKFPageState extends State // 查询分类下属问题 bytedeskEventBus.on().listen((event) { if (this.mounted) { - print('cid ${event.cid}, name ${event.name}'); + BytedeskUtils.printLog('cid ${event.cid}, name ${event.name}'); // 可以直接将问题和答案插入本地,并显示,但为了服务器保存查询记录,特将请求发送给服务器 appendQueryMessage(event.name); // @@ -872,7 +880,7 @@ class _ChatKFPageState extends State // 如果滑动到底部 // if (_scrollController.position.pixels == // _scrollController.position.maxScrollExtent) { - // print('已经到底了'); + // BytedeskUtils.printLog('已经到底了'); // } }); } @@ -885,7 +893,7 @@ class _ChatKFPageState extends State source: ImageSource.gallery, maxWidth: 800, imageQuality: 95); // if (pickedFile != null) { - print('pick image path: ${pickedFile.path}'); + BytedeskUtils.printLog('pick image path: ${pickedFile.path}'); // TODO: 将图片显示到对话消息中 // TODO: 显示处理中loading // 压缩 @@ -894,7 +902,7 @@ class _ChatKFPageState extends State // "/" + // BytedeskUtils.currentTimeMillis().toString() + // ".jpg"; - // print('targetPath: $targetPath'); + // BytedeskUtils.printLog('targetPath: $targetPath'); // await BytedeskUtils.compressImage(File(pickedFile.path), targetPath); // // 上传压缩后图片 // BlocProvider.of(context) @@ -906,7 +914,7 @@ class _ChatKFPageState extends State Fluttertoast.showToast(msg: '未选取图片'); } } catch (e) { - print('pick image error ${e.toString()}'); + BytedeskUtils.printLog('pick image error ${e.toString()}'); Fluttertoast.showToast(msg: "未选取图片"); } } @@ -918,7 +926,7 @@ class _ChatKFPageState extends State source: ImageSource.camera, maxWidth: 800, imageQuality: 95); // if (pickedFile != null) { - print('take image path: ${pickedFile.path}'); + BytedeskUtils.printLog('take image path: ${pickedFile.path}'); // TODO: 将图片显示到对话消息中 // TODO: 显示处理中loading // 压缩 @@ -927,7 +935,7 @@ class _ChatKFPageState extends State // "/" + // BytedeskUtils.currentTimeMillis().toString() + // ".jpg"; - // print('targetPath: $targetPath'); + // BytedeskUtils.printLog('targetPath: $targetPath'); // await BytedeskUtils.compressImage(File(pickedFile.path), targetPath); // // 上传压缩后图片 // BlocProvider.of(context) @@ -939,7 +947,7 @@ class _ChatKFPageState extends State Fluttertoast.showToast(msg: '未拍照'); } } catch (e) { - print('take image error ${e.toString()}'); + BytedeskUtils.printLog('take image error ${e.toString()}'); Fluttertoast.showToast(msg: "未选取图片"); } } @@ -951,7 +959,7 @@ class _ChatKFPageState extends State try { // final PickedFile videoFile = await _picker.getVideo( // source: ImageSource.gallery, maxDuration: const Duration(seconds: 10)); - // print('pick video path: ${videoFile.path}'); + // BytedeskUtils.printLog('pick video path: ${videoFile.path}'); // if (videoFile != null) { // BlocProvider.of(context) // ..add(UploadVideoEvent(filePath: videoFile.path)); @@ -975,9 +983,9 @@ class _ChatKFPageState extends State // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) // deleteOrigin: false, // default(false) // ); - // // debugPrint(info.toJson().toString()); + // // debugBytedeskUtils.printLog(info.toJson().toString()); // String? afterPath = info.toJson()['path']; - // // print('video path: ${_paths[0].path}, compress path: $afterPath'); + // // BytedeskUtils.printLog('video path: ${_paths[0].path}, compress path: $afterPath'); // // 上传 // BlocProvider.of(context) // ..add(UploadVideoEvent(filePath: afterPath)); @@ -986,7 +994,7 @@ class _ChatKFPageState extends State ..add(UploadVideoEvent(filePath: _paths[0].path)); } } catch (e) { - print('pick video error ${e.toString()}'); + BytedeskUtils.printLog('pick video error ${e.toString()}'); Fluttertoast.showToast(msg: "未选取视频"); } } @@ -998,7 +1006,7 @@ class _ChatKFPageState extends State source: ImageSource.camera, maxDuration: const Duration(seconds: 10)); // if (pickedFile != null) { - print('take video path: ${pickedFile.path}'); + BytedeskUtils.printLog('take video path: ${pickedFile.path}'); // TODO: 将图片显示到对话消息中 // TODO: 显示处理中loading // 压缩 @@ -1008,9 +1016,9 @@ class _ChatKFPageState extends State // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) // deleteOrigin: false, // default(false) // ); - // // debugPrint(info.toJson().toString()); + // // debugBytedeskUtils.printLog(info.toJson().toString()); // String? afterPath = info.toJson()['path']; - // // print('video path: ${pickedFile.path}, compress path: $afterPath'); + // // BytedeskUtils.printLog('video path: ${pickedFile.path}, compress path: $afterPath'); // // 上传 // BlocProvider.of(context) // ..add(UploadVideoEvent(filePath: afterPath)); @@ -1021,14 +1029,14 @@ class _ChatKFPageState extends State Fluttertoast.showToast(msg: '未录制视频'); } } catch (e) { - print('take video error ${e.toString()}'); + BytedeskUtils.printLog('take video error ${e.toString()}'); Fluttertoast.showToast(msg: "未录制视频"); } } // 加载更多聊天记录 // Future _loadMoreMessages() async { - // print('load more'); + // BytedeskUtils.printLog('load more'); // // TODO: 从服务器加载 // _getMessages(_page, _size); // } @@ -1042,7 +1050,7 @@ class _ChatKFPageState extends State // List messageList = await _messageProvider.getTopicMessages( _currentThread!.topic, _currentUid, page, size); - // print(messageList.length); + // BytedeskUtils.printLog(messageList.length); int length = messageList.length; for (var i = 0; i < length; i++) { Message message = messageList[i]; @@ -1103,15 +1111,16 @@ class _ChatKFPageState extends State if (message.status != BytedeskConstants.MESSAGE_STATUS_READ) { // 发送已读回执 if (message.isSend == 0) { - print('message.mid ${message.mid}'); - print('_currentThread ${_currentThread!.tid}'); + // BytedeskUtils.printLog('message.mid ${message.mid}'); + // BytedeskUtils.printLog('_currentThread ${_currentThread!.tid}'); _bdMqtt.sendReceiptReadMessage(message.mid!, _currentThread!); } } } Future _appendMessage(Message message) async { - print('append:' + message.mid! + 'content:' + message.content!); + BytedeskUtils.printLog( + 'append:' + message.mid! + 'content:' + message.content!); pushToMessageArray(message, true); } @@ -1130,7 +1139,7 @@ class _ChatKFPageState extends State @override void didChangeAppLifecycleState(AppLifecycleState state) { - // print("didChangeAppLifecycleState:" + state.toString()); + // BytedeskUtils.printLog("didChangeAppLifecycleState:" + state.toString()); switch (state) { case AppLifecycleState.inactive: // 处于这种状态的应用程序应该假设它们可能在任何时候暂停。 break; @@ -1148,11 +1157,12 @@ class _ChatKFPageState extends State @override void dispose() { - // print('chat_kf_page dispose'); + // BytedeskUtils.printLog('chat_kf_page dispose'); SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, false); WidgetsBinding.instance!.removeObserver(this); _debounce?.cancel(); - // _loadHistoryTimer?.cancel(); + _loadHistoryTimer?.cancel(); + // bytedeskEventBus.destroy(); // FIXME: 只能取消监听,不能destroy super.dispose(); } } diff --git a/bytedesk_kefu/lib/ui/chat/page/chat_ls_page.dart b/bytedesk_kefu/lib/ui/chat/page/chat_ls_page.dart index cb5d29e..e59f0ba 100755 --- a/bytedesk_kefu/lib/ui/chat/page/chat_ls_page.dart +++ b/bytedesk_kefu/lib/ui/chat/page/chat_ls_page.dart @@ -21,6 +21,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:image_picker/image_picker.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; // import 'package:path_provider/path_provider.dart' as path_provider; // TODO: 良师APP对话页面 @@ -96,7 +97,7 @@ class _ChatLSPageState extends State // @override void initState() { - // print('chat_kf_page init'); + // BytedeskUtils.printLog('chat_kf_page init'); SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, true); // 从历史会话或者顶部通知栏进入 if (widget.isThread! && widget.thread != null) { @@ -113,7 +114,7 @@ class _ChatLSPageState extends State WidgetsBinding.instance!.addObserver(this); // 监听build完成,https://blog.csdn.net/baoolong/article/details/85097318 // WidgetsBinding.instance.addPostFrameCallback((_) { - // print('addPostFrameCallback'); + // BytedeskUtils.printLog('addPostFrameCallback'); // }); _listener(); super.initState(); @@ -172,7 +173,7 @@ class _ChatLSPageState extends State // if (state.threadResult.statusCode == 200 || state.threadResult.statusCode == 201) { - print('创建新会话'); + BytedeskUtils.printLog('创建新会话'); // 插入本地 // _messageProvider.insert(state.threadResult.msg!); // TODO: 参考拼多多,在发送按钮上方显示pop商品信息,用户确认之后才会发送商品信息 @@ -189,7 +190,7 @@ class _ChatLSPageState extends State widget.postscript!, _currentThread!); } } else if (state.threadResult.statusCode == 202) { - print('提示排队中'); + BytedeskUtils.printLog('提示排队中'); // 插入本地 _messageProvider.insert(state.threadResult.msg!); // 加载本地历史消息 @@ -208,7 +209,7 @@ class _ChatLSPageState extends State widget.postscript!, _currentThread!); } } else if (state.threadResult.statusCode == 203) { - print('当前非工作时间,请自助查询或留言'); + BytedeskUtils.printLog('当前非工作时间,请自助查询或留言'); // TODO: 显示留言页面 setState(() { _currentThread = state.threadResult.msg!.thread; @@ -219,7 +220,7 @@ class _ChatLSPageState extends State _getMessages(_page, _size); _appendMessage(state.threadResult.msg!); } else if (state.threadResult.statusCode == 204) { - print('当前无客服在线,请自助查询或留言'); + BytedeskUtils.printLog('当前无客服在线,请自助查询或留言'); // TODO: 显示留言页面 setState(() { _currentThread = state.threadResult.msg!.thread; @@ -230,7 +231,7 @@ class _ChatLSPageState extends State _getMessages(_page, _size); _appendMessage(state.threadResult.msg!); } else if (state.threadResult.statusCode == 205) { - print('咨询前问卷'); + BytedeskUtils.printLog('咨询前问卷'); setState(() { _currentThread = state.threadResult.msg!.thread; }); @@ -241,7 +242,7 @@ class _ChatLSPageState extends State _appendMessage(state.threadResult.msg!); // } else if (state.threadResult.statusCode == 206) { - print('返回机器人初始欢迎语 + 欢迎问题列表'); + BytedeskUtils.printLog('返回机器人初始欢迎语 + 欢迎问题列表'); // TODO: 显示问题列表 setState(() { _isRobot = true; @@ -276,9 +277,10 @@ class _ChatLSPageState extends State ), BlocListener( listener: (context, state) { - print('message state change'); + BytedeskUtils.printLog('message state change'); if (state is ReceiveMessageState) { - print('receive message:' + state.message!.content!); + BytedeskUtils.printLog( + 'receive message:' + state.message!.content!); } else if (state is UploadImageSuccess) { _bdMqtt.sendImageMessage( state.uploadJsonResult.url!, _currentThread!); @@ -345,7 +347,7 @@ class _ChatLSPageState extends State child: SmartRefresher( enablePullDown: false, onLoading: () async { - print('TODO: 下拉刷新'); // 注意:方向跟默认是反着的 + BytedeskUtils.printLog('TODO: 下拉刷新'); // 注意:方向跟默认是反着的 // await Future.delayed(Duration(milliseconds: 1000)); _getMessages(_page, _size); setState(() {}); @@ -427,7 +429,7 @@ class _ChatLSPageState extends State if (_debounce?.isActive ?? false) _debounce!.cancel(); // 积累500毫秒,再发送。否则发送过于频繁 _debounce = Timer(const Duration(milliseconds: 500), () { - print('send preview $value'); + BytedeskUtils.printLog('send preview $value'); // 发送预知消息 value != null && if (value.trim().length > 0) { _bdMqtt.sendPreviewMessage(value, _currentThread!); @@ -486,7 +488,7 @@ class _ChatLSPageState extends State _listener() { // 更新消息状态 bytedeskEventBus.on().listen((event) { - // print('更新状态:' + event.status); + // BytedeskUtils.printLog('更新状态:' + event.status); if (!this.mounted) { return; } @@ -503,7 +505,7 @@ class _ChatLSPageState extends State } }); bytedeskEventBus.on().listen((event) { - // print('消息预知'); + // BytedeskUtils.printLog('消息预知'); if (this.mounted) { setState(() { // TODO: 国际化,支持英文 @@ -514,7 +516,7 @@ class _ChatLSPageState extends State Timer( Duration(seconds: 3), () { - // print('timer'); + // BytedeskUtils.printLog('timer'); if (this.mounted) { setState(() { _title = widget.title; @@ -525,11 +527,11 @@ class _ChatLSPageState extends State }); // 同 DeleteMessageEventBus 事件 // bytedeskEventBus.on().listen((event) { - // print('消息撤回'); + // BytedeskUtils.printLog('消息撤回'); // }); // 接收到新消息 bytedeskEventBus.on().listen((event) { - // print('receive message:' + event.message!.content); + // BytedeskUtils.printLog('receive message:' + event.message!.content); if (_currentThread != null && (event.message.thread!.topic != _currentThread!.topic)) { return; @@ -568,7 +570,7 @@ class _ChatLSPageState extends State bytedeskEventBus.on().listen((event) { // if (this.mounted) { - print( + BytedeskUtils.printLog( 'aid ${event.aid}, question ${event.question}, answer ${event.answer}'); // 可以直接将问题和答案插入本地,并显示,但为了服务器保存查询记录,特将请求发送给服务器 // BlocProvider.of(context) @@ -585,7 +587,7 @@ class _ChatLSPageState extends State // 如果滑动到底部 // if (_scrollController.position.pixels == // _scrollController.position.maxScrollExtent) { - // print('已经到底了'); + // BytedeskUtils.printLog('已经到底了'); // } }); } @@ -597,7 +599,7 @@ class _ChatLSPageState extends State source: ImageSource.gallery, maxWidth: 800, imageQuality: 95); // if (pickedFile != null) { - print('pick image path: ${pickedFile.path}'); + BytedeskUtils.printLog('pick image path: ${pickedFile.path}'); // TODO: 将图片显示到对话消息中 // TODO: 显示处理中loading // 压缩 @@ -606,7 +608,7 @@ class _ChatLSPageState extends State // "/" + // BytedeskUtils.currentTimeMillis().toString() + // ".jpg"; - // print('targetPath: $targetPath'); + // BytedeskUtils.printLog('targetPath: $targetPath'); // await BytedeskUtils.compressImage(File(pickedFile.path), targetPath); // // 上传压缩后图片 // BlocProvider.of(context) @@ -618,7 +620,7 @@ class _ChatLSPageState extends State Fluttertoast.showToast(msg: '未选取图片'); } } catch (e) { - print('pick image error ${e.toString()}'); + BytedeskUtils.printLog('pick image error ${e.toString()}'); Fluttertoast.showToast(msg: "未选取图片"); } } @@ -630,7 +632,7 @@ class _ChatLSPageState extends State source: ImageSource.camera, maxWidth: 800, imageQuality: 95); // if (pickedFile != null) { - print('take image path: ${pickedFile.path}'); + BytedeskUtils.printLog('take image path: ${pickedFile.path}'); // TODO: 将图片显示到对话消息中 // TODO: 显示处理中loading // 压缩 @@ -639,7 +641,7 @@ class _ChatLSPageState extends State // "/" + // BytedeskUtils.currentTimeMillis().toString() + // ".jpg"; - // print('targetPath: $targetPath'); + // BytedeskUtils.printLog('targetPath: $targetPath'); // await BytedeskUtils.compressImage(File(pickedFile.path), targetPath); // // 上传压缩后图片 // BlocProvider.of(context) @@ -651,7 +653,7 @@ class _ChatLSPageState extends State Fluttertoast.showToast(msg: '未拍照'); } } catch (e) { - print('take image error ${e.toString()}'); + BytedeskUtils.printLog('take image error ${e.toString()}'); Fluttertoast.showToast(msg: "未选取图片"); } } @@ -663,7 +665,7 @@ class _ChatLSPageState extends State try { // final PickedFile videoFile = await _picker.getVideo( // source: ImageSource.gallery, maxDuration: const Duration(seconds: 10)); - // print('pick video path: ${videoFile.path}'); + // BytedeskUtils.printLog('pick video path: ${videoFile.path}'); // if (videoFile != null) { // BlocProvider.of(context) // ..add(UploadVideoEvent(filePath: videoFile.path)); @@ -687,9 +689,9 @@ class _ChatLSPageState extends State // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) // deleteOrigin: false, // default(false) // ); - // // debugPrint(info.toJson().toString()); + // // debugBytedeskUtils.printLog(info.toJson().toString()); // String? afterPath = info.toJson()['path']; - // // print('video path: ${_paths[0].path}, compress path: $afterPath'); + // // BytedeskUtils.printLog('video path: ${_paths[0].path}, compress path: $afterPath'); // // 上传 // BlocProvider.of(context) // ..add(UploadVideoEvent(filePath: afterPath)); @@ -698,7 +700,7 @@ class _ChatLSPageState extends State ..add(UploadVideoEvent(filePath: _paths[0].path)); } } catch (e) { - print('pick video error ${e.toString()}'); + BytedeskUtils.printLog('pick video error ${e.toString()}'); Fluttertoast.showToast(msg: "未选取视频"); } } @@ -710,7 +712,7 @@ class _ChatLSPageState extends State source: ImageSource.camera, maxDuration: const Duration(seconds: 10)); // if (pickedFile != null) { - print('take video path: ${pickedFile.path}'); + BytedeskUtils.printLog('take video path: ${pickedFile.path}'); // TODO: 将图片显示到对话消息中 // TODO: 显示处理中loading // 压缩 @@ -720,9 +722,9 @@ class _ChatLSPageState extends State // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) // deleteOrigin: false, // default(false) // ); - // // debugPrint(info.toJson().toString()); + // // debugBytedeskUtils.printLog(info.toJson().toString()); // String? afterPath = info.toJson()['path']; - // // print('video path: ${pickedFile.path}, compress path: $afterPath'); + // // BytedeskUtils.printLog('video path: ${pickedFile.path}, compress path: $afterPath'); // // 上传 // BlocProvider.of(context) // ..add(UploadVideoEvent(filePath: afterPath)); @@ -733,14 +735,14 @@ class _ChatLSPageState extends State Fluttertoast.showToast(msg: '未录制视频'); } } catch (e) { - print('take video error ${e.toString()}'); + BytedeskUtils.printLog('take video error ${e.toString()}'); Fluttertoast.showToast(msg: "未录制视频"); } } // 加载更多聊天记录 // Future _loadMoreMessages() async { - // print('load more'); + // BytedeskUtils.printLog('load more'); // // TODO: 从服务器加载 // _getMessages(_page, _size); // } @@ -769,7 +771,7 @@ class _ChatLSPageState extends State } Future _appendMessage(Message message) async { - // print('append:' + message!.mid); + // BytedeskUtils.printLog('append:' + message!.mid); _messageProvider.insert(message); MessageWidget messageWidget = new MessageWidget( message: message, @@ -798,7 +800,7 @@ class _ChatLSPageState extends State @override void didChangeAppLifecycleState(AppLifecycleState state) { - // print("didChangeAppLifecycleState:" + state.toString()); + // BytedeskUtils.printLog("didChangeAppLifecycleState:" + state.toString()); switch (state) { case AppLifecycleState.inactive: // 处于这种状态的应用程序应该假设它们可能在任何时候暂停。 break; @@ -816,7 +818,7 @@ class _ChatLSPageState extends State @override void dispose() { - // print('chat_kf_page dispose'); + // BytedeskUtils.printLog('chat_kf_page dispose'); SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, false); WidgetsBinding.instance!.removeObserver(this); _debounce?.cancel(); diff --git a/bytedesk_kefu/lib/ui/chat/page/chat_webview_page.dart b/bytedesk_kefu/lib/ui/chat/page/chat_webview_page.dart index dcf7509..4b5afde 100755 --- a/bytedesk_kefu/lib/ui/chat/page/chat_webview_page.dart +++ b/bytedesk_kefu/lib/ui/chat/page/chat_webview_page.dart @@ -51,7 +51,7 @@ class _ChatWebViewPageState extends State { // padding: new EdgeInsets.only(right: 10), // child: InkWell( // onTap: () { - // print('share'); + // BytedeskUtils.printLog('share'); // // showShareSheet(context); // }, // child: Image.asset( @@ -120,7 +120,7 @@ class _ChatWebViewPageState extends State { // ); // }).then((value) { // // - // print('share $value'); + // BytedeskUtils.printLog('share $value'); // if (value == 'wechat') { // // TODO: 分享到微信 // } else if (value == 'weibo') { diff --git a/bytedesk_kefu/lib/ui/chat/widget/message_widget.dart b/bytedesk_kefu/lib/ui/chat/widget/message_widget.dart index 53f1058..ce9b3b6 100755 --- a/bytedesk_kefu/lib/ui/chat/widget/message_widget.dart +++ b/bytedesk_kefu/lib/ui/chat/widget/message_widget.dart @@ -13,6 +13,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:flutter_html/flutter_html.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; // 系统消息居中显示 class MessageWidget extends StatelessWidget { @@ -124,7 +125,7 @@ class MessageWidget extends StatelessWidget { ]; }, onSelected: (value) { - print('send menu $value'); + BytedeskUtils.printLog('send menu $value'); // 删除消息 if (value == 'copy') { /// 把文本复制进入粘贴板 @@ -150,7 +151,7 @@ class MessageWidget extends StatelessWidget { } }, onCancelled: () { - // print('cancel'); + // BytedeskUtils.printLog('cancel'); }, ); } @@ -212,11 +213,11 @@ class MessageWidget extends StatelessWidget { String imageUrl = commodityJson['imageUrl'].toString(); return InkWell( onTap: () { - // print('message!.type ${message!.type}, message!.content ${message!.content}'); + // BytedeskUtils.printLog('message!.type ${message!.type}, message!.content ${message!.content}'); if (customCallback != null) { customCallback!(message.content!); } else { - print('customCallback is null'); + BytedeskUtils.printLog('customCallback is null'); } }, child: Row( @@ -271,7 +272,7 @@ class MessageWidget extends StatelessWidget { } else if (message.type == BytedeskConstants.MESSAGE_TYPE_VIDEO) { return InkWell( onTap: () { - print('play video'); + BytedeskUtils.printLog('play video'); Navigator.of(context).push(new MaterialPageRoute(builder: (context) { return new VideoPlayPage(videoUrl: message.videoUrl); })); @@ -365,7 +366,7 @@ class MessageWidget extends StatelessWidget { ]; }, onSelected: (value) { - print('send menu $value'); + BytedeskUtils.printLog('send menu $value'); // 删除消息 if (value == 'copy') { /// 把文本复制进入粘贴板 @@ -389,7 +390,7 @@ class MessageWidget extends StatelessWidget { } }, onCancelled: () { - // print('cancel'); + // BytedeskUtils.printLog('cancel'); }, ); } @@ -464,7 +465,7 @@ class MessageWidget extends StatelessWidget { }, onImageTap: (src, _, __, ___) { // 查看大图 - // print("open image $src"); + // BytedeskUtils.printLog("open image $src"); Navigator.push( context, MaterialPageRoute( @@ -491,7 +492,7 @@ class MessageWidget extends StatelessWidget { ); }, onImageError: (exception, stackTrace) { - print(exception); + BytedeskUtils.printLog(exception); }, ), ), @@ -526,7 +527,7 @@ class MessageWidget extends StatelessWidget { style: TextStyle(color: Colors.blue), ), onTap: () => { - // print('object:' + answer.question), + // BytedeskUtils.printLog('object:' + answer.question), bytedeskEventBus.fire(QueryAnswerEventBus( answer.aid!, answer.question!, @@ -547,7 +548,7 @@ class MessageWidget extends StatelessWidget { style: TextStyle(color: Theme.of(context).primaryColor), ), onTap: () { - print('请求人工客服'); + BytedeskUtils.printLog('请求人工客服'); bytedeskEventBus.fire(RequestAgentThreadEventBus()); }, ) @@ -601,7 +602,7 @@ class MessageWidget extends StatelessWidget { style: TextStyle(color: Colors.blue), ), onTap: () => { - // print(category.name), + // BytedeskUtils.printLog(category.name), bytedeskEventBus.fire(QueryCategoryEventBus( category.cid!, category.name!)) }), @@ -620,7 +621,7 @@ class MessageWidget extends StatelessWidget { style: TextStyle(color: Theme.of(context).primaryColor), ), onTap: () { - print('请求人工客服'); + BytedeskUtils.printLog('请求人工客服'); bytedeskEventBus.fire(RequestAgentThreadEventBus()); }, ) @@ -648,11 +649,11 @@ class MessageWidget extends StatelessWidget { String imageUrl = commodityJson['imageUrl'].toString(); return InkWell( onTap: () { - // print('message!.type ${message!.type}, message!.content ${message!.content}'); + // BytedeskUtils.printLog('message!.type ${message!.type}, message!.content ${message!.content}'); if (customCallback != null) { customCallback!(message.content!); } else { - print('customCallback is null'); + BytedeskUtils.printLog('customCallback is null'); } }, child: Row( @@ -707,7 +708,7 @@ class MessageWidget extends StatelessWidget { } else if (message.type == BytedeskConstants.MESSAGE_TYPE_VIDEO) { return InkWell( onTap: () { - print('play video'); + BytedeskUtils.printLog('play video'); Navigator.of(context).push(new MaterialPageRoute(builder: (context) { return new VideoPlayPage(videoUrl: message.videoUrl); })); diff --git a/bytedesk_kefu/lib/ui/faq/page/help_article_list_page.dart b/bytedesk_kefu/lib/ui/faq/page/help_article_list_page.dart index c271d79..1d7ce84 100755 --- a/bytedesk_kefu/lib/ui/faq/page/help_article_list_page.dart +++ b/bytedesk_kefu/lib/ui/faq/page/help_article_list_page.dart @@ -7,6 +7,7 @@ import 'package:bytedesk_kefu/ui/widget/loading_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; // import 'package:flutter_easyrefresh/phoenix_header.dart'; class HelpArticleListPage extends StatefulWidget { @@ -44,7 +45,7 @@ class _HelpArticleListPageState extends State body: BlocConsumer(listener: (context, state) { // do stuff here based on BlocA's state if (state is HelpArticleState) { - print('help article load success length: ' + + BytedeskUtils.printLog('help article load success length: ' + state.articleList.length.toString()); if (state.articleList.length == 0) { // Toast.show('没有更多了哦'); diff --git a/bytedesk_kefu/lib/ui/faq/page/help_page.dart b/bytedesk_kefu/lib/ui/faq/page/help_page.dart index 0c80e31..04ad48e 100755 --- a/bytedesk_kefu/lib/ui/faq/page/help_page.dart +++ b/bytedesk_kefu/lib/ui/faq/page/help_page.dart @@ -7,6 +7,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; // import 'package:flutter_easyrefresh/phoenix_header.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; class HelpPage extends StatefulWidget { final String? uid; @@ -43,7 +44,7 @@ class _HelpPageState extends State body: BlocConsumer(listener: (context, state) { // do stuff here based on BlocA's state if (state is HelpCategoryState) { - print('help category load success length: ' + + BytedeskUtils.printLog('help category load success length: ' + state.categoryList.length.toString()); if (state.categoryList.length == 0) { // Toast.show('没有更多了哦'); diff --git a/bytedesk_kefu/lib/ui/feedback/page/feedback_page.dart b/bytedesk_kefu/lib/ui/feedback/page/feedback_page.dart index beca4aa..a4167eb 100755 --- a/bytedesk_kefu/lib/ui/feedback/page/feedback_page.dart +++ b/bytedesk_kefu/lib/ui/feedback/page/feedback_page.dart @@ -6,6 +6,7 @@ import 'package:bytedesk_kefu/ui/widget/loading_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; // import 'package:flutter_easyrefresh/phoenix_header.dart'; class FeedbackPage extends StatefulWidget { @@ -47,7 +48,7 @@ class _FeedbackPageState extends State BlocConsumer(listener: (context, state) { // do stuff here based on BlocA's state if (state is FeedbackCategoryState) { - print('help category load success length: ' + + BytedeskUtils.printLog('help category load success length: ' + state.categoryList.length.toString()); if (state.categoryList.length == 0) { // Toast.show('没有更多了哦'); diff --git a/bytedesk_kefu/lib/ui/feedback/page/feedback_submit_page.dart b/bytedesk_kefu/lib/ui/feedback/page/feedback_submit_page.dart index e09b321..ff53f33 100755 --- a/bytedesk_kefu/lib/ui/feedback/page/feedback_submit_page.dart +++ b/bytedesk_kefu/lib/ui/feedback/page/feedback_submit_page.dart @@ -7,6 +7,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:image_picker/image_picker.dart'; +import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; class FeedbackSubmitPage extends StatefulWidget { final HelpCategory? helpCategory; @@ -35,7 +36,7 @@ class _FeedbackSubmitPageState extends State { // 如果滑动到底部 if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) { - // print('scroll to bottom'); + // BytedeskUtils.printLog('scroll to bottom'); } }); super.initState(); @@ -44,7 +45,7 @@ class _FeedbackSubmitPageState extends State { @override Widget build(BuildContext context) { // - print('fileList的内容: $_fileList'); + BytedeskUtils.printLog('fileList的内容: $_fileList'); if (_selectedImageFile != null) { _fileList.add(_selectedImageFile!); } @@ -62,7 +63,7 @@ class _FeedbackSubmitPageState extends State { margin: EdgeInsets.only(right: 10), child: InkWell( onTap: () { - print('submit'); + BytedeskUtils.printLog('submit'); // TODO: 提交 BlocProvider.of(context) ..add(SubmitFeedbackEvent( @@ -222,7 +223,7 @@ class _FeedbackSubmitPageState extends State { try { XFile? pickedFile = await picker.pickImage( source: ImageSource.gallery, maxWidth: 800, imageQuality: 95); - print('pick image path: ${pickedFile!.path}'); + BytedeskUtils.printLog('pick image path: ${pickedFile!.path}'); setState(() { _selectedImageFile = File(pickedFile.path); }); @@ -230,7 +231,7 @@ class _FeedbackSubmitPageState extends State { BlocProvider.of(context) ..add(UploadImageEvent(filePath: pickedFile.path)); } catch (e) { - print('pick image error ${e.toString()}'); + BytedeskUtils.printLog('pick image error ${e.toString()}'); Fluttertoast.showToast(msg: "未选取图片"); } } @@ -244,7 +245,7 @@ class _FeedbackSubmitPageState extends State { try { XFile? pickedFile = await picker.pickImage( source: ImageSource.camera, maxWidth: 800, imageQuality: 95); - print('take image path: ${pickedFile!.path}'); + BytedeskUtils.printLog('take image path: ${pickedFile!.path}'); setState(() { _selectedImageFile = File(pickedFile.path); }); @@ -252,7 +253,7 @@ class _FeedbackSubmitPageState extends State { BlocProvider.of(context) ..add(UploadImageEvent(filePath: pickedFile.path)); } catch (e) { - print('take image error ${e.toString()}'); + BytedeskUtils.printLog('take image error ${e.toString()}'); Fluttertoast.showToast(msg: "未选取图片"); } } @@ -270,7 +271,7 @@ class _FeedbackSubmitPageState extends State { // ImagePicker.pickImage(source: source).then((result) { // setState(() { // _selectedImageFile = result; - // print("执行刷新:"); + // BytedeskUtils.printLog("执行刷新:"); // }); // }); // }, diff --git a/bytedesk_kefu/lib/ui/leavemsg/page/leavemsg_page.dart b/bytedesk_kefu/lib/ui/leavemsg/page/leavemsg_page.dart index 79c3bf4..b052cd9 100755 --- a/bytedesk_kefu/lib/ui/leavemsg/page/leavemsg_page.dart +++ b/bytedesk_kefu/lib/ui/leavemsg/page/leavemsg_page.dart @@ -52,7 +52,7 @@ class _LeaveMsgPageState extends State { // 如果滑动到底部 if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) { - // print('scroll to bottom'); + // BytedeskUtils.printLog('scroll to bottom'); } }); super.initState(); @@ -61,7 +61,7 @@ class _LeaveMsgPageState extends State { @override Widget build(BuildContext context) { // - // print('fileList的内容: $_fileList'); + // BytedeskUtils.printLog('fileList的内容: $_fileList'); // if (_selectedImageFile != null) { // _fileList.add(_selectedImageFile!); // } @@ -282,7 +282,7 @@ class _LeaveMsgPageState extends State { // try { // XFile? pickedFile = await picker.pickImage( // source: ImageSource.gallery, maxWidth: 800, imageQuality: 95); - // print('pick image path: ${pickedFile!.path}'); + // BytedeskUtils.printLog('pick image path: ${pickedFile!.path}'); // setState(() { // _selectedImageFile = File(pickedFile.path); // }); @@ -290,7 +290,7 @@ class _LeaveMsgPageState extends State { // BlocProvider.of(context) // ..add(UploadImageEvent(filePath: pickedFile.path)); // } catch (e) { - // print('pick image error ${e.toString()}'); + // BytedeskUtils.printLog('pick image error ${e.toString()}'); // Fluttertoast.showToast(msg: "未选取图片"); // } // } @@ -304,7 +304,7 @@ class _LeaveMsgPageState extends State { // try { // XFile? pickedFile = await picker.pickImage( // source: ImageSource.camera, maxWidth: 800, imageQuality: 95); - // print('take image path: ${pickedFile!.path}'); + // BytedeskUtils.printLog('take image path: ${pickedFile!.path}'); // setState(() { // _selectedImageFile = File(pickedFile.path); // }); @@ -312,7 +312,7 @@ class _LeaveMsgPageState extends State { // BlocProvider.of(context) // ..add(UploadImageEvent(filePath: pickedFile.path)); // } catch (e) { - // print('take image error ${e.toString()}'); + // BytedeskUtils.printLog('take image error ${e.toString()}'); // Fluttertoast.showToast(msg: "未选取图片"); // } // } diff --git a/bytedesk_kefu/lib/ui/widget/photo_view_wrapper.dart b/bytedesk_kefu/lib/ui/widget/photo_view_wrapper.dart index 2c74c1e..70bc56a 100755 --- a/bytedesk_kefu/lib/ui/widget/photo_view_wrapper.dart +++ b/bytedesk_kefu/lib/ui/widget/photo_view_wrapper.dart @@ -61,7 +61,7 @@ class PhotoViewWrapper extends StatelessWidget { // color: Colors.pink, child: InkWell( onTap: () { - print('imageurl: $imageUrl'); + BytedeskUtils.printLog('imageurl: $imageUrl'); BytedeskUtils.saveImage(imageUrl!); }, child: Text( diff --git a/bytedesk_kefu/lib/util/bytedesk_constants.dart b/bytedesk_kefu/lib/util/bytedesk_constants.dart index 1a5ab58..9fb76c1 100755 --- a/bytedesk_kefu/lib/util/bytedesk_constants.dart +++ b/bytedesk_kefu/lib/util/bytedesk_constants.dart @@ -18,7 +18,7 @@ class BytedeskConstants { // 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 String mqttHost = '172.20.10.7'; // 本机测试 // static const bool isDebug = true; @@ -30,8 +30,8 @@ class BytedeskConstants { // static const String httpBaseUrlAndroid = 'http://' + mqttHost + ':8000'; // static const String httpBaseUrliOS = 'http://' + mqttHost + ':8000'; // static const String httpUploadUrl = 'http://' + mqttHost + ':8000'; - // static const String mqttHost = '127.0.0.1'; // static const String host = mqttHost + ':8000'; + // static const String mqttHost = '127.0.0.1'; // static const String mqttHost = '10.0.2.2'; // 安卓模拟器 // 家 @@ -45,7 +45,7 @@ class BytedeskConstants { // static const String httpBaseUrliOS = 'http://' + mqttHost + ':8000'; // static const String httpUploadUrl = 'http://' + mqttHost + ':8000'; // static const String host = mqttHost + ':8000'; - // static const String mqttHost = '192.168.0.103'; + // static const String mqttHost = '192.168.0.106'; // 线上 static const bool isDebug = false; // false; diff --git a/bytedesk_kefu/lib/util/bytedesk_utils.dart b/bytedesk_kefu/lib/util/bytedesk_utils.dart index 381b6f4..f64eb25 100755 --- a/bytedesk_kefu/lib/util/bytedesk_utils.dart +++ b/bytedesk_kefu/lib/util/bytedesk_utils.dart @@ -39,6 +39,12 @@ class BytedeskUtils { static bool get isFuchsia => Platform.isFuchsia; static bool get isIOS => Platform.isIOS; + static void printLog(content) { + if (BytedeskConstants.isDebug) { + print(content); + } + } + static String client() { if (isWeb) { return 'flutter_web'; @@ -235,7 +241,7 @@ class BytedeskUtils { // 图片压缩 https://pub.dev/packages/flutter_image_compress // static Future compressImage(File file, String targetPath) async { - // // print("compressImage"); + // // BytedeskUtils.printLog("compressImage"); // final result = await FlutterImageCompress.compressAndGetFile( // file.absolute.path, // targetPath, @@ -307,7 +313,7 @@ class BytedeskUtils { } static Future requestPermission() async { - print('请求定位'); + BytedeskUtils.printLog('请求定位'); return true; // FIXME: // if (await Permission.location.request().isGranted) { @@ -402,9 +408,9 @@ class BytedeskUtils { if (result == null || result == '') throw '图片保存失败'; // 提示 Fluttertoast.showToast(msg: "保存成功"); - print("保存成功"); + BytedeskUtils.printLog("保存成功"); } catch (e) { - print(e.toString()); + BytedeskUtils.printLog(e.toString()); } } diff --git a/bytedesk_kefu/pubspec.yaml b/bytedesk_kefu/pubspec.yaml index c1a1b7e..8db145d 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.1 +version: 1.3.2 homepage: https://www.weikefu.net environment: @@ -49,7 +49,6 @@ dependencies: # https://pub.dev/packages/flutter_easyloading flutter_easyloading: ^3.0.3 # H5-webchat https://pub.dev/packages/webview_flutter - # webview_flutter: ^3.0.2 webview_flutter: ^2.0.4 # https://pub.dev/packages/device_info device_info: ^2.0.3