master
jack ning 3 years ago
parent 6771eb9950
commit e92afc3bd4

@ -46,7 +46,7 @@ dependencies:
# 请在ios/Podfile中添加use_frameworks! # 请在ios/Podfile中添加use_frameworks!
vibration: ^1.7.3 vibration: ^1.7.3
# 在线客服 https://pub.dev/packages/bytedesk_kefu # 在线客服 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. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.

@ -1,5 +1,9 @@
# Upgrade Log # Upgrade Log
## 1.3.2
* optimize user experience
## 1.3.1 ## 1.3.1
* optimize user experience * optimize user experience

@ -41,8 +41,9 @@ class _HistoryThreadPageState extends State<HistoryThreadPage> {
subtitle: Text('${_historyThreadList[index].content}'), subtitle: Text('${_historyThreadList[index].content}'),
onTap: () { onTap: () {
// //
BytedeskKefu.startChatThread( // BytedeskKefu.startChatThread(
context, _historyThreadList[index]); // context, _historyThreadList[index]);
BytedeskKefu.startChatThreadIM(context, _historyThreadList[index]);
}, },
), ),
itemCount: _historyThreadList.length, itemCount: _historyThreadList.length,

@ -2,6 +2,7 @@
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:bytedesk_kefu/blocs/contact_bloc/bloc.dart'; import 'package:bytedesk_kefu/blocs/contact_bloc/bloc.dart';
import 'package:bytedesk_kefu/repositories/contact_repository.dart'; import 'package:bytedesk_kefu/repositories/contact_repository.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
class ContactBloc extends Bloc<ContactEvent, ContactState> { class ContactBloc extends Bloc<ContactEvent, ContactState> {
final ContactRepository contactRepository = new ContactRepository(); final ContactRepository contactRepository = new ContactRepository();
@ -27,7 +28,7 @@ class ContactBloc extends Bloc<ContactEvent, ContactState> {
// final List<Contact> contactList = await contactRepository.getContacts(); // final List<Contact> contactList = await contactRepository.getContacts();
// yield ContactLoadSuccess(contactList); // yield ContactLoadSuccess(contactList);
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ContactLoadError()); emit(ContactLoadError());
} }
} }

@ -2,6 +2,7 @@
import 'package:bytedesk_kefu/blocs/feedback_bloc/bloc.dart'; import 'package:bytedesk_kefu/blocs/feedback_bloc/bloc.dart';
import 'package:bytedesk_kefu/model/helpCategory.dart'; import 'package:bytedesk_kefu/model/helpCategory.dart';
// import 'package:bytedesk_kefu/model/jsonResult.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:bytedesk_kefu/repositories/feedback_repository.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
@ -36,7 +37,7 @@ class FeedbackBloc extends Bloc<FeedbackEvent, FeedbackState> {
await feedbackRepository.getHelpFeedbackCategories(event.uid); await feedbackRepository.getHelpFeedbackCategories(event.uid);
emit(FeedbackCategoryState(categoryList)); emit(FeedbackCategoryState(categoryList));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(FeedbackLoadError()); emit(FeedbackLoadError());
} }
} }
@ -48,18 +49,19 @@ class FeedbackBloc extends Bloc<FeedbackEvent, FeedbackState> {
await feedbackRepository.submitFeedback(event.content, event.imageUrls); await feedbackRepository.submitFeedback(event.content, event.imageUrls);
emit(FeedbackSubmitSuccess()); emit(FeedbackSubmitSuccess());
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(FeedbackSubmitError()); emit(FeedbackSubmitError());
} }
} }
void _mapUploadImageToState(UploadImageEvent event, Emitter<FeedbackState> emit) async { void _mapUploadImageToState(
UploadImageEvent event, Emitter<FeedbackState> emit) async {
emit(ImageUploading()); emit(ImageUploading());
try { try {
final String url = await feedbackRepository.upload(event.filePath); final String url = await feedbackRepository.upload(event.filePath);
emit(UploadImageSuccess(url)); emit(UploadImageSuccess(url));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }

@ -2,6 +2,7 @@
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:bytedesk_kefu/blocs/friend_bloc/bloc.dart'; import 'package:bytedesk_kefu/blocs/friend_bloc/bloc.dart';
import 'package:bytedesk_kefu/model/friend.dart'; import 'package:bytedesk_kefu/model/friend.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
import 'package:bytedesk_kefu/repositories/friend_repository.dart'; import 'package:bytedesk_kefu/repositories/friend_repository.dart';
class FriendBloc extends Bloc<FriendEvent, FriendState> { class FriendBloc extends Bloc<FriendEvent, FriendState> {
@ -31,14 +32,15 @@ class FriendBloc extends Bloc<FriendEvent, FriendState> {
// } // }
// } // }
void _mapQueryFriendToState(QueryFriendEvent event, Emitter<FriendState> emit) async { void _mapQueryFriendToState(
QueryFriendEvent event, Emitter<FriendState> emit) async {
emit(FriendLoading()); emit(FriendLoading());
try { try {
final List<Friend> friendList = final List<Friend> friendList =
await friendRepository.getFriends(event.page, event.size); await friendRepository.getFriends(event.page, event.size);
emit(FriendLoadSuccess(friendList)); emit(FriendLoadSuccess(friendList));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ErrorFriendState('friend error')); emit(ErrorFriendState('friend error'));
} }
} }
@ -51,7 +53,7 @@ class FriendBloc extends Bloc<FriendEvent, FriendState> {
await friendRepository.getFriendsAddress(event.page, event.size); await friendRepository.getFriendsAddress(event.page, event.size);
emit(FriendLoadSuccess(friendList)); emit(FriendLoadSuccess(friendList));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ErrorFriendState('friend error')); emit(ErrorFriendState('friend error'));
} }
} }
@ -64,7 +66,7 @@ class FriendBloc extends Bloc<FriendEvent, FriendState> {
await friendRepository.uploadAddress(event.nickname, event.mobile); await friendRepository.uploadAddress(event.nickname, event.mobile);
emit(FriendCreateSuccess(friend: friend)); emit(FriendCreateSuccess(friend: friend));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ErrorFriendState('friend error')); emit(ErrorFriendState('friend error'));
} }
} }
@ -77,7 +79,7 @@ class FriendBloc extends Bloc<FriendEvent, FriendState> {
await friendRepository.getFriendsNearby(event.page, event.size); await friendRepository.getFriendsNearby(event.page, event.size);
emit(FriendLoadSuccess(friendList)); emit(FriendLoadSuccess(friendList));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ErrorFriendState('friend error')); emit(ErrorFriendState('friend error'));
} }
} }
@ -89,7 +91,7 @@ class FriendBloc extends Bloc<FriendEvent, FriendState> {
await friendRepository.updateLocation(event.latitude, event.longtitude); await friendRepository.updateLocation(event.latitude, event.longtitude);
emit(FriendUpdateSuccess()); emit(FriendUpdateSuccess());
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ErrorFriendState('friend error')); emit(ErrorFriendState('friend error'));
} }
} }

@ -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/helpArticle.dart';
import 'package:bytedesk_kefu/model/helpCategory.dart'; import 'package:bytedesk_kefu/model/helpCategory.dart';
import 'package:bytedesk_kefu/repositories/help_repository.dart'; import 'package:bytedesk_kefu/repositories/help_repository.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
class HelpBloc extends Bloc<HelpEvent, HelpState> { class HelpBloc extends Bloc<HelpEvent, HelpState> {
@ -31,7 +32,7 @@ class HelpBloc extends Bloc<HelpEvent, HelpState> {
await helpRepository.getHelpCategories(event.uid); await helpRepository.getHelpCategories(event.uid);
emit(HelpCategoryState(categoryList)); emit(HelpCategoryState(categoryList));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(HelpLoadError()); emit(HelpLoadError());
} }
} }
@ -44,7 +45,7 @@ class HelpBloc extends Bloc<HelpEvent, HelpState> {
await helpRepository.getCategoryArticles(event.categoryId); await helpRepository.getCategoryArticles(event.categoryId);
emit(HelpArticleState(categoryList)); emit(HelpArticleState(categoryList));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(HelpLoadError()); emit(HelpLoadError());
} }
} }

@ -2,6 +2,7 @@
import 'package:bytedesk_kefu/blocs/leavemsg_bloc/bloc.dart'; import 'package:bytedesk_kefu/blocs/leavemsg_bloc/bloc.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:bytedesk_kefu/repositories/leavemsg_repository.dart'; import 'package:bytedesk_kefu/repositories/leavemsg_repository.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
class LeaveMsgBloc extends Bloc<LeaveMsgEvent, LeaveMsgState> { class LeaveMsgBloc extends Bloc<LeaveMsgEvent, LeaveMsgState> {
// //
@ -27,21 +28,23 @@ class LeaveMsgBloc extends Bloc<LeaveMsgEvent, LeaveMsgState> {
SubmitLeaveMsgEvent event, Emitter<LeaveMsgState> emit) async { SubmitLeaveMsgEvent event, Emitter<LeaveMsgState> emit) async {
emit(LeaveMsgSubmiting()); emit(LeaveMsgSubmiting());
try { 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()); emit(LeaveMsgSubmitSuccessState());
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(LeaveMsgSubmitError()); emit(LeaveMsgSubmitError());
} }
} }
void _mapUploadImageToState(UploadImageEvent event, Emitter<LeaveMsgState> emit) async { void _mapUploadImageToState(
UploadImageEvent event, Emitter<LeaveMsgState> emit) async {
emit(ImageUploading()); emit(ImageUploading());
try { try {
final String url = await leaveMsgRepository.upload(event.filePath); final String url = await leaveMsgRepository.upload(event.filePath);
emit(UploadImageSuccess(url)); emit(UploadImageSuccess(url));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }

@ -5,6 +5,7 @@ import 'package:bytedesk_kefu/model/requestAnswer.dart';
import 'package:bytedesk_kefu/model/requestCategory.dart'; import 'package:bytedesk_kefu/model/requestCategory.dart';
import 'package:bytedesk_kefu/model/uploadJsonResult.dart'; import 'package:bytedesk_kefu/model/uploadJsonResult.dart';
import 'package:bytedesk_kefu/repositories/message_repository.dart'; import 'package:bytedesk_kefu/repositories/message_repository.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import './bloc.dart'; import './bloc.dart';
@ -18,6 +19,9 @@ class MessageBloc extends Bloc<MessageEvent, MessageState> {
on<UploadVideoEvent>(_mapUploadVideoToState); on<UploadVideoEvent>(_mapUploadVideoToState);
on<SendMessageRestEvent>(_mapSendMessageRestToState); on<SendMessageRestEvent>(_mapSendMessageRestToState);
on<LoadHistoryMessageEvent>(_mapLoadHistoryMessageToState); on<LoadHistoryMessageEvent>(_mapLoadHistoryMessageToState);
on<LoadUnreadMessagesEvent>(_mapLoadUnreadMessageToState);
on<LoadUnreadVisitorMessagesEvent>(_mapLoadUnreadVisitorMessageToState);
on<LoadUnreadAgentMessagesEvent>(_mapLoadUnreadAgentMessageToState);
on<LoadTopicMessageEvent>(_mapLoadTopicMessageToState); on<LoadTopicMessageEvent>(_mapLoadTopicMessageToState);
on<LoadChannelMessageEvent>(_mapLoadChannelMessageToState); on<LoadChannelMessageEvent>(_mapLoadChannelMessageToState);
@ -52,95 +56,143 @@ class MessageBloc extends Bloc<MessageEvent, MessageState> {
// } // }
// } // }
void _mapRefreshCourseToState(ReceiveMessageEvent event, Emitter<MessageState> emit) async { void _mapRefreshCourseToState(
ReceiveMessageEvent event, Emitter<MessageState> emit) async {
try { try {
emit(ReceiveMessageState(message: event.message)); emit(ReceiveMessageState(message: event.message));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
} }
} }
void _mapUploadImageToState(UploadImageEvent event, Emitter<MessageState> emit) async { void _mapUploadImageToState(
UploadImageEvent event, Emitter<MessageState> emit) async {
emit(MessageUpLoading()); emit(MessageUpLoading());
try { try {
final UploadJsonResult uploadJsonResult = final UploadJsonResult uploadJsonResult =
await messageRepository.uploadImage(event.filePath); await messageRepository.uploadImage(event.filePath);
emit(UploadImageSuccess(uploadJsonResult)); emit(UploadImageSuccess(uploadJsonResult));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }
void _mapUploadVideoToState(UploadVideoEvent event, Emitter<MessageState> emit) async { void _mapUploadVideoToState(
UploadVideoEvent event, Emitter<MessageState> emit) async {
emit(MessageUpLoading()); emit(MessageUpLoading());
try { try {
final UploadJsonResult uploadJsonResult = final UploadJsonResult uploadJsonResult =
await messageRepository.uploadVideo(event.filePath); await messageRepository.uploadVideo(event.filePath);
emit(UploadVideoSuccess(uploadJsonResult)); emit(UploadVideoSuccess(uploadJsonResult));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }
void _mapSendMessageRestToState(SendMessageRestEvent event, Emitter<MessageState> emit) async { void _mapSendMessageRestToState(
SendMessageRestEvent event, Emitter<MessageState> emit) async {
emit(RestMessageSending()); emit(RestMessageSending());
try { try {
final JsonResult jsonResult = final JsonResult jsonResult =
await messageRepository.sendMessageRest(event.json); await messageRepository.sendMessageRest(event.json);
emit(SendMessageRestSuccess(jsonResult)); emit(SendMessageRestSuccess(jsonResult));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(SendMessageRestError()); emit(SendMessageRestError());
} }
} }
void _mapLoadHistoryMessageToState(LoadHistoryMessageEvent event, Emitter<MessageState> emit) async { void _mapLoadHistoryMessageToState(
LoadHistoryMessageEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading()); emit(MessageLoading());
try { try {
final List<Message> messageList = await messageRepository final List<Message> messageList = await messageRepository
.loadHistoryMessages(event.uid, event.page, event.size); .loadHistoryMessages(event.uid, event.page, event.size);
emit(LoadHistoryMessageSuccess(messageList: messageList)); emit(LoadHistoryMessageSuccess(messageList: messageList));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(LoadHistoryMessageError()); emit(LoadHistoryMessageError());
} }
} }
void _mapLoadTopicMessageToState(LoadTopicMessageEvent event, Emitter<MessageState> emit) async { void _mapLoadTopicMessageToState(
LoadTopicMessageEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading()); emit(MessageLoading());
try { try {
final List<Message> messageList = await messageRepository final List<Message> messageList = await messageRepository
.loadTopicMessages(event.topic, event.page, event.size); .loadTopicMessages(event.topic, event.page, event.size);
emit(LoadTopicMessageSuccess(messageList: messageList)); emit(LoadTopicMessageSuccess(messageList: messageList));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(LoadTopicMessageError()); emit(LoadTopicMessageError());
} }
} }
void _mapLoadChannelMessageToState(LoadChannelMessageEvent event, Emitter<MessageState> emit) async { void _mapLoadChannelMessageToState(
LoadChannelMessageEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading()); emit(MessageLoading());
try { try {
final List<Message> messageList = await messageRepository final List<Message> messageList = await messageRepository
.loadChannelMessages(event.cid, event.page, event.size); .loadChannelMessages(event.cid, event.page, event.size);
emit(LoadChannelMessageSuccess(messageList: messageList)); emit(LoadChannelMessageSuccess(messageList: messageList));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(LoadChannelMessageError()); emit(LoadChannelMessageError());
} }
} }
void _mapQueryAnswerToState(QueryAnswerEvent event, Emitter<MessageState> emit) async { void _mapLoadUnreadMessageToState(
LoadUnreadMessagesEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading());
try {
final List<Message> 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<MessageState> emit) async {
emit(MessageLoading());
try {
final List<Message> messageList = await messageRepository
.loadUnreadVisitorMessages(event.page, event.size);
emit(LoadUnreadVisitorMessageSuccess(messageList: messageList));
} catch (error) {
BytedeskUtils.printLog(error);
emit(LoadUnreadMessageError());
}
}
void _mapLoadUnreadAgentMessageToState(
LoadUnreadAgentMessagesEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading());
try {
final List<Message> messageList = await messageRepository
.loadUnreadAgentMessages(event.page, event.size);
emit(LoadUnreadAgentMessageSuccess(messageList: messageList));
} catch (error) {
BytedeskUtils.printLog(error);
emit(LoadUnreadAgentMessageError());
}
}
void _mapQueryAnswerToState(
QueryAnswerEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading()); emit(MessageLoading());
try { try {
final RequestAnswerResult requestAnswerResult = final RequestAnswerResult requestAnswerResult =
await messageRepository.queryAnswer(event.tid, event.aid, event.mid); await messageRepository.queryAnswer(event.tid, event.aid, event.mid);
emit(QueryAnswerSuccess( emit(QueryAnswerSuccess(
query: requestAnswerResult.query, answer: requestAnswerResult.anwser)); query: requestAnswerResult.query,
answer: requestAnswerResult.anwser));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }
@ -155,32 +207,35 @@ class MessageBloc extends Bloc<MessageEvent, MessageState> {
query: requestAnswerResult.query, query: requestAnswerResult.query,
answer: requestAnswerResult.anwser)); answer: requestAnswerResult.anwser));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }
void _mapMessageAnswerToState(MessageAnswerEvent event, Emitter<MessageState> emit) async { void _mapMessageAnswerToState(
MessageAnswerEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading()); emit(MessageLoading());
try { try {
final RequestAnswerResult requestAnswerResult = await messageRepository final RequestAnswerResult requestAnswerResult =
.messageAnswer(event.wid, event.content); await messageRepository.messageAnswer(event.wid, event.content);
emit(MessageAnswerSuccess( emit(MessageAnswerSuccess(
query: requestAnswerResult.query, answer: requestAnswerResult.anwser)); query: requestAnswerResult.query,
answer: requestAnswerResult.anwser));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }
void _mapRateAnswerToState(RateAnswerEvent event, Emitter<MessageState> emit) async { void _mapRateAnswerToState(
RateAnswerEvent event, Emitter<MessageState> emit) async {
emit(MessageLoading()); emit(MessageLoading());
try { try {
final RequestAnswerResult requestAnswerResult = final RequestAnswerResult requestAnswerResult =
await messageRepository.rateAnswer(event.aid, event.mid, event.rate); await messageRepository.rateAnswer(event.aid, event.mid, event.rate);
emit(RateAnswerSuccess(result: requestAnswerResult.anwser)); emit(RateAnswerSuccess(result: requestAnswerResult.anwser));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }

@ -64,6 +64,33 @@ class LoadChannelMessageEvent extends MessageEvent {
: super(); : 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 { class QueryAnswerEvent extends MessageEvent {
final String? tid; final String? tid;
final String? aid; final String? aid;

@ -84,6 +84,21 @@ class LoadChannelMessageError extends MessageState {
String toString() => 'LoadChannelMessageError'; 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 { class UploadVideoSuccess extends MessageState {
final UploadJsonResult uploadJsonResult; final UploadJsonResult uploadJsonResult;
@ -119,6 +134,24 @@ class LoadChannelMessageSuccess extends MessageState {
LoadChannelMessageSuccess({@required this.messageList}) : super(); LoadChannelMessageSuccess({@required this.messageList}) : super();
} }
class LoadUnreadMessageSuccess extends MessageState {
final List<Message>? messageList;
LoadUnreadMessageSuccess({@required this.messageList}) : super();
}
class LoadUnreadVisitorMessageSuccess extends MessageState {
final List<Message>? messageList;
LoadUnreadVisitorMessageSuccess({@required this.messageList}) : super();
}
class LoadUnreadAgentMessageSuccess extends MessageState {
final List<Message>? messageList;
LoadUnreadAgentMessageSuccess({@required this.messageList}) : super();
}
class QueryAnswerSuccess extends MessageState { class QueryAnswerSuccess extends MessageState {
final Message? query; final Message? query;
final Message? answer; final Message? answer;

@ -3,6 +3,7 @@ import 'package:bytedesk_kefu/model/jsonResult.dart';
import 'package:bytedesk_kefu/model/user.dart'; import 'package:bytedesk_kefu/model/user.dart';
import 'package:bytedesk_kefu/repositories/user_repository.dart'; import 'package:bytedesk_kefu/repositories/user_repository.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
import './bloc.dart'; import './bloc.dart';
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> { class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
@ -24,7 +25,6 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
on<UserFollowEvent>(_mapUserFollowToState); on<UserFollowEvent>(_mapUserFollowToState);
on<UserUnfollowEvent>(_mapUserUnfollowToState); on<UserUnfollowEvent>(_mapUserUnfollowToState);
} }
// @override // @override
@ -57,7 +57,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
// } // }
// } // }
void _mapProfileState(GetProfileEvent event, Emitter<ProfileState> emit) async { void _mapProfileState(
GetProfileEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress()); emit(ProfileInProgress());
try { try {
User user = await userRepository.getProfile(); User user = await userRepository.getProfile();
@ -68,124 +69,135 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
} }
} }
void _mapUploadImageToState(UploadImageEvent event, Emitter<ProfileState> emit) async { void _mapUploadImageToState(
UploadImageEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress()); emit(ProfileInProgress());
try { try {
final String url = await userRepository.upload(event.filePath); final String url = await userRepository.upload(event.filePath);
emit(UploadImageSuccess(url)); emit(UploadImageSuccess(url));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }
void _mapUpdateAvatarToState(UpdateAvatarEvent event, Emitter<ProfileState> emit) async { void _mapUpdateAvatarToState(
UpdateAvatarEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress()); emit(ProfileInProgress());
try { try {
final User user = await userRepository.updateAvatar(event.avatar); final User user = await userRepository.updateAvatar(event.avatar);
emit(UpdateAvatarSuccess(user)); emit(UpdateAvatarSuccess(user));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }
void _mapUpdateNicknameToState(UpdateNicknameEvent event, Emitter<ProfileState> emit) async { void _mapUpdateNicknameToState(
UpdateNicknameEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress()); emit(ProfileInProgress());
try { try {
final User user = await userRepository.updateNickname(event.nickname); final User user = await userRepository.updateNickname(event.nickname);
emit(UpdateNicknameSuccess(user)); emit(UpdateNicknameSuccess(user));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }
void _mapUpdateDescriptionToState(UpdateDescriptionEvent event, Emitter<ProfileState> emit) async { void _mapUpdateDescriptionToState(
UpdateDescriptionEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress()); emit(ProfileInProgress());
try { try {
final User user = final User user =
await userRepository.updateDescription(event.description); await userRepository.updateDescription(event.description);
emit(UpdateDescriptionSuccess(user)); emit(UpdateDescriptionSuccess(user));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }
void _mapUpdateMobileToState(UpdateMobileEvent event, Emitter<ProfileState> emit) async { void _mapUpdateMobileToState(
UpdateMobileEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress()); emit(ProfileInProgress());
try { try {
final User user = await userRepository.updateMobile(event.mobile); final User user = await userRepository.updateMobile(event.mobile);
emit(UpdateMobileSuccess(user)); emit(UpdateMobileSuccess(user));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }
void _mapUpdateSexToState(UpdateSexEvent event, Emitter<ProfileState> emit) async { void _mapUpdateSexToState(
UpdateSexEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress()); emit(ProfileInProgress());
try { try {
final User user = await userRepository.updateSex(event.sex); final User user = await userRepository.updateSex(event.sex);
emit(UpdateSexSuccess(user)); emit(UpdateSexSuccess(user));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }
void _mapUpdateLocationToState(UpdateLocationEvent event, Emitter<ProfileState> emit) async { void _mapUpdateLocationToState(
UpdateLocationEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress()); emit(ProfileInProgress());
try { try {
final User user = await userRepository.updateLocation(event.location); final User user = await userRepository.updateLocation(event.location);
emit(UpdateLocationSuccess(user)); emit(UpdateLocationSuccess(user));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }
void _mapUpdateBirthdayToState(UpdateBirthdayEvent event, Emitter<ProfileState> emit) async { void _mapUpdateBirthdayToState(
UpdateBirthdayEvent event, Emitter<ProfileState> emit) async {
emit(ProfileInProgress()); emit(ProfileInProgress());
try { try {
final User user = await userRepository.updateBirthday(event.birthday); final User user = await userRepository.updateBirthday(event.birthday);
emit(UpdateBirthdaySuccess(user)); emit(UpdateBirthdaySuccess(user));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }
void _mapQueryFollowToState(QueryFollowEvent event, Emitter<ProfileState> emit) async { void _mapQueryFollowToState(
QueryFollowEvent event, Emitter<ProfileState> emit) async {
emit(QueryFollowing()); emit(QueryFollowing());
try { try {
final bool isFollowed = await userRepository.isFollowed(event.uid); final bool isFollowed = await userRepository.isFollowed(event.uid);
emit(QueryFollowSuccess(isFollowed)); emit(QueryFollowSuccess(isFollowed));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(QueryFollowError()); emit(QueryFollowError());
} }
} }
void _mapUserFollowToState(UserFollowEvent event, Emitter<ProfileState> emit) async { void _mapUserFollowToState(
UserFollowEvent event, Emitter<ProfileState> emit) async {
emit(Following()); emit(Following());
try { try {
final JsonResult jsonResult = await userRepository.follow(event.uid); final JsonResult jsonResult = await userRepository.follow(event.uid);
emit(FollowResultSuccess(jsonResult)); emit(FollowResultSuccess(jsonResult));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(FollowError()); emit(FollowError());
} }
} }
void _mapUserUnfollowToState(UserUnfollowEvent event, Emitter<ProfileState> emit) async { void _mapUserUnfollowToState(
UserUnfollowEvent event, Emitter<ProfileState> emit) async {
emit(Following()); emit(Following());
try { try {
final JsonResult jsonResult = await userRepository.unfollow(event.uid); final JsonResult jsonResult = await userRepository.unfollow(event.uid);
emit(UnfollowResultSuccess(jsonResult)); emit(UnfollowResultSuccess(jsonResult));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UnFollowError()); emit(UnFollowError());
} }
} }

@ -4,6 +4,7 @@ import 'package:bloc/bloc.dart';
import './bloc.dart'; import './bloc.dart';
import 'package:bytedesk_kefu/repositories/repositories.dart'; import 'package:bytedesk_kefu/repositories/repositories.dart';
import 'package:bytedesk_kefu/model/model.dart'; import 'package:bytedesk_kefu/model/model.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
class ThreadBloc extends Bloc<ThreadEvent, ThreadState> { class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
// //
@ -39,7 +40,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
final List<Thread> threadList = await threadRepository.getThreads(); final List<Thread> threadList = await threadRepository.getThreads();
emit(ThreadLoadSuccess(threadList)); emit(ThreadLoadSuccess(threadList));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ThreadLoadError()); emit(ThreadLoadError());
} }
} }
@ -52,7 +53,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
await threadRepository.getHistoryThreads(event.page, event.size); await threadRepository.getHistoryThreads(event.page, event.size);
emit(ThreadLoadSuccess(threadList)); emit(ThreadLoadSuccess(threadList));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ThreadLoadError()); emit(ThreadLoadError());
} }
} }
@ -65,7 +66,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
await threadRepository.getVisitorThreads(event.page, event.size); await threadRepository.getVisitorThreads(event.page, event.size);
emit(ThreadLoadSuccess(threadList)); emit(ThreadLoadSuccess(threadList));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ThreadLoadError()); emit(ThreadLoadError());
} }
} }
@ -78,7 +79,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
await threadRepository.getVisitorThreadsAll(); await threadRepository.getVisitorThreadsAll();
emit(ThreadLoadSuccess(threadList)); emit(ThreadLoadSuccess(threadList));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ThreadLoadError()); emit(ThreadLoadError());
} }
} }
@ -91,7 +92,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
event.wid, event.type, event.aid, event.isV2Robot); event.wid, event.type, event.aid, event.isV2Robot);
emit(RequestThreadSuccess(thread)); emit(RequestThreadSuccess(thread));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(RequestThreadError()); emit(RequestThreadError());
} }
} }
@ -104,7 +105,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
await threadRepository.requestAgent(event.wid, event.type, event.aid); await threadRepository.requestAgent(event.wid, event.type, event.aid);
emit(RequestAgentSuccess(thread)); emit(RequestAgentSuccess(thread));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(RequestAgentThreadError()); emit(RequestAgentThreadError());
} }
} }
@ -117,7 +118,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
await threadRepository.requestContactThread(event.cid); await threadRepository.requestContactThread(event.cid);
emit(RequestContactThreadSuccess(thread)); emit(RequestContactThreadSuccess(thread));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ThreadLoadError()); emit(ThreadLoadError());
} }
} }
@ -130,7 +131,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
await threadRepository.requestGroupThread(event.gid); await threadRepository.requestGroupThread(event.gid);
emit(RequestGroupThreadSuccess(thread)); emit(RequestGroupThreadSuccess(thread));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ThreadLoadError()); emit(ThreadLoadError());
} }
} }
@ -142,7 +143,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
final MarkThreadResult thread = await threadRepository.markTop(event.tid); final MarkThreadResult thread = await threadRepository.markTop(event.tid);
emit(MarkTopThreadSuccess(thread)); emit(MarkTopThreadSuccess(thread));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ThreadLoadError()); emit(ThreadLoadError());
} }
} }
@ -155,7 +156,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
await threadRepository.unmarkTop(event.tid); await threadRepository.unmarkTop(event.tid);
emit(UnMarkTopThreadSuccess(thread)); emit(UnMarkTopThreadSuccess(thread));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ThreadLoadError()); emit(ThreadLoadError());
} }
} }
@ -168,7 +169,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
await threadRepository.markNodisturb(event.tid); await threadRepository.markNodisturb(event.tid);
emit(MarkNodisturbThreadSuccess(thread)); emit(MarkNodisturbThreadSuccess(thread));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ThreadLoadError()); emit(ThreadLoadError());
} }
} }
@ -181,7 +182,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
await threadRepository.unmarkNodisturb(event.tid); await threadRepository.unmarkNodisturb(event.tid);
emit(UnMarkNodisturbThreadSuccess(thread)); emit(UnMarkNodisturbThreadSuccess(thread));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ThreadLoadError()); emit(ThreadLoadError());
} }
} }
@ -194,7 +195,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
await threadRepository.markUnread(event.tid); await threadRepository.markUnread(event.tid);
emit(MarkUnreadThreadSuccess(thread)); emit(MarkUnreadThreadSuccess(thread));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ThreadLoadError()); emit(ThreadLoadError());
} }
} }
@ -207,7 +208,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
await threadRepository.unmarkUnread(event.tid); await threadRepository.unmarkUnread(event.tid);
emit(UnMarkUnreadThreadSuccess(thread)); emit(UnMarkUnreadThreadSuccess(thread));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ThreadLoadError()); emit(ThreadLoadError());
} }
} }
@ -219,7 +220,7 @@ class ThreadBloc extends Bloc<ThreadEvent, ThreadState> {
final MarkThreadResult thread = await threadRepository.delete(event.tid); final MarkThreadResult thread = await threadRepository.delete(event.tid);
emit(DeleteThreadSuccess(thread)); emit(DeleteThreadSuccess(thread));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(ThreadLoadError()); emit(ThreadLoadError());
} }
} }

@ -1,6 +1,7 @@
// import 'dart:async'; // import 'dart:async';
import 'package:bytedesk_kefu/blocs/ticket_bloc/bloc.dart'; import 'package:bytedesk_kefu/blocs/ticket_bloc/bloc.dart';
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
import 'package:bytedesk_kefu/repositories/ticket_repository.dart'; import 'package:bytedesk_kefu/repositories/ticket_repository.dart';
class TicketBloc extends Bloc<TicketEvent, TicketState> { class TicketBloc extends Bloc<TicketEvent, TicketState> {
@ -26,37 +27,40 @@ class TicketBloc extends Bloc<TicketEvent, TicketState> {
// } // }
// } // }
void _mapGetTicketCategoryToState(GetTicketCategoryEvent event, Emitter<TicketState> emit) async { void _mapGetTicketCategoryToState(
GetTicketCategoryEvent event, Emitter<TicketState> emit) async {
emit(TicketLoading()); emit(TicketLoading());
try { try {
// final List<HelpCategory> categoryList = // final List<HelpCategory> categoryList =
// await feedbackRepository.getHelpTicketCategories(); // await feedbackRepository.getHelpTicketCategories();
// emit(TicketCategoryState(categoryList); // emit(TicketCategoryState(categoryList);
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(TicketLoadError()); emit(TicketLoadError());
} }
} }
void _mapSubmitTicketToState(SubmitTicketEvent event, Emitter<TicketState> emit) async { void _mapSubmitTicketToState(
SubmitTicketEvent event, Emitter<TicketState> emit) async {
emit(TicketLoading()); emit(TicketLoading());
try { try {
// final List<HelpCategory> categoryList = // final List<HelpCategory> categoryList =
// await feedbackRepository.getHelpTicketCategories(); // await feedbackRepository.getHelpTicketCategories();
// emit(TicketCategoryState(categoryList); // emit(TicketCategoryState(categoryList);
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(TicketLoadError()); emit(TicketLoadError());
} }
} }
void _mapUploadImageToState(UploadImageEvent event, Emitter<TicketState> emit) async { void _mapUploadImageToState(
UploadImageEvent event, Emitter<TicketState> emit) async {
emit(TicketLoading()); emit(TicketLoading());
try { try {
final String url = await feedbackRepository.upload(event.filePath); final String url = await feedbackRepository.upload(event.filePath);
emit(UploadImageSuccess(url)); emit(UploadImageSuccess(url));
} catch (error) { } catch (error) {
print(error); BytedeskUtils.printLog(error);
emit(UpLoadImageError()); emit(UpLoadImageError());
} }
} }

@ -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/helpArticle.dart';
import 'package:bytedesk_kefu/model/helpCategory.dart'; import 'package:bytedesk_kefu/model/helpCategory.dart';
import 'package:bytedesk_kefu/util/bytedesk_constants.dart'; import 'package:bytedesk_kefu/util/bytedesk_constants.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
class BytedeskFaqHttpApi extends BytedeskBaseHttpApi { class BytedeskFaqHttpApi extends BytedeskBaseHttpApi {
// //
@ -12,7 +13,7 @@ class BytedeskFaqHttpApi extends BytedeskBaseHttpApi {
// //
final categoriesUrl = Uri.http(BytedeskConstants.host, final categoriesUrl = Uri.http(BytedeskConstants.host,
'/visitor/api/category/support', {'uid': uid, 'client': client}); '/visitor/api/category/support', {'uid': uid, 'client': client});
print("categories Url $categoriesUrl"); BytedeskUtils.printLog("categories Url $categoriesUrl");
final initResponse = await this.httpClient.get(categoriesUrl); final initResponse = await this.httpClient.get(categoriesUrl);
// //
//json //json
@ -20,7 +21,7 @@ class BytedeskFaqHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// //
List<HelpCategory> categories = (responseJson['data'] as List<dynamic>) List<HelpCategory> categories = (responseJson['data'] as List<dynamic>)
.map((item) => HelpCategory.fromJson(item)) .map((item) => HelpCategory.fromJson(item))
@ -38,7 +39,7 @@ class BytedeskFaqHttpApi extends BytedeskBaseHttpApi {
BytedeskConstants.host, BytedeskConstants.host,
'/visitor/api/category/articles', '/visitor/api/category/articles',
{'categoryId': categoryId, 'client': client}); {'categoryId': categoryId, 'client': client});
print("categories Url $categoriesUrl"); BytedeskUtils.printLog("categories Url $categoriesUrl");
final initResponse = await this.httpClient.get(categoriesUrl); final initResponse = await this.httpClient.get(categoriesUrl);
// //
//json //json
@ -46,7 +47,7 @@ class BytedeskFaqHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// //
List<HelpArticle> articles = (responseJson['data'] as List<dynamic>) List<HelpArticle> articles = (responseJson['data'] as List<dynamic>)
.map((item) => HelpArticle.fromJson(item)) .map((item) => HelpArticle.fromJson(item))

@ -5,6 +5,7 @@ import 'package:bytedesk_kefu/model/helpCategory.dart';
import 'package:bytedesk_kefu/model/jsonResult.dart'; import 'package:bytedesk_kefu/model/jsonResult.dart';
import 'package:bytedesk_kefu/util/bytedesk_constants.dart'; import 'package:bytedesk_kefu/util/bytedesk_constants.dart';
import 'package:bytedesk_kefu/util/bytedesk_events.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:sp_util/sp_util.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
@ -17,7 +18,7 @@ class BytedeskFeedbackHttpApi extends BytedeskBaseHttpApi {
// '$baseUrl/visitor/api/category/feedback?uid=$uid&client=$client'; // '$baseUrl/visitor/api/category/feedback?uid=$uid&client=$client';
final categoriesUrl = Uri.http(BytedeskConstants.host, final categoriesUrl = Uri.http(BytedeskConstants.host,
'/visitor/api/category/feedback', {'uid': uid, 'client': client}); '/visitor/api/category/feedback', {'uid': uid, 'client': client});
print("categories Url $categoriesUrl"); BytedeskUtils.printLog("categories Url $categoriesUrl");
final initResponse = await this.httpClient.get(categoriesUrl); final initResponse = await this.httpClient.get(categoriesUrl);
// //
//json //json
@ -25,7 +26,7 @@ class BytedeskFeedbackHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// //
List<HelpCategory> categories = (responseJson['data'] as List<dynamic>) List<HelpCategory> categories = (responseJson['data'] as List<dynamic>)
.map((item) => HelpCategory.fromJson(item)) .map((item) => HelpCategory.fromJson(item))
@ -49,7 +50,7 @@ class BytedeskFeedbackHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -65,7 +66,8 @@ class BytedeskFeedbackHttpApi extends BytedeskBaseHttpApi {
String? username = SpUtil.getString(BytedeskConstants.uid); String? username = SpUtil.getString(BytedeskConstants.uid);
final uploadUrl = '$baseUrl/visitor/api/upload/image'; 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 uri = Uri.parse(uploadUrl);
var request = http.MultipartRequest('POST', uri) var request = http.MultipartRequest('POST', uri)
@ -75,16 +77,16 @@ class BytedeskFeedbackHttpApi extends BytedeskBaseHttpApi {
http.Response response = http.Response response =
await http.Response.fromStream(await request.send()); await http.Response.fromStream(await request.send());
// print("Result: ${response.body}"); // BytedeskUtils.printLog("Result: ${response.body}");
//json //json
Utf8Decoder utf8decoder = Utf8Decoder(); // fix Utf8Decoder utf8decoder = Utf8Decoder(); // fix
//string json //string json
final responseJson = json.decode(utf8decoder.convert(response.bodyBytes)); final responseJson = json.decode(utf8decoder.convert(response.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
String url = responseJson['data']; String url = responseJson['data'];
print('url:' + url); BytedeskUtils.printLog('url:' + url);
return url; return url;
} }
} }

@ -14,7 +14,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi {
// '$baseUrl/api/friend/query?page=$page&size=$size&client=$client'; // '$baseUrl/api/friend/query?page=$page&size=$size&client=$client';
final friendsUrl = Uri.http(BytedeskConstants.host, '/api/friend/query', final friendsUrl = Uri.http(BytedeskConstants.host, '/api/friend/query',
{'page': page.toString(), 'size': size.toString(), 'client': client}); {'page': page.toString(), 'size': size.toString(), 'client': client});
print("get friends Url $friendsUrl"); BytedeskUtils.printLog("get friends Url $friendsUrl");
final initResponse = final initResponse =
await this.httpClient.get(friendsUrl, headers: getHeaders()); await this.httpClient.get(friendsUrl, headers: getHeaders());
@ -23,7 +23,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -45,7 +45,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi {
BytedeskConstants.host, BytedeskConstants.host,
'/api/friend/address/query', '/api/friend/address/query',
{'page': page.toString(), 'size': size.toString(), 'client': client}); {'page': page.toString(), 'size': size.toString(), 'client': client});
print("address Url $addressUrl"); BytedeskUtils.printLog("address Url $addressUrl");
final initResponse = final initResponse =
await this.httpClient.get(addressUrl, headers: getHeaders()); await this.httpClient.get(addressUrl, headers: getHeaders());
@ -54,7 +54,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -83,7 +83,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -108,7 +108,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi {
'size': size.toString(), 'size': size.toString(),
'client': client 'client': client
}); });
print("address Url $addressUrl"); BytedeskUtils.printLog("address Url $addressUrl");
final initResponse = final initResponse =
await this.httpClient.get(addressUrl, headers: getHeaders()); await this.httpClient.get(addressUrl, headers: getHeaders());
@ -117,7 +117,7 @@ class BytedeskFriendHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());

@ -5,7 +5,7 @@ import 'package:bytedesk_kefu/model/helpCategory.dart';
import 'package:bytedesk_kefu/model/jsonResult.dart'; import 'package:bytedesk_kefu/model/jsonResult.dart';
import 'package:bytedesk_kefu/util/bytedesk_constants.dart'; import 'package:bytedesk_kefu/util/bytedesk_constants.dart';
import 'package:bytedesk_kefu/util/bytedesk_events.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:http/http.dart' as http;
import 'package:sp_util/sp_util.dart'; import 'package:sp_util/sp_util.dart';
@ -17,7 +17,7 @@ class BytedeskLeaveMsgHttpApi extends BytedeskBaseHttpApi {
// '$baseUrl/visitor/api/category/feedback?uid=$uid&client=$client'; // '$baseUrl/visitor/api/category/feedback?uid=$uid&client=$client';
final categoriesUrl = Uri.http(BytedeskConstants.host, final categoriesUrl = Uri.http(BytedeskConstants.host,
'/visitor/api/category/feedback', {'uid': uid, 'client': client}); '/visitor/api/category/feedback', {'uid': uid, 'client': client});
print("categories Url $categoriesUrl"); BytedeskUtils.printLog("categories Url $categoriesUrl");
final initResponse = await this.httpClient.get(categoriesUrl); final initResponse = await this.httpClient.get(categoriesUrl);
// //
//json //json
@ -37,7 +37,15 @@ class BytedeskLeaveMsgHttpApi extends BytedeskBaseHttpApi {
Future<JsonResult> submitLeaveMsg(String? wid, String? aid, String? type, Future<JsonResult> submitLeaveMsg(String? wid, String? aid, String? type,
String? mobile, String? email, String? content) async { 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 initUrl = Uri.http(BytedeskConstants.host, '/api/leavemsg/save');
final initResponse = final initResponse =
await this.httpClient.post(initUrl, headers: getHeaders(), body: body); await this.httpClient.post(initUrl, headers: getHeaders(), body: body);
@ -46,8 +54,8 @@ class BytedeskLeaveMsgHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("submitLeaveMsg:"); BytedeskUtils.printLog("submitLeaveMsg:");
print(responseJson); BytedeskUtils.printLog(responseJson);
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -63,7 +71,8 @@ class BytedeskLeaveMsgHttpApi extends BytedeskBaseHttpApi {
String? username = SpUtil.getString(BytedeskConstants.uid); String? username = SpUtil.getString(BytedeskConstants.uid);
final uploadUrl = '$baseUrl/visitor/api/upload/image'; 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 uri = Uri.parse(uploadUrl);
var request = http.MultipartRequest('POST', uri) var request = http.MultipartRequest('POST', uri)
@ -73,16 +82,16 @@ class BytedeskLeaveMsgHttpApi extends BytedeskBaseHttpApi {
http.Response response = http.Response response =
await http.Response.fromStream(await request.send()); await http.Response.fromStream(await request.send());
// print("Result: ${response.body}"); // BytedeskUtils.printLog("Result: ${response.body}");
//json //json
Utf8Decoder utf8decoder = Utf8Decoder(); // fix Utf8Decoder utf8decoder = Utf8Decoder(); // fix
//string json //string json
final responseJson = json.decode(utf8decoder.convert(response.bodyBytes)); final responseJson = json.decode(utf8decoder.convert(response.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
String url = responseJson['data']; String url = responseJson['data'];
print('url:' + url); BytedeskUtils.printLog('url:' + url);
return url; return url;
} }
} }

@ -9,6 +9,7 @@ import 'package:bytedesk_kefu/model/requestCategory.dart';
import 'package:bytedesk_kefu/model/uploadJsonResult.dart'; import 'package:bytedesk_kefu/model/uploadJsonResult.dart';
import 'package:bytedesk_kefu/util/bytedesk_constants.dart'; import 'package:bytedesk_kefu/util/bytedesk_constants.dart';
import 'package:bytedesk_kefu/util/bytedesk_events.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:sp_util/sp_util.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:http_parser/http_parser.dart'; import 'package:http_parser/http_parser.dart';
@ -30,7 +31,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(sendMessageResponse.bodyBytes)); json.decode(utf8decoder.convert(sendMessageResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -49,7 +50,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
'uid': uid, 'uid': uid,
'client': client 'client': client
}); });
// print("loadHistoryMessages Url $loadHistoryMessages"); // BytedeskUtils.printLog("loadHistoryMessages Url $loadHistoryMessages");
final initResponse = await this final initResponse = await this
.httpClient .httpClient
.get(loadHistoryMessagesUrl, headers: getHeaders()); .get(loadHistoryMessagesUrl, headers: getHeaders());
@ -75,8 +76,6 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
Future<List<Message>> loadTopicMessages( Future<List<Message>> loadTopicMessages(
String? topic, int? page, int? size) async { String? topic, int? page, int? size) async {
// //
// final loadTopicMessagesUrl =
// '$baseUrl/api/messages/topic?topic=$topic&page=$page&size=$size&client=$client';
final loadTopicMessagesUrl = final loadTopicMessagesUrl =
Uri.http(BytedeskConstants.host, '/api/messages/topic', { Uri.http(BytedeskConstants.host, '/api/messages/topic', {
'page': page.toString(), 'page': page.toString(),
@ -84,7 +83,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
'topic': topic, 'topic': topic,
'client': client 'client': client
}); });
// print("loadHistoryMessages Url $loadHistoryMessages"); // BytedeskUtils.printLog("loadHistoryMessages Url $loadHistoryMessages");
final initResponse = final initResponse =
await this.httpClient.get(loadTopicMessagesUrl, headers: getHeaders()); await this.httpClient.get(loadTopicMessagesUrl, headers: getHeaders());
// //
@ -118,7 +117,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
'cid': cid, 'cid': cid,
'client': client 'client': client
}); });
// print("loadChannelMessagesUrl Url $loadHistoryMessages"); // BytedeskUtils.printLog("loadChannelMessagesUrl Url $loadHistoryMessages");
final initResponse = await this final initResponse = await this
.httpClient .httpClient
.get(loadChannelMessagesUrl, headers: getHeaders()); .get(loadChannelMessagesUrl, headers: getHeaders());
@ -141,12 +140,108 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
return messageList; return messageList;
} }
/// -wid
/// widid
/// 访
Future<List<Message>> 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<Message> messageList =
(responseJson['data']['content'] as List<dynamic>)
.map((item) => Message.fromJson(item))
.toList();
return messageList;
}
// 访-访
Future<List<Message>> 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<Message> messageList =
(responseJson['data']['content'] as List<dynamic>)
.map((item) => Message.fromJson(item))
.toList();
return messageList;
}
// -
Future<List<Message>> 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<Message> messageList =
(responseJson['data']['content'] as List<dynamic>)
.map((item) => Message.fromJson(item))
.toList();
return messageList;
}
// //
Future<RequestAnswerResult> queryAnswer(String? tid, String? aid) async { Future<RequestAnswerResult> queryAnswer(String? tid, String? aid) async {
// //
final queryAnswerUrl = Uri.http(BytedeskConstants.host, '/api/answer/query', final queryAnswerUrl = Uri.http(BytedeskConstants.host, '/api/answer/query',
{'tid': tid, 'aid': aid, 'client': client}); {'tid': tid, 'aid': aid, 'client': client});
print("query Url $queryAnswerUrl"); BytedeskUtils.printLog("query Url $queryAnswerUrl");
final initResponse = final initResponse =
await this.httpClient.get(queryAnswerUrl, headers: getHeaders()); await this.httpClient.get(queryAnswerUrl, headers: getHeaders());
// //
@ -171,7 +266,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
BytedeskConstants.host, BytedeskConstants.host,
'/api/v2/answer/query', '/api/v2/answer/query',
{'tid': tid, 'aid': aid, 'mid': mid, 'client': client}); {'tid': tid, 'aid': aid, 'mid': mid, 'client': client});
print("query Url $queryAnswerUrl"); BytedeskUtils.printLog("query Url $queryAnswerUrl");
final initResponse = final initResponse =
await this.httpClient.get(queryAnswerUrl, headers: getHeaders()); await this.httpClient.get(queryAnswerUrl, headers: getHeaders());
// //
@ -189,14 +284,11 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
} }
// //
Future<RequestCategoryResult> queryCategory( Future<RequestCategoryResult> queryCategory(String? tid, String? cid) async {
String? tid, String? cid) async {
// //
final queryCategoryUrl = Uri.http( final queryCategoryUrl = Uri.http(BytedeskConstants.host,
BytedeskConstants.host, '/api/v2/answer/category', {'tid': tid, 'cid': cid, 'client': client});
'/api/v2/answer/category', BytedeskUtils.printLog("query Url $queryCategoryUrl");
{'tid': tid, 'cid': cid, 'client': client});
print("query Url $queryCategoryUrl");
final initResponse = final initResponse =
await this.httpClient.get(queryCategoryUrl, headers: getHeaders()); await this.httpClient.get(queryCategoryUrl, headers: getHeaders());
// //
@ -225,7 +317,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
'content': content, 'content': content,
'client': client 'client': client
}); });
print("message Url $messageAnswerUrl"); BytedeskUtils.printLog("message Url $messageAnswerUrl");
final initResponse = final initResponse =
await this.httpClient.get(messageAnswerUrl, headers: getHeaders()); await this.httpClient.get(messageAnswerUrl, headers: getHeaders());
// //
@ -234,8 +326,8 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("messageAnswer:"); BytedeskUtils.printLog("messageAnswer:");
print(responseJson); BytedeskUtils.printLog(responseJson);
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -252,7 +344,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
// '$baseUrl/api/answer/rate?aid=$aid&mid=$mid&rate=$rate&client=$client'; // '$baseUrl/api/answer/rate?aid=$aid&mid=$mid&rate=$rate&client=$client';
final rateAnswerUrl = Uri.http(BytedeskConstants.host, '/api/answer/rate', final rateAnswerUrl = Uri.http(BytedeskConstants.host, '/api/answer/rate',
{'aid': aid, 'mid': mid, 'rate': rate, 'client': client}); {'aid': aid, 'mid': mid, 'rate': rate, 'client': client});
print("rate Url $rateAnswerUrl"); BytedeskUtils.printLog("rate Url $rateAnswerUrl");
final initResponse = final initResponse =
await this.httpClient.get(rateAnswerUrl, headers: getHeaders()); await this.httpClient.get(rateAnswerUrl, headers: getHeaders());
// //
@ -277,7 +369,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
final uploadUrl = final uploadUrl =
'${BytedeskConstants.httpUploadUrl}/visitor/api/upload/image'; '${BytedeskConstants.httpUploadUrl}/visitor/api/upload/image';
print( BytedeskUtils.printLog(
"uploadImage fileName $fileName, username $username, upload Url $uploadUrl"); "uploadImage fileName $fileName, username $username, upload Url $uploadUrl");
var uri = Uri.parse(uploadUrl); var uri = Uri.parse(uploadUrl);
@ -288,13 +380,13 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
http.Response response = http.Response response =
await http.Response.fromStream(await request.send()); await http.Response.fromStream(await request.send());
// print("Result: ${response.body}"); // BytedeskUtils.printLog("Result: ${response.body}");
//json //json
Utf8Decoder utf8decoder = Utf8Decoder(); // fix Utf8Decoder utf8decoder = Utf8Decoder(); // fix
//string json //string json
final responseJson = json.decode(utf8decoder.convert(response.bodyBytes)); final responseJson = json.decode(utf8decoder.convert(response.bodyBytes));
print("upload image responseJson $responseJson"); BytedeskUtils.printLog("upload image responseJson $responseJson");
// //
return UploadJsonResult.fromJson(responseJson); return UploadJsonResult.fromJson(responseJson);
} }
@ -306,7 +398,7 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
String? username = SpUtil.getString(BytedeskConstants.uid); String? username = SpUtil.getString(BytedeskConstants.uid);
final uploadUrl = final uploadUrl =
'${BytedeskConstants.httpUploadUrl}/visitor/api/upload/video'; '${BytedeskConstants.httpUploadUrl}/visitor/api/upload/video';
print( BytedeskUtils.printLog(
"uploadVideo fileName $fileName, username $username, upload Url $uploadUrl"); "uploadVideo fileName $fileName, username $username, upload Url $uploadUrl");
// //
Map<String, String> headers = { Map<String, String> headers = {
@ -323,13 +415,13 @@ class BytedeskMessageHttpApi extends BytedeskBaseHttpApi {
http.Response response = http.Response response =
await http.Response.fromStream(await request.send()); await http.Response.fromStream(await request.send());
// print("Result: ${response.body}"); // BytedeskUtils.printLog("Result: ${response.body}");
//json //json
Utf8Decoder utf8decoder = Utf8Decoder(); // fix Utf8Decoder utf8decoder = Utf8Decoder(); // fix
//string json //string json
final responseJson = json.decode(utf8decoder.convert(response.bodyBytes)); final responseJson = json.decode(utf8decoder.convert(response.bodyBytes));
print("upload Video responseJson $responseJson"); BytedeskUtils.printLog("upload Video responseJson $responseJson");
// //
return UploadJsonResult.fromJson(responseJson); return UploadJsonResult.fromJson(responseJson);
} }

@ -7,6 +7,7 @@ import 'package:bytedesk_kefu/model/requestThread.dart';
import 'package:bytedesk_kefu/model/thread.dart'; import 'package:bytedesk_kefu/model/thread.dart';
import 'package:bytedesk_kefu/util/bytedesk_constants.dart'; import 'package:bytedesk_kefu/util/bytedesk_constants.dart';
import 'package:bytedesk_kefu/util/bytedesk_events.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:sp_util/sp_util.dart';
class BytedeskThreadHttpApi extends BytedeskBaseHttpApi { class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
@ -16,7 +17,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
// final threadUrl = '$baseUrl/api/thread/get?client=$client'; // final threadUrl = '$baseUrl/api/thread/get?client=$client';
final threadUrl = final threadUrl =
Uri.http(BytedeskConstants.host, '/api/thread/get', {'client': client}); Uri.http(BytedeskConstants.host, '/api/thread/get', {'client': client});
// print("thread Url $threadUrl"); // BytedeskUtils.printLog("thread Url $threadUrl");
final initResponse = final initResponse =
await this.httpClient.get(threadUrl, headers: getHeaders()); await this.httpClient.get(threadUrl, headers: getHeaders());
@ -25,7 +26,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -63,7 +64,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
BytedeskConstants.host, BytedeskConstants.host,
'/api/thread/history/records', '/api/thread/history/records',
{'page': page.toString(), 'size': size.toString(), 'client': client}); {'page': page.toString(), 'size': size.toString(), 'client': client});
// print("thread Url $threadUrl"); // BytedeskUtils.printLog("thread Url $threadUrl");
final initResponse = final initResponse =
await this.httpClient.get(threadUrl, headers: getHeaders()); await this.httpClient.get(threadUrl, headers: getHeaders());
@ -72,7 +73,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -104,7 +105,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("getVisitorThreads responseJson $responseJson"); // BytedeskUtils.printLog("getVisitorThreads responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -130,7 +131,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("getVisitorThreadsAll responseJson $responseJson"); BytedeskUtils.printLog("getVisitorThreadsAll responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -149,7 +150,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
// //
final threadUrl = Uri.http(BytedeskConstants.host, '/api/thread/request', final threadUrl = Uri.http(BytedeskConstants.host, '/api/thread/request',
{'wId': wid, 'type': type, 'aId': aid, 'client': client}); {'wId': wid, 'type': type, 'aId': aid, 'client': client});
print(threadUrl); BytedeskUtils.printLog(threadUrl);
final initResponse = final initResponse =
await this.httpClient.get(threadUrl, headers: getHeaders()); await this.httpClient.get(threadUrl, headers: getHeaders());
@ -158,8 +159,8 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("requestThread:"); // BytedeskUtils.printLog("requestThread:");
// print(responseJson); // BytedeskUtils.printLog(responseJson);
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -173,7 +174,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
// //
final threadUrl = Uri.http(BytedeskConstants.host, final threadUrl = Uri.http(BytedeskConstants.host,
'/api/v2/thread/workGroup', {'wId': wid, 'client': client}); '/api/v2/thread/workGroup', {'wId': wid, 'client': client});
print(threadUrl); BytedeskUtils.printLog(threadUrl);
final initResponse = final initResponse =
await this.httpClient.get(threadUrl, headers: getHeaders()); await this.httpClient.get(threadUrl, headers: getHeaders());
@ -182,8 +183,8 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("requestWorkGroupThreadV2:"); BytedeskUtils.printLog("requestWorkGroupThreadV2:");
print(responseJson); BytedeskUtils.printLog(responseJson);
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -200,7 +201,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
BytedeskConstants.host, BytedeskConstants.host,
'/api/thread/request/agent', '/api/thread/request/agent',
{'wId': wid, 'type': type, 'aId': aid, 'client': client}); {'wId': wid, 'type': type, 'aId': aid, 'client': client});
print("request agent Url $threadUrl"); BytedeskUtils.printLog("request agent Url $threadUrl");
final initResponse = final initResponse =
await this.httpClient.get(threadUrl, headers: getHeaders()); await this.httpClient.get(threadUrl, headers: getHeaders());
@ -209,7 +210,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -223,7 +224,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
// //
final threadUrl = Uri.http(BytedeskConstants.host, '/api/thread/contact', final threadUrl = Uri.http(BytedeskConstants.host, '/api/thread/contact',
{'cid': cid, 'client': client}); {'cid': cid, 'client': client});
print("request contact thread Url $threadUrl"); BytedeskUtils.printLog("request contact thread Url $threadUrl");
final initResponse = final initResponse =
await this.httpClient.get(threadUrl, headers: getHeaders()); await this.httpClient.get(threadUrl, headers: getHeaders());
@ -232,7 +233,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -246,7 +247,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
// //
final threadUrl = Uri.http(BytedeskConstants.host, '/api/thread/group', final threadUrl = Uri.http(BytedeskConstants.host, '/api/thread/group',
{'gid': gid, 'client': client}); {'gid': gid, 'client': client});
print("request contact thread Url $threadUrl"); BytedeskUtils.printLog("request contact thread Url $threadUrl");
final initResponse = final initResponse =
await this.httpClient.get(threadUrl, headers: getHeaders()); await this.httpClient.get(threadUrl, headers: getHeaders());
@ -255,7 +256,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -283,7 +284,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -311,7 +312,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -339,7 +340,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -367,7 +368,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -395,7 +396,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -423,7 +424,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -445,7 +446,7 @@ class BytedeskThreadHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {

@ -18,7 +18,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
// //
Future<OAuth> oauth(String? username, String? password) async { Future<OAuth> oauth(String? username, String? password) async {
var oauthUrl = Uri.http(BytedeskConstants.host, '/oauth/token'); var oauthUrl = Uri.http(BytedeskConstants.host, '/oauth/token');
// print("http api client: oauthUrl $oauthUrl"); // BytedeskUtils.printLog("http api client: oauthUrl $oauthUrl");
Map<String, String> headers = { Map<String, String> headers = {
"Authorization": "Basic Y2xpZW50OnNlY3JldA==" "Authorization": "Basic Y2xpZW50OnNlY3JldA=="
}; };
@ -30,14 +30,14 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
}; };
final oauthResponse = final oauthResponse =
await this.httpClient.post(oauthUrl, headers: headers, body: bodyMap); 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 // check the status code for the result
int statusCode = oauthResponse.statusCode; int statusCode = oauthResponse.statusCode;
// print("statusCode $statusCode"); // BytedeskUtils.printLog("statusCode $statusCode");
// 200: // 200:
final oauthJson = jsonDecode(oauthResponse.body); final oauthJson = jsonDecode(oauthResponse.body);
// print('oauth:'); BytedeskUtils.printLog('oauth:');
// print(oauthJson); BytedeskUtils.printLog(oauthJson);
SpUtil.putBool(BytedeskConstants.isLogin, true); SpUtil.putBool(BytedeskConstants.isLogin, true);
SpUtil.putString(BytedeskConstants.accessToken, oauthJson['access_token']); SpUtil.putString(BytedeskConstants.accessToken, oauthJson['access_token']);
// //
@ -50,7 +50,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
// final oauthUrl = '$baseUrl/mobile/token'; // final oauthUrl = '$baseUrl/mobile/token';
// final oauthUrl = Uri.http(BytedeskConstants.host, '/mobile/token'); // final oauthUrl = Uri.http(BytedeskConstants.host, '/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<String, String> headers = { Map<String, String> headers = {
"Authorization": "Basic Y2xpZW50OnNlY3JldA==" "Authorization": "Basic Y2xpZW50OnNlY3JldA=="
}; };
@ -63,12 +63,12 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
// //
final oauthResponse = final oauthResponse =
await this.httpClient.post(oauthUrl, headers: headers, body: bodyMap); await this.httpClient.post(oauthUrl, headers: headers, body: bodyMap);
// print('oauth result: $oauthResponse'); // BytedeskUtils.printLog('oauth result: $oauthResponse');
int statusCode = oauthResponse.statusCode; int statusCode = oauthResponse.statusCode;
// 200: // 200:
final oauthJson = jsonDecode(oauthResponse.body); final oauthJson = jsonDecode(oauthResponse.body);
print('smsOAuth:'); BytedeskUtils.printLog('smsOAuth:');
print(oauthJson); BytedeskUtils.printLog(oauthJson);
if (statusCode == 200) { if (statusCode == 200) {
SpUtil.putBool(BytedeskConstants.isLogin, true); SpUtil.putBool(BytedeskConstants.isLogin, true);
SpUtil.putBool(BytedeskConstants.isAuthenticated, true); SpUtil.putBool(BytedeskConstants.isAuthenticated, true);
@ -84,7 +84,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
// //
// final oauthUrl = '$baseUrl/wechat/token'; // final oauthUrl = '$baseUrl/wechat/token';
final oauthUrl = Uri.http(BytedeskConstants.host, '/wechat/token'); final oauthUrl = Uri.http(BytedeskConstants.host, '/wechat/token');
// print("http api client: oauthUrl $oauthUrl"); // BytedeskUtils.printLog("http api client: oauthUrl $oauthUrl");
Map<String, String> headers = { Map<String, String> headers = {
"Authorization": "Basic Y2xpZW50OnNlY3JldA==" "Authorization": "Basic Y2xpZW50OnNlY3JldA=="
}; };
@ -96,14 +96,14 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
// //
final oauthResponse = final oauthResponse =
await this.httpClient.post(oauthUrl, headers: headers, body: bodyMap); 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 // check the status code for the result
int statusCode = oauthResponse.statusCode; int statusCode = oauthResponse.statusCode;
// print("statusCode $statusCode"); // BytedeskUtils.printLog("statusCode $statusCode");
// 200: // 200:
final oauthJson = jsonDecode(oauthResponse.body); final oauthJson = jsonDecode(oauthResponse.body);
print('unionIdOAuth:'); BytedeskUtils.printLog('unionIdOAuth:');
print(oauthJson); BytedeskUtils.printLog(oauthJson);
if (statusCode == 200) { if (statusCode == 200) {
SpUtil.putBool(BytedeskConstants.isLogin, true); SpUtil.putBool(BytedeskConstants.isLogin, true);
SpUtil.putBool(BytedeskConstants.isAuthenticated, true); SpUtil.putBool(BytedeskConstants.isAuthenticated, true);
@ -137,8 +137,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("register:"); // BytedeskUtils.printLog("register:");
// print(responseJson); // BytedeskUtils.printLog(responseJson);
return JsonResult.fromJson(responseJson); return JsonResult.fromJson(responseJson);
} }
@ -157,8 +157,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("registerAnonymous:"); // BytedeskUtils.printLog("registerAnonymous:");
// print(responseJson); // BytedeskUtils.printLog(responseJson);
// //
User user = User.fromJson(responseJson['data']); User user = User.fromJson(responseJson['data']);
// //
@ -196,8 +196,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("registerUser:"); BytedeskUtils.printLog("registerUser:");
print(responseJson); BytedeskUtils.printLog(responseJson);
// //
int statusCode = responseJson['status_code']; int statusCode = responseJson['status_code'];
if (statusCode == 200) { if (statusCode == 200) {
@ -243,8 +243,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// final responseJson = json.decode(initResponse.body); // final responseJson = json.decode(initResponse.body);
// print("changePassword"); // BytedeskUtils.printLog("changePassword");
// print(responseJson); // BytedeskUtils.printLog(responseJson);
return JsonResult.fromJson(responseJson); return JsonResult.fromJson(responseJson);
} }
@ -261,8 +261,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("requestCode:"); // BytedeskUtils.printLog("requestCode:");
// print(responseJson); // BytedeskUtils.printLog(responseJson);
SpUtil.putBool(BytedeskConstants.exist, responseJson['data']['exist']); SpUtil.putBool(BytedeskConstants.exist, responseJson['data']['exist']);
SpUtil.putString(BytedeskConstants.code, responseJson['data']['code']); SpUtil.putString(BytedeskConstants.code, responseJson['data']['code']);
@ -284,7 +284,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
int statusCode = responseJson['status_code']; int statusCode = responseJson['status_code'];
if (statusCode == 200) { if (statusCode == 200) {
SpUtil.putBool(BytedeskConstants.isAuthenticated, true); SpUtil.putBool(BytedeskConstants.isAuthenticated, true);
@ -306,8 +306,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("getProfile:"); // BytedeskUtils.printLog("getProfile:");
// print(responseJson); // BytedeskUtils.printLog(responseJson);
// //
User user = User.fromJson(responseJson['data']); User user = User.fromJson(responseJson['data']);
// //
@ -334,8 +334,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("updateNickname:"); BytedeskUtils.printLog("updateNickname:");
print(responseJson); BytedeskUtils.printLog(responseJson);
// //
SpUtil.putString(BytedeskConstants.nickname, nickname!); SpUtil.putString(BytedeskConstants.nickname, nickname!);
@ -356,8 +356,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("updateAvatar:"); BytedeskUtils.printLog("updateAvatar:");
print(responseJson); BytedeskUtils.printLog(responseJson);
// //
SpUtil.putString(BytedeskConstants.avatar, avatar!); SpUtil.putString(BytedeskConstants.avatar, avatar!);
@ -378,8 +378,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("updateDescription:"); BytedeskUtils.printLog("updateDescription:");
print(responseJson); BytedeskUtils.printLog(responseJson);
// //
SpUtil.putString(BytedeskConstants.description, description!); SpUtil.putString(BytedeskConstants.description, description!);
@ -406,8 +406,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("updateProfile:"); BytedeskUtils.printLog("updateProfile:");
print(responseJson); BytedeskUtils.printLog(responseJson);
// //
SpUtil.putString(BytedeskConstants.nickname, nickname!); SpUtil.putString(BytedeskConstants.nickname, nickname!);
SpUtil.putString(BytedeskConstants.avatar, avatar!); SpUtil.putString(BytedeskConstants.avatar, avatar!);
@ -430,7 +430,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("updateSex $responseJson"); // BytedeskUtils.printLog("updateSex $responseJson");
// //
SpUtil.putBool(BytedeskConstants.sex, sex!); SpUtil.putBool(BytedeskConstants.sex, sex!);
@ -451,7 +451,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("updateLocation $responseJson"); // BytedeskUtils.printLog("updateLocation $responseJson");
// //
SpUtil.putString(BytedeskConstants.location, location!); SpUtil.putString(BytedeskConstants.location, location!);
@ -472,7 +472,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("updateBirthday $responseJson"); // BytedeskUtils.printLog("updateBirthday $responseJson");
// //
SpUtil.putString(BytedeskConstants.birthday, birthday!); SpUtil.putString(BytedeskConstants.birthday, birthday!);
@ -493,7 +493,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("updateMobile $responseJson"); // BytedeskUtils.printLog("updateMobile $responseJson");
// //
SpUtil.putString(BytedeskConstants.mobile, mobile!); SpUtil.putString(BytedeskConstants.mobile, mobile!);
@ -507,7 +507,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
String? username = SpUtil.getString(BytedeskConstants.uid); String? username = SpUtil.getString(BytedeskConstants.uid);
final uploadUrl = '$baseUrl/visitor/api/upload/image'; 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 uri = Uri.parse(uploadUrl);
var request = http.MultipartRequest('POST', uri) var request = http.MultipartRequest('POST', uri)
@ -517,17 +517,17 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
http.Response response = http.Response response =
await http.Response.fromStream(await request.send()); await http.Response.fromStream(await request.send());
// print("Result: ${response.body}"); // BytedeskUtils.printLog("Result: ${response.body}");
//json //json
Utf8Decoder utf8decoder = Utf8Decoder(); // fix Utf8Decoder utf8decoder = Utf8Decoder(); // fix
//string json //string json
final responseJson = json.decode(utf8decoder.convert(response.bodyBytes)); final responseJson = json.decode(utf8decoder.convert(response.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// TODO: status_code // TODO: status_code
String? url = responseJson['data']; String? url = responseJson['data'];
// print('url:' + url); // BytedeskUtils.printLog('url:' + url);
return url!; return url!;
} }
@ -545,7 +545,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// TODO: status_code // TODO: status_code
// //
return responseJson['data']['status'].toString(); return responseJson['data']['status'].toString();
@ -563,7 +563,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// TODO: status_code // TODO: status_code
// //
return responseJson['data']['status'].toString(); return responseJson['data']['status'].toString();
@ -583,7 +583,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// TODO: status_code // TODO: status_code
// //
return responseJson['data'].toString(); return responseJson['data'].toString();
@ -601,7 +601,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// TODO: status_code // TODO: status_code
// //
return responseJson['data'].toString(); return responseJson['data'].toString();
@ -619,7 +619,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// TODO: status_code // TODO: status_code
// //
return responseJson['data'].toString(); return responseJson['data'].toString();
@ -637,8 +637,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("checkAppVersion:"); BytedeskUtils.printLog("checkAppVersion:");
print(responseJson); BytedeskUtils.printLog(responseJson);
// token // token
if (responseJson.toString().contains('invalid_token')) { if (responseJson.toString().contains('invalid_token')) {
bytedeskEventBus.fire(InvalidTokenEventBus()); bytedeskEventBus.fire(InvalidTokenEventBus());
@ -663,7 +663,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// //
return responseJson['data'].toString(); return responseJson['data'].toString();
} }
@ -682,7 +682,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// //
return WeChatResult.fromJson(responseJson); return WeChatResult.fromJson(responseJson);
} }
@ -714,7 +714,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// //
UserJsonResult userJsonResult = UserJsonResult.fromJson(responseJson); UserJsonResult userJsonResult = UserJsonResult.fromJson(responseJson);
if (userJsonResult.statusCode == 200) { if (userJsonResult.statusCode == 200) {
@ -749,7 +749,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// //
UserJsonResult userJsonResult = UserJsonResult.fromJson(responseJson); UserJsonResult userJsonResult = UserJsonResult.fromJson(responseJson);
if (userJsonResult.statusCode == 200) { if (userJsonResult.statusCode == 200) {
@ -773,7 +773,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("responseJson $responseJson"); // BytedeskUtils.printLog("responseJson $responseJson");
// //
return responseJson['data']; return responseJson['data'];
} }
@ -790,7 +790,7 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("responseJson $responseJson"); BytedeskUtils.printLog("responseJson $responseJson");
// //
return JsonResult.fromJson(responseJson); return JsonResult.fromJson(responseJson);
} }
@ -807,8 +807,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
// print("unfollow:"); // BytedeskUtils.printLog("unfollow:");
// print(responseJson); // BytedeskUtils.printLog(responseJson);
return JsonResult.fromJson(responseJson); return JsonResult.fromJson(responseJson);
} }
@ -827,8 +827,8 @@ class BytedeskUserHttpApi extends BytedeskBaseHttpApi {
//string json //string json
final responseJson = final responseJson =
json.decode(utf8decoder.convert(initResponse.bodyBytes)); json.decode(utf8decoder.convert(initResponse.bodyBytes));
print("logout:"); BytedeskUtils.printLog("logout:");
print(responseJson); BytedeskUtils.printLog(responseJson);
BytedeskUtils.clearUserCache(); BytedeskUtils.clearUserCache();
} }
} }

@ -9,8 +9,8 @@ class Answer extends Equatable {
Answer({this.aid, this.question, this.answer}) : super(); Answer({this.aid, this.question, this.answer}) : super();
// //
static Answer fromJson(dynamic json) { static Answer fromJson(dynamic json) {
// print('aid:' + json['aid']); // BytedeskUtils.printLog('aid:' + json['aid']);
// print('question:' + json['question']); // BytedeskUtils.printLog('question:' + json['question']);
return Answer( return Answer(
aid: json['aid'], question: json['question'], answer: json['answer']); aid: json['aid'], question: json['question'], answer: json['answer']);
} }

@ -70,7 +70,7 @@ class MessageProvider {
version: 10, 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 // 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<int> insert(Message message) async { Future<int> insert(Message message) async {
@ -78,19 +78,19 @@ class MessageProvider {
if (BytedeskUtils.isWeb) { if (BytedeskUtils.isWeb) {
return 0; 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()); return await database!.insert(tableMessage!, message.toMap());
} }
// //
Future<List<Message>> getTopicMessages( Future<List<Message>> getTopicMessages(
String? topic, String? currentUid, int? page, int? size) async { String? topic, String? currentUid, int? page, int? size) async {
// print('1: ' + topic! + ' currentUid:' + currentUid!); // BytedeskUtils.printLog('1: ' + topic! + ' currentUid:' + currentUid!);
// FIXME: web // FIXME: web
if (BytedeskUtils.isWeb) { if (BytedeskUtils.isWeb) {
return []; return [];
} }
// print('2'); // BytedeskUtils.printLog('2');
// //
List<Map> maps = await database!.query(tableMessage!, List<Map> maps = await database!.query(tableMessage!,
columns: [ columns: [
@ -117,8 +117,8 @@ class MessageProvider {
limit: size, limit: size,
offset: page! * size!); offset: page! * size!);
// //
// print('3'); // BytedeskUtils.printLog('3');
// print(maps.length); // BytedeskUtils.printLog(maps.length);
// //
return List.generate(maps.length, (i) { return List.generate(maps.length, (i) {
// //
@ -140,7 +140,7 @@ class MessageProvider {
// .map((item) => Category.fromJson(item)) // .map((item) => Category.fromJson(item))
// .toList(); // .toList();
// } // }
// print('4'); // BytedeskUtils.printLog('4');
return Message( return Message(
mid: maps[i]['mid'], mid: maps[i]['mid'],
content: maps[i]['content'], content: maps[i]['content'],

@ -58,7 +58,7 @@ class ThreadProvider {
} }
Future<int> insert(Thread thread) async { Future<int> 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()); return await database!.insert(tableThread!, thread.toMap());
} }

@ -117,9 +117,7 @@ class BytedeskMqtt {
// .withWillMessage('My Will message') // .withWillMessage('My Will message')
// .startClean() // Non persistent session for testing // .startClean() // Non persistent session for testing
// .withWillQos(MqttQos.atLeastOnce); // .withWillQos(MqttQos.atLeastOnce);
if (BytedeskConstants.isDebug) { BytedeskUtils.printLog('mqttClient connecting....');
print('mqttClient connecting....');
}
mqttClient.connectionMessage = connMessage; mqttClient.connectionMessage = connMessage;
/// Connect the client, any errors here are communicated by raising of the appropriate exception. Note /// Connect the client, any errors here are communicated by raising of the appropriate exception. Note
@ -128,16 +126,16 @@ class BytedeskMqtt {
try { try {
await mqttClient.connect(); await mqttClient.connect();
} on Exception catch (e) { } on Exception catch (e) {
print('mqttClient exception - $e'); BytedeskUtils.printLog('mqttClient exception - $e');
mqttClient.disconnect(); mqttClient.disconnect();
} }
/// Check we are connected /// Check we are connected
if (mqttClient.connectionStatus.state == MqttConnectionState.connected) { if (mqttClient.connectionStatus.state == MqttConnectionState.connected) {
print('mqttClient connected'); BytedeskUtils.printLog('mqttClient connected');
} else { } else {
/// Use status here rather than state if you also want the broker return code. /// 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}'); 'ERROR mqttClient connection failed - disconnecting, status is ${mqttClient.connectionStatus}');
mqttClient.disconnect(); mqttClient.disconnect();
// exit(-1); // exit(-1);
@ -149,14 +147,14 @@ class BytedeskMqtt {
// final MqttPublishMessage recMess = c[0].payload; // final MqttPublishMessage recMess = c[0].payload;
// final String pt = // final String pt =
// MqttPublishPayload.bytesToStringAsString(recMess.payload.message); // 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) { // if (mqttClient != null && mqttClient.published != null) {
// //
mqttClient.published!.listen((MqttPublishMessage messageBinary) { 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 messageProto =
protomsg.Message.fromBuffer(messageBinary.payload.message); protomsg.Message.fromBuffer(messageBinary.payload.message);
@ -177,14 +175,12 @@ class BytedeskMqtt {
var timestamp = messageProto.timestamp; var timestamp = messageProto.timestamp;
var client = messageProto.client; var client = messageProto.client;
// //
if (BytedeskConstants.isDebug) { BytedeskUtils.printLog('bytedesk_mqtt.dart receive type:' +
print('bytedesk_mqtt.dart receive type:' + type +
type + ' client:' +
' client:' + client +
client + ' mid:' +
' mid:' + mid);
mid);
}
// , // ,
if (type == BytedeskConstants.MESSAGE_TYPE_NOTIFICATION_NOTICE) { if (type == BytedeskConstants.MESSAGE_TYPE_NOTIFICATION_NOTICE) {
// TODO: // TODO:
@ -232,6 +228,7 @@ class BytedeskMqtt {
sendReceipt = true; sendReceipt = true;
// TODO: // TODO:
message.content = messageProto.text.content; message.content = messageProto.text.content;
BytedeskUtils.printLog('receive text:' + message.content!);
break; break;
} }
case BytedeskConstants.MESSAGE_TYPE_IMAGE: case BytedeskConstants.MESSAGE_TYPE_IMAGE:
@ -550,7 +547,7 @@ class BytedeskMqtt {
return; return;
} }
default: default:
print('other message type:' + type); BytedeskUtils.printLog('other message type:' + type);
} }
// 使 // 使
// if (autoReply) { // if (autoReply) {
@ -564,7 +561,7 @@ class BytedeskMqtt {
// //
// final encrypter = Encrypter(AES(key, mode: AESMode.cbc)); // final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
// final decrypted = encrypter.decrypt64(messageProto.text.content, iv: iv); // final decrypted = encrypter.decrypt64(messageProto.text.content, iv: iv);
// print('content: ' + decrypted); // BytedeskUtils.printLog('content: ' + decrypted);
// //
// //
if (message.content == 'visitorConnect' || if (message.content == 'visitorConnect' ||
@ -579,18 +576,18 @@ class BytedeskMqtt {
bytedeskEventBus.fire(ReceiveMessageEventBus(message)); bytedeskEventBus.fire(ReceiveMessageEventBus(message));
// SDKdemo // SDKdemo
if (BytedeskKefu.getPlayAudioOnReceiveMessage()! && message.isSend == 0) { if (BytedeskKefu.getPlayAudioOnReceiveMessage()! && message.isSend == 0) {
// print('play audio'); // BytedeskUtils.printLog('play audio');
SystemSound.play(SystemSoundType.click); SystemSound.play(SystemSoundType.click);
} }
// SDKdemo // SDKdemo
if (BytedeskKefu.getVibrateOnReceiveMessage()! && message.isSend == 0) { if (BytedeskKefu.getVibrateOnReceiveMessage()! && message.isSend == 0) {
// print('should vibrate'); // BytedeskUtils.printLog('should vibrate');
vibrate(); vibrate();
} }
}); });
// //
// } else { // } else {
// print('mqttClient.published is null'); // BytedeskUtils.printLog('mqttClient.published is null');
// } // }
} }
@ -602,7 +599,7 @@ class BytedeskMqtt {
} }
void subscribe(String topic) { void subscribe(String topic) {
// print('Subscribing to the hello topic'); // BytedeskUtils.printLog('Subscribing to the hello topic');
mqttClient.subscribe(topic, MqttQos.exactlyOnce); mqttClient.subscribe(topic, MqttQos.exactlyOnce);
} }
@ -673,16 +670,16 @@ class BytedeskMqtt {
void publish(String content, String type, Thread currentThread, void publish(String content, String type, Thread currentThread,
ExtraParam? extraParam) { ExtraParam? extraParam) {
// if (currentThread == null) { // if (currentThread == null) {
// print('连接客服失败,请退出页面重新进入。注意: 请在App启动的时候调用init接口'); // BytedeskUtils.printLog('连接客服失败,请退出页面重新进入。注意: 请在App启动的时候调用init接口');
// Fluttertoast.showToast(msg: '连接客服失败,请退出页面重新进入'); // Fluttertoast.showToast(msg: '连接客服失败,请退出页面重新进入');
// return; // return;
// } // }
// https://pub.dev/packages/encrypt#aes // https://pub.dev/packages/encrypt#aes
// final encrypter = Encrypter(AES(key, mode: AESMode.cbc)); // final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
// final encrypted = encrypter.encrypt(content, iv: iv); // final encrypted = encrypter.encrypt(content, iv: iv);
// print(encrypted.base64); // BytedeskUtils.printLog(encrypted.base64);
// final decrypted = encrypter.decrypt(encrypted, iv: iv); // final decrypted = encrypter.decrypt(encrypted, iv: iv);
// print(decrypted); // BytedeskUtils.printLog(decrypted);
// thread // thread
protothread.Thread thread = new protothread.Thread(); protothread.Thread thread = new protothread.Thread();
thread.tid = currentThread.tid!; thread.tid = currentThread.tid!;
@ -958,8 +955,8 @@ class BytedeskMqtt {
// //
return; return;
} else { } else {
// TODO: //
print('other type:' + type); BytedeskUtils.printLog('other type:' + type);
} }
// //
messageProto.user = user; messageProto.user = user;
@ -992,46 +989,46 @@ class BytedeskMqtt {
/// The subscribed callback /// The subscribed callback
void _onSubscribed(String? topic) { void _onSubscribed(String? topic) {
// print('Subscription confirmed for topic $topic'); // BytedeskUtils.printLog('Subscription confirmed for topic $topic');
} }
/// The unsubscribed callback /// The unsubscribed callback
void _onUnSubscribed(String? topic) { void _onUnSubscribed(String? topic) {
// print('UnSubscription confirmed for topic $topic'); // BytedeskUtils.printLog('UnSubscription confirmed for topic $topic');
} }
/// The subscribed callback /// The subscribed callback
void _onSubscribeFailed(String? topic) { void _onSubscribeFailed(String? topic) {
// print('Subscribe Failed confirmed for topic $topic'); // BytedeskUtils.printLog('Subscribe Failed confirmed for topic $topic');
} }
/// The unsolicited disconnect callback /// The unsolicited disconnect callback
void _onDisconnected() { void _onDisconnected() {
// _isConnected = false; // _isConnected = false;
// print('OnDisconnected client callback - Client disconnection'); // BytedeskUtils.printLog('OnDisconnected client callback - Client disconnection');
// eventbus广 // eventbus广
bytedeskEventBus bytedeskEventBus
.fire(ConnectionEventBus(BytedeskConstants.USER_STATUS_DISCONNECTED)); .fire(ConnectionEventBus(BytedeskConstants.USER_STATUS_DISCONNECTED));
// if (mqttClient.connectionStatus.returnCode == MqttConnectReturnCode.solicited) { // if (mqttClient.connectionStatus.returnCode == MqttConnectReturnCode.solicited) {
// print('OnDisconnected callback is solicited, this is correct'); // BytedeskUtils.printLog('OnDisconnected callback is solicited, this is correct');
// } // }
// 10s // 10s
Future.delayed(Duration(seconds: 10), () { Future.delayed(Duration(seconds: 10), () {
// print('start reconnecting'); // BytedeskUtils.printLog('start reconnecting');
// reconnect(); // reconnect();
}); });
} }
/// The unsolicited disconnect callback /// The unsolicited disconnect callback
// void _onAutoReconnect() { // 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(); // // connect();
// } // }
/// The successful connect callback /// The successful connect callback
void _onConnected() { void _onConnected() {
// _isConnected = true; // _isConnected = true;
// print('OnConnected client callback - Client connection was sucessful'); // BytedeskUtils.printLog('OnConnected client callback - Client connection was sucessful');
// TODO: eventbus广 // TODO: eventbus广
bytedeskEventBus bytedeskEventBus
.fire(ConnectionEventBus(BytedeskConstants.USER_STATUS_CONNECTED)); .fire(ConnectionEventBus(BytedeskConstants.USER_STATUS_CONNECTED));
@ -1039,7 +1036,7 @@ class BytedeskMqtt {
/// Pong callback /// Pong callback
void _onPong() { void _onPong() {
// print('Ping response client callback invoked'); // BytedeskUtils.printLog('Ping response client callback invoked');
} }
bool isConnected() { bool isConnected() {

@ -38,7 +38,8 @@ class MqttServerConnection extends MqttConnectionBase {
try { try {
listener = client.listen(_onData, onError: onError, onDone: onDone); listener = client.listen(_onData, onError: onError, onDone: onDone);
} on Exception catch (e) { } on Exception catch (e) {
print('MqttServerConnection::_startListening - exception raised $e'); print(
'MqttServerConnection::_startListening - exception raised $e');
} }
} }

@ -29,6 +29,19 @@ class MessageRepository {
return await bytedeskHttpApi.loadChannelMessages(cid, page, size); return await bytedeskHttpApi.loadChannelMessages(cid, page, size);
} }
Future<List<Message>> loadUnreadMessages(
String? wid, int? page, int? size) async {
return await bytedeskHttpApi.loadUnreadMessages(wid, page, size);
}
Future<List<Message>> loadUnreadVisitorMessages(int? page, int? size) async {
return await bytedeskHttpApi.loadUnreadMessagesVisitor(page, size);
}
Future<List<Message>> loadUnreadAgentMessages(int? page, int? size) async {
return await bytedeskHttpApi.loadUnreadMessagesAgent(page, size);
}
Future<RequestAnswerResult> queryAnswer(String? tid, String? aid, String? mid) async { Future<RequestAnswerResult> queryAnswer(String? tid, String? aid, String? mid) async {
return await bytedeskHttpApi.queryAnswer2(tid, aid, mid); return await bytedeskHttpApi.queryAnswer2(tid, aid, mid);
} }

@ -85,12 +85,12 @@ class UserRepository {
} }
Future<void> logout() { Future<void> logout() {
// print("user_repository logout"); // BytedeskUtils.printLog("user_repository logout");
return Future.wait([bytedeskHttpApi.logout()]); return Future.wait([bytedeskHttpApi.logout()]);
} }
// Future<bool> isLogin() { // Future<bool> isLogin() {
// print("user_repository isSignedIn"); // BytedeskUtils.printLog("user_repository isSignedIn");
// // final currentUser = BytedeskHttpApi.currentUser(); // // final currentUser = BytedeskHttpApi.currentUser();
// // return currentUser != null; // // return currentUser != null;
// } // }
@ -100,7 +100,7 @@ class UserRepository {
} }
// Future<String> getUsername() { // Future<String> getUsername() {
// print("user_repository getUsername"); // BytedeskUtils.printLog("user_repository getUsername");
// return (BytedeskHttpApi.currentUser()).username; // return (BytedeskHttpApi.currentUser()).username;
// } // }

@ -102,7 +102,7 @@ class _ChatIMPageState extends State<ChatIMPage>
// //
@override @override
void initState() { void initState() {
// print('chat_kf_page init'); // BytedeskUtils.printLog('chat_kf_page init');
SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, true); SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, true);
// //
if (widget.isThread! && widget.thread != null) { if (widget.isThread! && widget.thread != null) {
@ -116,14 +116,14 @@ class _ChatIMPageState extends State<ChatIMPage>
WidgetsBinding.instance!.addObserver(this); WidgetsBinding.instance!.addObserver(this);
// buildhttps://blog.csdn.net/baoolong/article/details/85097318 // buildhttps://blog.csdn.net/baoolong/article/details/85097318
// WidgetsBinding.instance.addPostFrameCallback((_) { // WidgetsBinding.instance.addPostFrameCallback((_) {
// print('addPostFrameCallback'); // BytedeskUtils.printLog('addPostFrameCallback');
// }); // });
// Fluttertoast.showToast(msg: "请求中, 请稍后..."); // Fluttertoast.showToast(msg: "请求中, 请稍后...");
_listener(); _listener();
super.initState(); super.initState();
// 10s // 10s
_loadHistoryTimer = Timer.periodic(Duration(seconds: 10), (timer) { _loadHistoryTimer = Timer.periodic(Duration(seconds: 10), (timer) {
// print('从服务器 load history'); // BytedeskUtils.printLog('从服务器 load history');
BlocProvider.of<MessageBloc>(context) BlocProvider.of<MessageBloc>(context)
..add(LoadHistoryMessageEvent(uid: _currentUid, page: 0, size: 10)); ..add(LoadHistoryMessageEvent(uid: _currentUid, page: 0, size: 10));
// 1 // 1
@ -186,7 +186,7 @@ class _ChatIMPageState extends State<ChatIMPage>
// //
if (state.threadResult.statusCode == 200 || if (state.threadResult.statusCode == 200 ||
state.threadResult.statusCode == 201) { state.threadResult.statusCode == 201) {
print('创建新会话'); BytedeskUtils.printLog('创建新会话');
// //
// _messageProvider.insert(state.threadResult.msg!); // _messageProvider.insert(state.threadResult.msg!);
// TODO: pop // TODO: pop
@ -203,7 +203,7 @@ class _ChatIMPageState extends State<ChatIMPage>
widget.postscript!, _currentThread!); widget.postscript!, _currentThread!);
} }
} else if (state.threadResult.statusCode == 202) { } else if (state.threadResult.statusCode == 202) {
print('提示排队中'); BytedeskUtils.printLog('提示排队中');
// //
_messageProvider.insert(state.threadResult.msg!); _messageProvider.insert(state.threadResult.msg!);
// //
@ -222,7 +222,7 @@ class _ChatIMPageState extends State<ChatIMPage>
widget.postscript!, _currentThread!); widget.postscript!, _currentThread!);
} }
} else if (state.threadResult.statusCode == 203) { } else if (state.threadResult.statusCode == 203) {
print('当前非工作时间,请自助查询或留言'); BytedeskUtils.printLog('当前非工作时间,请自助查询或留言');
// TODO: // TODO:
setState(() { setState(() {
_currentThread = state.threadResult.msg!.thread; _currentThread = state.threadResult.msg!.thread;
@ -233,7 +233,7 @@ class _ChatIMPageState extends State<ChatIMPage>
_getMessages(_page, _size); _getMessages(_page, _size);
_appendMessage(state.threadResult.msg!); _appendMessage(state.threadResult.msg!);
} else if (state.threadResult.statusCode == 204) { } else if (state.threadResult.statusCode == 204) {
print('当前无客服在线,请自助查询或留言'); BytedeskUtils.printLog('当前无客服在线,请自助查询或留言');
// TODO: // TODO:
setState(() { setState(() {
_currentThread = state.threadResult.msg!.thread; _currentThread = state.threadResult.msg!.thread;
@ -244,7 +244,7 @@ class _ChatIMPageState extends State<ChatIMPage>
_getMessages(_page, _size); _getMessages(_page, _size);
_appendMessage(state.threadResult.msg!); _appendMessage(state.threadResult.msg!);
} else if (state.threadResult.statusCode == 205) { } else if (state.threadResult.statusCode == 205) {
print('咨询前问卷'); BytedeskUtils.printLog('咨询前问卷');
setState(() { setState(() {
_currentThread = state.threadResult.msg!.thread; _currentThread = state.threadResult.msg!.thread;
}); });
@ -255,7 +255,7 @@ class _ChatIMPageState extends State<ChatIMPage>
_appendMessage(state.threadResult.msg!); _appendMessage(state.threadResult.msg!);
// //
} else if (state.threadResult.statusCode == 206) { } else if (state.threadResult.statusCode == 206) {
print('返回机器人初始欢迎语 + 欢迎问题列表'); BytedeskUtils.printLog('返回机器人初始欢迎语 + 欢迎问题列表');
// TODO: // TODO:
setState(() { setState(() {
_isRobot = true; _isRobot = true;
@ -290,9 +290,10 @@ class _ChatIMPageState extends State<ChatIMPage>
), ),
BlocListener<MessageBloc, MessageState>( BlocListener<MessageBloc, MessageState>(
listener: (context, state) { listener: (context, state) {
// print('message state change'); // BytedeskUtils.printLog('message state change');
if (state is ReceiveMessageState) { if (state is ReceiveMessageState) {
print('receive message:' + state.message!.content!); BytedeskUtils.printLog(
'receive message:' + state.message!.content!);
} else if (state is UploadImageSuccess) { } else if (state is UploadImageSuccess) {
_bdMqtt.sendImageMessage( _bdMqtt.sendImageMessage(
state.uploadJsonResult.url!, _currentThread!); state.uploadJsonResult.url!, _currentThread!);
@ -327,14 +328,15 @@ class _ChatIMPageState extends State<ChatIMPage>
// TODO: // TODO:
} else if (state is LoadHistoryMessageSuccess) { } else if (state is LoadHistoryMessageSuccess) {
// TODO: // TODO:
// print('history ${state.messageList!.length}'); // BytedeskUtils.printLog('history ${state.messageList!.length}');
for (var i = 0; i < state.messageList!.length; i++) { for (var i = 0; i < state.messageList!.length; i++) {
// Message message = state.messageList[i]; // Message message = state.messageList[i];
// _appendMessage(message); // _appendMessage(message);
} }
} else if (state is LoadTopicMessageSuccess) { } else if (state is LoadTopicMessageSuccess) {
// TODO: // TODO:
print('topic history ${state.messageList!.length}'); BytedeskUtils.printLog(
'topic history ${state.messageList!.length}');
for (var i = 0; i < state.messageList!.length; i++) { for (var i = 0; i < state.messageList!.length; i++) {
// Message message = state.messageList[i]; // Message message = state.messageList[i];
// _appendMessage(message); // _appendMessage(message);
@ -375,7 +377,7 @@ class _ChatIMPageState extends State<ChatIMPage>
child: SmartRefresher( child: SmartRefresher(
enablePullDown: false, enablePullDown: false,
onLoading: () async { onLoading: () async {
print('TODO: 下拉刷新'); // BytedeskUtils.printLog('TODO: 下拉刷新'); //
// await Future.delayed(Duration(milliseconds: 1000)); // await Future.delayed(Duration(milliseconds: 1000));
_getMessages(_page, _size); _getMessages(_page, _size);
setState(() {}); setState(() {});
@ -457,7 +459,7 @@ class _ChatIMPageState extends State<ChatIMPage>
if (_debounce?.isActive ?? false) _debounce!.cancel(); if (_debounce?.isActive ?? false) _debounce!.cancel();
// 500 // 500
_debounce = Timer(const Duration(milliseconds: 500), () { _debounce = Timer(const Duration(milliseconds: 500), () {
print('send preview $value'); BytedeskUtils.printLog('send preview $value');
// value != null && // value != null &&
if (value.trim().length > 0) { if (value.trim().length > 0) {
_bdMqtt.sendPreviewMessage(value, _currentThread!); _bdMqtt.sendPreviewMessage(value, _currentThread!);
@ -512,7 +514,7 @@ class _ChatIMPageState extends State<ChatIMPage>
// //
_bdMqtt.sendTextMessage(text, _currentThread!); _bdMqtt.sendTextMessage(text, _currentThread!);
} else { } else {
print('长连接断开的情况下调用rest接口'); BytedeskUtils.printLog('长连接断开的情况下调用rest接口');
String? mid = BytedeskUuid.generateV4(); String? mid = BytedeskUuid.generateV4();
String? timestamp = BytedeskUtils.formatedDateNow(); String? timestamp = BytedeskUtils.formatedDateNow();
String? client = BytedeskUtils.getClient(); String? client = BytedeskUtils.getClient();
@ -574,7 +576,7 @@ class _ChatIMPageState extends State<ChatIMPage>
_listener() { _listener() {
// //
bytedeskEventBus.on<ReceiveMessageReceiptEventBus>().listen((event) { bytedeskEventBus.on<ReceiveMessageReceiptEventBus>().listen((event) {
// print('更新状态:' + event.status); // BytedeskUtils.printLog('更新状态:' + event.status);
if (!this.mounted) { if (!this.mounted) {
return; return;
} }
@ -591,7 +593,7 @@ class _ChatIMPageState extends State<ChatIMPage>
} }
}); });
bytedeskEventBus.on<ReceiveMessagePreviewEventBus>().listen((event) { bytedeskEventBus.on<ReceiveMessagePreviewEventBus>().listen((event) {
// print('消息预知'); // BytedeskUtils.printLog('消息预知');
if (this.mounted) { if (this.mounted) {
setState(() { setState(() {
// TODO: // TODO:
@ -602,7 +604,7 @@ class _ChatIMPageState extends State<ChatIMPage>
Timer( Timer(
Duration(seconds: 3), Duration(seconds: 3),
() { () {
// print('timer'); // BytedeskUtils.printLog('timer');
if (this.mounted) { if (this.mounted) {
setState(() { setState(() {
_title = widget.title; _title = widget.title;
@ -613,11 +615,11 @@ class _ChatIMPageState extends State<ChatIMPage>
}); });
// DeleteMessageEventBus // DeleteMessageEventBus
// bytedeskEventBus.on<ReceiveMessageRecallEventBus>().listen((event) { // bytedeskEventBus.on<ReceiveMessageRecallEventBus>().listen((event) {
// print('消息撤回'); // BytedeskUtils.printLog('消息撤回');
// }); // });
// //
bytedeskEventBus.on<ReceiveMessageEventBus>().listen((event) { bytedeskEventBus.on<ReceiveMessageEventBus>().listen((event) {
// print('receive message:' + event.message!.content); // BytedeskUtils.printLog('receive message:' + event.message!.content);
if (_currentThread != null && if (_currentThread != null &&
(event.message.thread!.topic != _currentThread!.topic)) { (event.message.thread!.topic != _currentThread!.topic)) {
return; return;
@ -656,7 +658,7 @@ class _ChatIMPageState extends State<ChatIMPage>
bytedeskEventBus.on<QueryAnswerEventBus>().listen((event) { bytedeskEventBus.on<QueryAnswerEventBus>().listen((event) {
// //
if (this.mounted) { if (this.mounted) {
print( BytedeskUtils.printLog(
'aid ${event.aid}, question ${event.question}, answer ${event.answer}'); 'aid ${event.aid}, question ${event.question}, answer ${event.answer}');
// //
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
@ -673,7 +675,7 @@ class _ChatIMPageState extends State<ChatIMPage>
// //
// if (_scrollController.position.pixels == // if (_scrollController.position.pixels ==
// _scrollController.position.maxScrollExtent) { // _scrollController.position.maxScrollExtent) {
// print('已经到底了'); // BytedeskUtils.printLog('已经到底了');
// } // }
}); });
} }
@ -685,7 +687,7 @@ class _ChatIMPageState extends State<ChatIMPage>
source: ImageSource.gallery, maxWidth: 800, imageQuality: 95); source: ImageSource.gallery, maxWidth: 800, imageQuality: 95);
// //
if (pickedFile != null) { if (pickedFile != null) {
print('pick image path: ${pickedFile.path}'); BytedeskUtils.printLog('pick image path: ${pickedFile.path}');
// TODO: // TODO:
// TODO: loading // TODO: loading
// //
@ -694,7 +696,7 @@ class _ChatIMPageState extends State<ChatIMPage>
// "/" + // "/" +
// BytedeskUtils.currentTimeMillis().toString() + // BytedeskUtils.currentTimeMillis().toString() +
// ".jpg"; // ".jpg";
// print('targetPath: $targetPath'); // BytedeskUtils.printLog('targetPath: $targetPath');
// await BytedeskUtils.compressImage(File(pickedFile.path), targetPath); // await BytedeskUtils.compressImage(File(pickedFile.path), targetPath);
// // // //
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
@ -706,7 +708,7 @@ class _ChatIMPageState extends State<ChatIMPage>
Fluttertoast.showToast(msg: '未选取图片'); Fluttertoast.showToast(msg: '未选取图片');
} }
} catch (e) { } catch (e) {
print('pick image error ${e.toString()}'); BytedeskUtils.printLog('pick image error ${e.toString()}');
Fluttertoast.showToast(msg: "未选取图片"); Fluttertoast.showToast(msg: "未选取图片");
} }
} }
@ -718,7 +720,7 @@ class _ChatIMPageState extends State<ChatIMPage>
source: ImageSource.camera, maxWidth: 800, imageQuality: 95); source: ImageSource.camera, maxWidth: 800, imageQuality: 95);
// //
if (pickedFile != null) { if (pickedFile != null) {
print('take image path: ${pickedFile.path}'); BytedeskUtils.printLog('take image path: ${pickedFile.path}');
// TODO: // TODO:
// TODO: loading // TODO: loading
// //
@ -727,7 +729,7 @@ class _ChatIMPageState extends State<ChatIMPage>
// "/" + // "/" +
// BytedeskUtils.currentTimeMillis().toString() + // BytedeskUtils.currentTimeMillis().toString() +
// ".jpg"; // ".jpg";
// print('targetPath: $targetPath'); // BytedeskUtils.printLog('targetPath: $targetPath');
// await BytedeskUtils.compressImage(File(pickedFile.path), targetPath); // await BytedeskUtils.compressImage(File(pickedFile.path), targetPath);
// // // //
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
@ -739,7 +741,7 @@ class _ChatIMPageState extends State<ChatIMPage>
Fluttertoast.showToast(msg: '未拍照'); Fluttertoast.showToast(msg: '未拍照');
} }
} catch (e) { } catch (e) {
print('take image error ${e.toString()}'); BytedeskUtils.printLog('take image error ${e.toString()}');
Fluttertoast.showToast(msg: "未选取图片"); Fluttertoast.showToast(msg: "未选取图片");
} }
} }
@ -751,7 +753,7 @@ class _ChatIMPageState extends State<ChatIMPage>
try { try {
// final PickedFile videoFile = await _picker.getVideo( // final PickedFile videoFile = await _picker.getVideo(
// source: ImageSource.gallery, maxDuration: const Duration(seconds: 10)); // source: ImageSource.gallery, maxDuration: const Duration(seconds: 10));
// print('pick video path: ${videoFile.path}'); // BytedeskUtils.printLog('pick video path: ${videoFile.path}');
// if (videoFile != null) { // if (videoFile != null) {
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
// ..add(UploadVideoEvent(filePath: videoFile.path)); // ..add(UploadVideoEvent(filePath: videoFile.path));
@ -775,9 +777,9 @@ class _ChatIMPageState extends State<ChatIMPage>
// VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality)
// deleteOrigin: false, // default(false) // deleteOrigin: false, // default(false)
// ); // );
// // debugPrint(info.toJson().toString()); // // debugBytedeskUtils.printLog(info.toJson().toString());
// String? afterPath = info.toJson()['path']; // 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<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
// ..add(UploadVideoEvent(filePath: afterPath)); // ..add(UploadVideoEvent(filePath: afterPath));
@ -786,7 +788,7 @@ class _ChatIMPageState extends State<ChatIMPage>
..add(UploadVideoEvent(filePath: _paths[0].path)); ..add(UploadVideoEvent(filePath: _paths[0].path));
} }
} catch (e) { } catch (e) {
print('pick video error ${e.toString()}'); BytedeskUtils.printLog('pick video error ${e.toString()}');
Fluttertoast.showToast(msg: "未选取视频"); Fluttertoast.showToast(msg: "未选取视频");
} }
} }
@ -798,7 +800,7 @@ class _ChatIMPageState extends State<ChatIMPage>
source: ImageSource.camera, maxDuration: const Duration(seconds: 10)); source: ImageSource.camera, maxDuration: const Duration(seconds: 10));
// //
if (pickedFile != null) { if (pickedFile != null) {
print('take video path: ${pickedFile.path}'); BytedeskUtils.printLog('take video path: ${pickedFile.path}');
// TODO: // TODO:
// TODO: loading // TODO: loading
// //
@ -808,9 +810,9 @@ class _ChatIMPageState extends State<ChatIMPage>
// VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality)
// deleteOrigin: false, // default(false) // deleteOrigin: false, // default(false)
// ); // );
// // debugPrint(info.toJson().toString()); // // debugBytedeskUtils.printLog(info.toJson().toString());
// String? afterPath = info.toJson()['path']; // String? afterPath = info.toJson()['path'];
// // print('video path: ${pickedFile.path}, compress path: $afterPath'); // // BytedeskUtils.printLog('video path: ${pickedFile.path}, compress path: $afterPath');
// // // //
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
// ..add(UploadVideoEvent(filePath: afterPath)); // ..add(UploadVideoEvent(filePath: afterPath));
@ -821,14 +823,14 @@ class _ChatIMPageState extends State<ChatIMPage>
Fluttertoast.showToast(msg: '未录制视频'); Fluttertoast.showToast(msg: '未录制视频');
} }
} catch (e) { } catch (e) {
print('take video error ${e.toString()}'); BytedeskUtils.printLog('take video error ${e.toString()}');
Fluttertoast.showToast(msg: "未录制视频"); Fluttertoast.showToast(msg: "未录制视频");
} }
} }
// //
// Future<void> _loadMoreMessages() async { // Future<void> _loadMoreMessages() async {
// print('load more'); // BytedeskUtils.printLog('load more');
// // TODO: // // TODO:
// _getMessages(_page, _size); // _getMessages(_page, _size);
// } // }
@ -857,7 +859,7 @@ class _ChatIMPageState extends State<ChatIMPage>
} }
Future<Null> _appendMessage(Message message) async { Future<Null> _appendMessage(Message message) async {
// print('append:' + message!.mid); // BytedeskUtils.printLog('append:' + message!.mid);
bool contains = false; bool contains = false;
for (var i = 0; i < _messages.length; i++) { for (var i = 0; i < _messages.length; i++) {
Message? element = _messages[i].message; Message? element = _messages[i].message;
@ -895,7 +897,7 @@ class _ChatIMPageState extends State<ChatIMPage>
@override @override
void didChangeAppLifecycleState(AppLifecycleState state) { void didChangeAppLifecycleState(AppLifecycleState state) {
// print("didChangeAppLifecycleState:" + state.toString()); // BytedeskUtils.printLog("didChangeAppLifecycleState:" + state.toString());
switch (state) { switch (state) {
case AppLifecycleState.inactive: // case AppLifecycleState.inactive: //
break; break;
@ -913,7 +915,7 @@ class _ChatIMPageState extends State<ChatIMPage>
@override @override
void dispose() { void dispose() {
// print('chat_kf_page dispose'); // BytedeskUtils.printLog('chat_kf_page dispose');
SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, false); SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, false);
WidgetsBinding.instance!.removeObserver(this); WidgetsBinding.instance!.removeObserver(this);
_debounce?.cancel(); _debounce?.cancel();

@ -100,14 +100,14 @@ class _ChatKFPageState extends State<ChatKFPage>
// preview // preview
Timer? _debounce; Timer? _debounce;
// //
// Timer? _loadHistoryTimer; Timer? _loadHistoryTimer;
// //
// final _flutterVideoCompress = FlutterVideoCompress(); // final _flutterVideoCompress = FlutterVideoCompress();
bool _isRequestingThread = true; bool _isRequestingThread = true;
// //
@override @override
void initState() { void initState() {
// print('chat_kf_page init'); // BytedeskUtils.printLog('chat_kf_page init');
SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, true); SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, true);
// //
if (widget.isThread! && widget.thread != null) { if (widget.isThread! && widget.thread != null) {
@ -124,20 +124,22 @@ class _ChatKFPageState extends State<ChatKFPage>
WidgetsBinding.instance!.addObserver(this); WidgetsBinding.instance!.addObserver(this);
// buildhttps://blog.csdn.net/baoolong/article/details/85097318 // buildhttps://blog.csdn.net/baoolong/article/details/85097318
// WidgetsBinding.instance.addPostFrameCallback((_) { // WidgetsBinding.instance.addPostFrameCallback((_) {
// print('addPostFrameCallback'); // BytedeskUtils.printLog('addPostFrameCallback');
// }); // });
// Fluttertoast.showToast(msg: "请求中, 请稍后..."); // Fluttertoast.showToast(msg: "请求中, 请稍后...");
_listener(); _listener();
super.initState(); super.initState();
// 10s // 10s
// _loadHistoryTimer = Timer.periodic(Duration(seconds: 10), (timer) { _loadHistoryTimer = Timer.periodic(Duration(seconds: 15), (timer) {
// // print('从服务器 load history'); // BytedeskUtils.printLog('从服务器 load history');
// // TODO: // // TODO:
// // BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
// // ..add(LoadHistoryMessageEvent(uid: _currentUid, page: 0, size: 10)); // ..add(LoadHistoryMessageEvent(uid: _currentUid, page: 0, size: 10));
// // 1 // // 1
// // timer.cancel(); // // timer.cancel();
// }); });
BlocProvider.of<MessageBloc>(context)
..add(LoadUnreadVisitorMessagesEvent(page: 0, size: 10));
} }
// //
@ -197,7 +199,7 @@ class _ChatKFPageState extends State<ChatKFPage>
// //
if (state.threadResult.statusCode == 200 || if (state.threadResult.statusCode == 200 ||
state.threadResult.statusCode == 201) { state.threadResult.statusCode == 201) {
print('创建新会话'); BytedeskUtils.printLog('创建新会话');
// TODO: pop // TODO: pop
// //
if (widget.custom != null && if (widget.custom != null &&
@ -212,7 +214,7 @@ class _ChatKFPageState extends State<ChatKFPage>
widget.postscript!, _currentThread!); widget.postscript!, _currentThread!);
} }
} else if (state.threadResult.statusCode == 202) { } else if (state.threadResult.statusCode == 202) {
print('提示排队中'); BytedeskUtils.printLog('提示排队中');
// //
_messageProvider.insert(state.threadResult.msg!); _messageProvider.insert(state.threadResult.msg!);
// //
@ -230,7 +232,7 @@ class _ChatKFPageState extends State<ChatKFPage>
widget.postscript!, _currentThread!); widget.postscript!, _currentThread!);
} }
} else if (state.threadResult.statusCode == 203) { } else if (state.threadResult.statusCode == 203) {
print('当前非工作时间,请自助查询或留言'); BytedeskUtils.printLog('当前非工作时间,请自助查询或留言');
setState(() { setState(() {
_currentThread = state.threadResult.msg!.thread; _currentThread = state.threadResult.msg!.thread;
}); });
@ -248,7 +250,7 @@ class _ChatKFPageState extends State<ChatKFPage>
tip: state.threadResult.msg!.content); tip: state.threadResult.msg!.content);
})); }));
} else if (state.threadResult.statusCode == 204) { } else if (state.threadResult.statusCode == 204) {
print('当前无客服在线,请自助查询或留言'); BytedeskUtils.printLog('当前无客服在线,请自助查询或留言');
setState(() { setState(() {
_currentThread = state.threadResult.msg!.thread; _currentThread = state.threadResult.msg!.thread;
}); });
@ -267,7 +269,7 @@ class _ChatKFPageState extends State<ChatKFPage>
tip: state.threadResult.msg!.content); tip: state.threadResult.msg!.content);
})); }));
} else if (state.threadResult.statusCode == 205) { } else if (state.threadResult.statusCode == 205) {
print('咨询前问卷'); BytedeskUtils.printLog('咨询前问卷');
setState(() { setState(() {
_currentThread = state.threadResult.msg!.thread; _currentThread = state.threadResult.msg!.thread;
}); });
@ -278,7 +280,7 @@ class _ChatKFPageState extends State<ChatKFPage>
_appendMessage(state.threadResult.msg!); _appendMessage(state.threadResult.msg!);
// //
} else if (state.threadResult.statusCode == 206) { } else if (state.threadResult.statusCode == 206) {
// print('返回机器人初始欢迎语 + 欢迎问题列表'); // BytedeskUtils.printLog('返回机器人初始欢迎语 + 欢迎问题列表');
// TODO: // TODO:
setState(() { setState(() {
_isRobot = true; _isRobot = true;
@ -329,9 +331,9 @@ class _ChatKFPageState extends State<ChatKFPage>
), ),
BlocListener<MessageBloc, MessageState>( BlocListener<MessageBloc, MessageState>(
listener: (context, state) { listener: (context, state) {
// print('message state change'); // BytedeskUtils.printLog('message state change');
if (state is ReceiveMessageState) { if (state is ReceiveMessageState) {
// print('receive message:' + state.message!.content!); // BytedeskUtils.printLog('receive message:' + state.message!.content!);
} else if (state is MessageUpLoading) { } else if (state is MessageUpLoading) {
Fluttertoast.showToast(msg: '上传中...'); Fluttertoast.showToast(msg: '上传中...');
} else if (state is UploadImageSuccess) { } else if (state is UploadImageSuccess) {
@ -375,7 +377,13 @@ class _ChatKFPageState extends State<ChatKFPage>
} else if (state is RateAnswerSuccess) { } else if (state is RateAnswerSuccess) {
// TODO: // TODO:
} else if (state is LoadHistoryMessageSuccess) { } 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++) { for (var i = 0; i < state.messageList!.length; i++) {
Message message = state.messageList![i]; Message message = state.messageList![i];
@ -406,7 +414,7 @@ class _ChatKFPageState extends State<ChatKFPage>
child: SmartRefresher( child: SmartRefresher(
enablePullDown: false, enablePullDown: false,
onLoading: () async { onLoading: () async {
// print('TODO: 下拉刷新'); // // BytedeskUtils.printLog('TODO: 下拉刷新'); //
// await Future.delayed(Duration(milliseconds: 1000)); // await Future.delayed(Duration(milliseconds: 1000));
_getMessages(_page, _size); _getMessages(_page, _size);
setState(() {}); setState(() {});
@ -490,7 +498,7 @@ class _ChatKFPageState extends State<ChatKFPage>
if (_debounce?.isActive ?? false) _debounce!.cancel(); if (_debounce?.isActive ?? false) _debounce!.cancel();
// 500 // 500
_debounce = Timer(const Duration(milliseconds: 500), () { _debounce = Timer(const Duration(milliseconds: 500), () {
// print('send preview $value'); // BytedeskUtils.printLog('send preview $value');
// //
if (value.trim().length > 0) { if (value.trim().length > 0) {
_bdMqtt.sendPreviewMessage(value, _currentThread!); _bdMqtt.sendPreviewMessage(value, _currentThread!);
@ -547,7 +555,7 @@ class _ChatKFPageState extends State<ChatKFPage>
// //
_bdMqtt.sendTextMessage(text, _currentThread!); _bdMqtt.sendTextMessage(text, _currentThread!);
} else { } else {
// print('长连接断开的情况下调用rest接口'); // BytedeskUtils.printLog('长连接断开的情况下调用rest接口');
sendTextMessageRest(text); sendTextMessageRest(text);
} }
} }
@ -744,7 +752,7 @@ class _ChatKFPageState extends State<ChatKFPage>
_listener() { _listener() {
// //
bytedeskEventBus.on<ReceiveMessageReceiptEventBus>().listen((event) { bytedeskEventBus.on<ReceiveMessageReceiptEventBus>().listen((event) {
// print('更新状态:' + event.mid + '-' + event.status); // BytedeskUtils.printLog('更新状态:' + event.mid + '-' + event.status);
if (this.mounted) { if (this.mounted) {
// //
for (var i = 0; i < _messages.length; i++) { for (var i = 0; i < _messages.length; i++) {
@ -752,7 +760,7 @@ class _ChatKFPageState extends State<ChatKFPage>
if (messageWidget.message!.mid == event.mid && if (messageWidget.message!.mid == event.mid &&
_messages[i].message!.status != _messages[i].message!.status !=
BytedeskConstants.MESSAGE_STATUS_READ) { BytedeskConstants.MESSAGE_STATUS_READ) {
// print('do update status:' + messageWidget.message!.mid!); // BytedeskUtils.printLog('do update status:' + messageWidget.message!.mid!);
// setState(() { // setState(() {
// _messages[i].message!.status = event.status; // // _messages[i].message!.status = event.status; //
// }); // });
@ -772,7 +780,7 @@ class _ChatKFPageState extends State<ChatKFPage>
} }
}); });
bytedeskEventBus.on<ReceiveMessagePreviewEventBus>().listen((event) { bytedeskEventBus.on<ReceiveMessagePreviewEventBus>().listen((event) {
// print('消息预知'); // BytedeskUtils.printLog('消息预知');
if (this.mounted) { if (this.mounted) {
setState(() { setState(() {
// TODO: // TODO:
@ -783,7 +791,7 @@ class _ChatKFPageState extends State<ChatKFPage>
Timer( Timer(
Duration(seconds: 3), Duration(seconds: 3),
() { () {
// print('timer'); // BytedeskUtils.printLog('timer');
if (this.mounted) { if (this.mounted) {
setState(() { setState(() {
_title = widget.title; _title = widget.title;
@ -794,7 +802,7 @@ class _ChatKFPageState extends State<ChatKFPage>
}); });
// //
bytedeskEventBus.on<ReceiveMessageEventBus>().listen((event) { bytedeskEventBus.on<ReceiveMessageEventBus>().listen((event) {
// print('receive message:' + event.message!.content); // BytedeskUtils.printLog('receive message:' + event.message!.content);
if (_currentThread != null && if (_currentThread != null &&
(event.message.thread!.topic != _currentThread!.topic)) { (event.message.thread!.topic != _currentThread!.topic)) {
return; return;
@ -834,7 +842,7 @@ class _ChatKFPageState extends State<ChatKFPage>
// //
bytedeskEventBus.on<QueryAnswerEventBus>().listen((event) { bytedeskEventBus.on<QueryAnswerEventBus>().listen((event) {
if (this.mounted) { 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); appendQueryMessage(event.question);
// //
@ -849,7 +857,7 @@ class _ChatKFPageState extends State<ChatKFPage>
// //
bytedeskEventBus.on<QueryCategoryEventBus>().listen((event) { bytedeskEventBus.on<QueryCategoryEventBus>().listen((event) {
if (this.mounted) { if (this.mounted) {
print('cid ${event.cid}, name ${event.name}'); BytedeskUtils.printLog('cid ${event.cid}, name ${event.name}');
// //
appendQueryMessage(event.name); appendQueryMessage(event.name);
// //
@ -872,7 +880,7 @@ class _ChatKFPageState extends State<ChatKFPage>
// //
// if (_scrollController.position.pixels == // if (_scrollController.position.pixels ==
// _scrollController.position.maxScrollExtent) { // _scrollController.position.maxScrollExtent) {
// print('已经到底了'); // BytedeskUtils.printLog('已经到底了');
// } // }
}); });
} }
@ -885,7 +893,7 @@ class _ChatKFPageState extends State<ChatKFPage>
source: ImageSource.gallery, maxWidth: 800, imageQuality: 95); source: ImageSource.gallery, maxWidth: 800, imageQuality: 95);
// //
if (pickedFile != null) { if (pickedFile != null) {
print('pick image path: ${pickedFile.path}'); BytedeskUtils.printLog('pick image path: ${pickedFile.path}');
// TODO: // TODO:
// TODO: loading // TODO: loading
// //
@ -894,7 +902,7 @@ class _ChatKFPageState extends State<ChatKFPage>
// "/" + // "/" +
// BytedeskUtils.currentTimeMillis().toString() + // BytedeskUtils.currentTimeMillis().toString() +
// ".jpg"; // ".jpg";
// print('targetPath: $targetPath'); // BytedeskUtils.printLog('targetPath: $targetPath');
// await BytedeskUtils.compressImage(File(pickedFile.path), targetPath); // await BytedeskUtils.compressImage(File(pickedFile.path), targetPath);
// // // //
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
@ -906,7 +914,7 @@ class _ChatKFPageState extends State<ChatKFPage>
Fluttertoast.showToast(msg: '未选取图片'); Fluttertoast.showToast(msg: '未选取图片');
} }
} catch (e) { } catch (e) {
print('pick image error ${e.toString()}'); BytedeskUtils.printLog('pick image error ${e.toString()}');
Fluttertoast.showToast(msg: "未选取图片"); Fluttertoast.showToast(msg: "未选取图片");
} }
} }
@ -918,7 +926,7 @@ class _ChatKFPageState extends State<ChatKFPage>
source: ImageSource.camera, maxWidth: 800, imageQuality: 95); source: ImageSource.camera, maxWidth: 800, imageQuality: 95);
// //
if (pickedFile != null) { if (pickedFile != null) {
print('take image path: ${pickedFile.path}'); BytedeskUtils.printLog('take image path: ${pickedFile.path}');
// TODO: // TODO:
// TODO: loading // TODO: loading
// //
@ -927,7 +935,7 @@ class _ChatKFPageState extends State<ChatKFPage>
// "/" + // "/" +
// BytedeskUtils.currentTimeMillis().toString() + // BytedeskUtils.currentTimeMillis().toString() +
// ".jpg"; // ".jpg";
// print('targetPath: $targetPath'); // BytedeskUtils.printLog('targetPath: $targetPath');
// await BytedeskUtils.compressImage(File(pickedFile.path), targetPath); // await BytedeskUtils.compressImage(File(pickedFile.path), targetPath);
// // // //
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
@ -939,7 +947,7 @@ class _ChatKFPageState extends State<ChatKFPage>
Fluttertoast.showToast(msg: '未拍照'); Fluttertoast.showToast(msg: '未拍照');
} }
} catch (e) { } catch (e) {
print('take image error ${e.toString()}'); BytedeskUtils.printLog('take image error ${e.toString()}');
Fluttertoast.showToast(msg: "未选取图片"); Fluttertoast.showToast(msg: "未选取图片");
} }
} }
@ -951,7 +959,7 @@ class _ChatKFPageState extends State<ChatKFPage>
try { try {
// final PickedFile videoFile = await _picker.getVideo( // final PickedFile videoFile = await _picker.getVideo(
// source: ImageSource.gallery, maxDuration: const Duration(seconds: 10)); // source: ImageSource.gallery, maxDuration: const Duration(seconds: 10));
// print('pick video path: ${videoFile.path}'); // BytedeskUtils.printLog('pick video path: ${videoFile.path}');
// if (videoFile != null) { // if (videoFile != null) {
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
// ..add(UploadVideoEvent(filePath: videoFile.path)); // ..add(UploadVideoEvent(filePath: videoFile.path));
@ -975,9 +983,9 @@ class _ChatKFPageState extends State<ChatKFPage>
// VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality)
// deleteOrigin: false, // default(false) // deleteOrigin: false, // default(false)
// ); // );
// // debugPrint(info.toJson().toString()); // // debugBytedeskUtils.printLog(info.toJson().toString());
// String? afterPath = info.toJson()['path']; // 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<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
// ..add(UploadVideoEvent(filePath: afterPath)); // ..add(UploadVideoEvent(filePath: afterPath));
@ -986,7 +994,7 @@ class _ChatKFPageState extends State<ChatKFPage>
..add(UploadVideoEvent(filePath: _paths[0].path)); ..add(UploadVideoEvent(filePath: _paths[0].path));
} }
} catch (e) { } catch (e) {
print('pick video error ${e.toString()}'); BytedeskUtils.printLog('pick video error ${e.toString()}');
Fluttertoast.showToast(msg: "未选取视频"); Fluttertoast.showToast(msg: "未选取视频");
} }
} }
@ -998,7 +1006,7 @@ class _ChatKFPageState extends State<ChatKFPage>
source: ImageSource.camera, maxDuration: const Duration(seconds: 10)); source: ImageSource.camera, maxDuration: const Duration(seconds: 10));
// //
if (pickedFile != null) { if (pickedFile != null) {
print('take video path: ${pickedFile.path}'); BytedeskUtils.printLog('take video path: ${pickedFile.path}');
// TODO: // TODO:
// TODO: loading // TODO: loading
// //
@ -1008,9 +1016,9 @@ class _ChatKFPageState extends State<ChatKFPage>
// VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality)
// deleteOrigin: false, // default(false) // deleteOrigin: false, // default(false)
// ); // );
// // debugPrint(info.toJson().toString()); // // debugBytedeskUtils.printLog(info.toJson().toString());
// String? afterPath = info.toJson()['path']; // String? afterPath = info.toJson()['path'];
// // print('video path: ${pickedFile.path}, compress path: $afterPath'); // // BytedeskUtils.printLog('video path: ${pickedFile.path}, compress path: $afterPath');
// // // //
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
// ..add(UploadVideoEvent(filePath: afterPath)); // ..add(UploadVideoEvent(filePath: afterPath));
@ -1021,14 +1029,14 @@ class _ChatKFPageState extends State<ChatKFPage>
Fluttertoast.showToast(msg: '未录制视频'); Fluttertoast.showToast(msg: '未录制视频');
} }
} catch (e) { } catch (e) {
print('take video error ${e.toString()}'); BytedeskUtils.printLog('take video error ${e.toString()}');
Fluttertoast.showToast(msg: "未录制视频"); Fluttertoast.showToast(msg: "未录制视频");
} }
} }
// //
// Future<void> _loadMoreMessages() async { // Future<void> _loadMoreMessages() async {
// print('load more'); // BytedeskUtils.printLog('load more');
// // TODO: // // TODO:
// _getMessages(_page, _size); // _getMessages(_page, _size);
// } // }
@ -1042,7 +1050,7 @@ class _ChatKFPageState extends State<ChatKFPage>
// //
List<Message> messageList = await _messageProvider.getTopicMessages( List<Message> messageList = await _messageProvider.getTopicMessages(
_currentThread!.topic, _currentUid, page, size); _currentThread!.topic, _currentUid, page, size);
// print(messageList.length); // BytedeskUtils.printLog(messageList.length);
int length = messageList.length; int length = messageList.length;
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
Message message = messageList[i]; Message message = messageList[i];
@ -1103,15 +1111,16 @@ class _ChatKFPageState extends State<ChatKFPage>
if (message.status != BytedeskConstants.MESSAGE_STATUS_READ) { if (message.status != BytedeskConstants.MESSAGE_STATUS_READ) {
// //
if (message.isSend == 0) { if (message.isSend == 0) {
print('message.mid ${message.mid}'); // BytedeskUtils.printLog('message.mid ${message.mid}');
print('_currentThread ${_currentThread!.tid}'); // BytedeskUtils.printLog('_currentThread ${_currentThread!.tid}');
_bdMqtt.sendReceiptReadMessage(message.mid!, _currentThread!); _bdMqtt.sendReceiptReadMessage(message.mid!, _currentThread!);
} }
} }
} }
Future<Null> _appendMessage(Message message) async { Future<Null> _appendMessage(Message message) async {
print('append:' + message.mid! + 'content:' + message.content!); BytedeskUtils.printLog(
'append:' + message.mid! + 'content:' + message.content!);
pushToMessageArray(message, true); pushToMessageArray(message, true);
} }
@ -1130,7 +1139,7 @@ class _ChatKFPageState extends State<ChatKFPage>
@override @override
void didChangeAppLifecycleState(AppLifecycleState state) { void didChangeAppLifecycleState(AppLifecycleState state) {
// print("didChangeAppLifecycleState:" + state.toString()); // BytedeskUtils.printLog("didChangeAppLifecycleState:" + state.toString());
switch (state) { switch (state) {
case AppLifecycleState.inactive: // case AppLifecycleState.inactive: //
break; break;
@ -1148,11 +1157,12 @@ class _ChatKFPageState extends State<ChatKFPage>
@override @override
void dispose() { void dispose() {
// print('chat_kf_page dispose'); // BytedeskUtils.printLog('chat_kf_page dispose');
SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, false); SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, false);
WidgetsBinding.instance!.removeObserver(this); WidgetsBinding.instance!.removeObserver(this);
_debounce?.cancel(); _debounce?.cancel();
// _loadHistoryTimer?.cancel(); _loadHistoryTimer?.cancel();
// bytedeskEventBus.destroy(); // FIXME: destroy
super.dispose(); super.dispose();
} }
} }

@ -21,6 +21,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttertoast/fluttertoast.dart'; import 'package:fluttertoast/fluttertoast.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:pull_to_refresh/pull_to_refresh.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; // import 'package:path_provider/path_provider.dart' as path_provider;
// TODO: APP // TODO: APP
@ -96,7 +97,7 @@ class _ChatLSPageState extends State<ChatLSPage>
// //
@override @override
void initState() { void initState() {
// print('chat_kf_page init'); // BytedeskUtils.printLog('chat_kf_page init');
SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, true); SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, true);
// //
if (widget.isThread! && widget.thread != null) { if (widget.isThread! && widget.thread != null) {
@ -113,7 +114,7 @@ class _ChatLSPageState extends State<ChatLSPage>
WidgetsBinding.instance!.addObserver(this); WidgetsBinding.instance!.addObserver(this);
// buildhttps://blog.csdn.net/baoolong/article/details/85097318 // buildhttps://blog.csdn.net/baoolong/article/details/85097318
// WidgetsBinding.instance.addPostFrameCallback((_) { // WidgetsBinding.instance.addPostFrameCallback((_) {
// print('addPostFrameCallback'); // BytedeskUtils.printLog('addPostFrameCallback');
// }); // });
_listener(); _listener();
super.initState(); super.initState();
@ -172,7 +173,7 @@ class _ChatLSPageState extends State<ChatLSPage>
// //
if (state.threadResult.statusCode == 200 || if (state.threadResult.statusCode == 200 ||
state.threadResult.statusCode == 201) { state.threadResult.statusCode == 201) {
print('创建新会话'); BytedeskUtils.printLog('创建新会话');
// //
// _messageProvider.insert(state.threadResult.msg!); // _messageProvider.insert(state.threadResult.msg!);
// TODO: pop // TODO: pop
@ -189,7 +190,7 @@ class _ChatLSPageState extends State<ChatLSPage>
widget.postscript!, _currentThread!); widget.postscript!, _currentThread!);
} }
} else if (state.threadResult.statusCode == 202) { } else if (state.threadResult.statusCode == 202) {
print('提示排队中'); BytedeskUtils.printLog('提示排队中');
// //
_messageProvider.insert(state.threadResult.msg!); _messageProvider.insert(state.threadResult.msg!);
// //
@ -208,7 +209,7 @@ class _ChatLSPageState extends State<ChatLSPage>
widget.postscript!, _currentThread!); widget.postscript!, _currentThread!);
} }
} else if (state.threadResult.statusCode == 203) { } else if (state.threadResult.statusCode == 203) {
print('当前非工作时间,请自助查询或留言'); BytedeskUtils.printLog('当前非工作时间,请自助查询或留言');
// TODO: // TODO:
setState(() { setState(() {
_currentThread = state.threadResult.msg!.thread; _currentThread = state.threadResult.msg!.thread;
@ -219,7 +220,7 @@ class _ChatLSPageState extends State<ChatLSPage>
_getMessages(_page, _size); _getMessages(_page, _size);
_appendMessage(state.threadResult.msg!); _appendMessage(state.threadResult.msg!);
} else if (state.threadResult.statusCode == 204) { } else if (state.threadResult.statusCode == 204) {
print('当前无客服在线,请自助查询或留言'); BytedeskUtils.printLog('当前无客服在线,请自助查询或留言');
// TODO: // TODO:
setState(() { setState(() {
_currentThread = state.threadResult.msg!.thread; _currentThread = state.threadResult.msg!.thread;
@ -230,7 +231,7 @@ class _ChatLSPageState extends State<ChatLSPage>
_getMessages(_page, _size); _getMessages(_page, _size);
_appendMessage(state.threadResult.msg!); _appendMessage(state.threadResult.msg!);
} else if (state.threadResult.statusCode == 205) { } else if (state.threadResult.statusCode == 205) {
print('咨询前问卷'); BytedeskUtils.printLog('咨询前问卷');
setState(() { setState(() {
_currentThread = state.threadResult.msg!.thread; _currentThread = state.threadResult.msg!.thread;
}); });
@ -241,7 +242,7 @@ class _ChatLSPageState extends State<ChatLSPage>
_appendMessage(state.threadResult.msg!); _appendMessage(state.threadResult.msg!);
// //
} else if (state.threadResult.statusCode == 206) { } else if (state.threadResult.statusCode == 206) {
print('返回机器人初始欢迎语 + 欢迎问题列表'); BytedeskUtils.printLog('返回机器人初始欢迎语 + 欢迎问题列表');
// TODO: // TODO:
setState(() { setState(() {
_isRobot = true; _isRobot = true;
@ -276,9 +277,10 @@ class _ChatLSPageState extends State<ChatLSPage>
), ),
BlocListener<MessageBloc, MessageState>( BlocListener<MessageBloc, MessageState>(
listener: (context, state) { listener: (context, state) {
print('message state change'); BytedeskUtils.printLog('message state change');
if (state is ReceiveMessageState) { if (state is ReceiveMessageState) {
print('receive message:' + state.message!.content!); BytedeskUtils.printLog(
'receive message:' + state.message!.content!);
} else if (state is UploadImageSuccess) { } else if (state is UploadImageSuccess) {
_bdMqtt.sendImageMessage( _bdMqtt.sendImageMessage(
state.uploadJsonResult.url!, _currentThread!); state.uploadJsonResult.url!, _currentThread!);
@ -345,7 +347,7 @@ class _ChatLSPageState extends State<ChatLSPage>
child: SmartRefresher( child: SmartRefresher(
enablePullDown: false, enablePullDown: false,
onLoading: () async { onLoading: () async {
print('TODO: 下拉刷新'); // BytedeskUtils.printLog('TODO: 下拉刷新'); //
// await Future.delayed(Duration(milliseconds: 1000)); // await Future.delayed(Duration(milliseconds: 1000));
_getMessages(_page, _size); _getMessages(_page, _size);
setState(() {}); setState(() {});
@ -427,7 +429,7 @@ class _ChatLSPageState extends State<ChatLSPage>
if (_debounce?.isActive ?? false) _debounce!.cancel(); if (_debounce?.isActive ?? false) _debounce!.cancel();
// 500 // 500
_debounce = Timer(const Duration(milliseconds: 500), () { _debounce = Timer(const Duration(milliseconds: 500), () {
print('send preview $value'); BytedeskUtils.printLog('send preview $value');
// value != null && // value != null &&
if (value.trim().length > 0) { if (value.trim().length > 0) {
_bdMqtt.sendPreviewMessage(value, _currentThread!); _bdMqtt.sendPreviewMessage(value, _currentThread!);
@ -486,7 +488,7 @@ class _ChatLSPageState extends State<ChatLSPage>
_listener() { _listener() {
// //
bytedeskEventBus.on<ReceiveMessageReceiptEventBus>().listen((event) { bytedeskEventBus.on<ReceiveMessageReceiptEventBus>().listen((event) {
// print('更新状态:' + event.status); // BytedeskUtils.printLog('更新状态:' + event.status);
if (!this.mounted) { if (!this.mounted) {
return; return;
} }
@ -503,7 +505,7 @@ class _ChatLSPageState extends State<ChatLSPage>
} }
}); });
bytedeskEventBus.on<ReceiveMessagePreviewEventBus>().listen((event) { bytedeskEventBus.on<ReceiveMessagePreviewEventBus>().listen((event) {
// print('消息预知'); // BytedeskUtils.printLog('消息预知');
if (this.mounted) { if (this.mounted) {
setState(() { setState(() {
// TODO: // TODO:
@ -514,7 +516,7 @@ class _ChatLSPageState extends State<ChatLSPage>
Timer( Timer(
Duration(seconds: 3), Duration(seconds: 3),
() { () {
// print('timer'); // BytedeskUtils.printLog('timer');
if (this.mounted) { if (this.mounted) {
setState(() { setState(() {
_title = widget.title; _title = widget.title;
@ -525,11 +527,11 @@ class _ChatLSPageState extends State<ChatLSPage>
}); });
// DeleteMessageEventBus // DeleteMessageEventBus
// bytedeskEventBus.on<ReceiveMessageRecallEventBus>().listen((event) { // bytedeskEventBus.on<ReceiveMessageRecallEventBus>().listen((event) {
// print('消息撤回'); // BytedeskUtils.printLog('消息撤回');
// }); // });
// //
bytedeskEventBus.on<ReceiveMessageEventBus>().listen((event) { bytedeskEventBus.on<ReceiveMessageEventBus>().listen((event) {
// print('receive message:' + event.message!.content); // BytedeskUtils.printLog('receive message:' + event.message!.content);
if (_currentThread != null && if (_currentThread != null &&
(event.message.thread!.topic != _currentThread!.topic)) { (event.message.thread!.topic != _currentThread!.topic)) {
return; return;
@ -568,7 +570,7 @@ class _ChatLSPageState extends State<ChatLSPage>
bytedeskEventBus.on<QueryAnswerEventBus>().listen((event) { bytedeskEventBus.on<QueryAnswerEventBus>().listen((event) {
// //
if (this.mounted) { if (this.mounted) {
print( BytedeskUtils.printLog(
'aid ${event.aid}, question ${event.question}, answer ${event.answer}'); 'aid ${event.aid}, question ${event.question}, answer ${event.answer}');
// //
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
@ -585,7 +587,7 @@ class _ChatLSPageState extends State<ChatLSPage>
// //
// if (_scrollController.position.pixels == // if (_scrollController.position.pixels ==
// _scrollController.position.maxScrollExtent) { // _scrollController.position.maxScrollExtent) {
// print('已经到底了'); // BytedeskUtils.printLog('已经到底了');
// } // }
}); });
} }
@ -597,7 +599,7 @@ class _ChatLSPageState extends State<ChatLSPage>
source: ImageSource.gallery, maxWidth: 800, imageQuality: 95); source: ImageSource.gallery, maxWidth: 800, imageQuality: 95);
// //
if (pickedFile != null) { if (pickedFile != null) {
print('pick image path: ${pickedFile.path}'); BytedeskUtils.printLog('pick image path: ${pickedFile.path}');
// TODO: // TODO:
// TODO: loading // TODO: loading
// //
@ -606,7 +608,7 @@ class _ChatLSPageState extends State<ChatLSPage>
// "/" + // "/" +
// BytedeskUtils.currentTimeMillis().toString() + // BytedeskUtils.currentTimeMillis().toString() +
// ".jpg"; // ".jpg";
// print('targetPath: $targetPath'); // BytedeskUtils.printLog('targetPath: $targetPath');
// await BytedeskUtils.compressImage(File(pickedFile.path), targetPath); // await BytedeskUtils.compressImage(File(pickedFile.path), targetPath);
// // // //
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
@ -618,7 +620,7 @@ class _ChatLSPageState extends State<ChatLSPage>
Fluttertoast.showToast(msg: '未选取图片'); Fluttertoast.showToast(msg: '未选取图片');
} }
} catch (e) { } catch (e) {
print('pick image error ${e.toString()}'); BytedeskUtils.printLog('pick image error ${e.toString()}');
Fluttertoast.showToast(msg: "未选取图片"); Fluttertoast.showToast(msg: "未选取图片");
} }
} }
@ -630,7 +632,7 @@ class _ChatLSPageState extends State<ChatLSPage>
source: ImageSource.camera, maxWidth: 800, imageQuality: 95); source: ImageSource.camera, maxWidth: 800, imageQuality: 95);
// //
if (pickedFile != null) { if (pickedFile != null) {
print('take image path: ${pickedFile.path}'); BytedeskUtils.printLog('take image path: ${pickedFile.path}');
// TODO: // TODO:
// TODO: loading // TODO: loading
// //
@ -639,7 +641,7 @@ class _ChatLSPageState extends State<ChatLSPage>
// "/" + // "/" +
// BytedeskUtils.currentTimeMillis().toString() + // BytedeskUtils.currentTimeMillis().toString() +
// ".jpg"; // ".jpg";
// print('targetPath: $targetPath'); // BytedeskUtils.printLog('targetPath: $targetPath');
// await BytedeskUtils.compressImage(File(pickedFile.path), targetPath); // await BytedeskUtils.compressImage(File(pickedFile.path), targetPath);
// // // //
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
@ -651,7 +653,7 @@ class _ChatLSPageState extends State<ChatLSPage>
Fluttertoast.showToast(msg: '未拍照'); Fluttertoast.showToast(msg: '未拍照');
} }
} catch (e) { } catch (e) {
print('take image error ${e.toString()}'); BytedeskUtils.printLog('take image error ${e.toString()}');
Fluttertoast.showToast(msg: "未选取图片"); Fluttertoast.showToast(msg: "未选取图片");
} }
} }
@ -663,7 +665,7 @@ class _ChatLSPageState extends State<ChatLSPage>
try { try {
// final PickedFile videoFile = await _picker.getVideo( // final PickedFile videoFile = await _picker.getVideo(
// source: ImageSource.gallery, maxDuration: const Duration(seconds: 10)); // source: ImageSource.gallery, maxDuration: const Duration(seconds: 10));
// print('pick video path: ${videoFile.path}'); // BytedeskUtils.printLog('pick video path: ${videoFile.path}');
// if (videoFile != null) { // if (videoFile != null) {
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
// ..add(UploadVideoEvent(filePath: videoFile.path)); // ..add(UploadVideoEvent(filePath: videoFile.path));
@ -687,9 +689,9 @@ class _ChatLSPageState extends State<ChatLSPage>
// VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality)
// deleteOrigin: false, // default(false) // deleteOrigin: false, // default(false)
// ); // );
// // debugPrint(info.toJson().toString()); // // debugBytedeskUtils.printLog(info.toJson().toString());
// String? afterPath = info.toJson()['path']; // 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<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
// ..add(UploadVideoEvent(filePath: afterPath)); // ..add(UploadVideoEvent(filePath: afterPath));
@ -698,7 +700,7 @@ class _ChatLSPageState extends State<ChatLSPage>
..add(UploadVideoEvent(filePath: _paths[0].path)); ..add(UploadVideoEvent(filePath: _paths[0].path));
} }
} catch (e) { } catch (e) {
print('pick video error ${e.toString()}'); BytedeskUtils.printLog('pick video error ${e.toString()}');
Fluttertoast.showToast(msg: "未选取视频"); Fluttertoast.showToast(msg: "未选取视频");
} }
} }
@ -710,7 +712,7 @@ class _ChatLSPageState extends State<ChatLSPage>
source: ImageSource.camera, maxDuration: const Duration(seconds: 10)); source: ImageSource.camera, maxDuration: const Duration(seconds: 10));
// //
if (pickedFile != null) { if (pickedFile != null) {
print('take video path: ${pickedFile.path}'); BytedeskUtils.printLog('take video path: ${pickedFile.path}');
// TODO: // TODO:
// TODO: loading // TODO: loading
// //
@ -720,9 +722,9 @@ class _ChatLSPageState extends State<ChatLSPage>
// VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality) // VideoQuality.LowQuality, // default(VideoQuality.DefaultQuality)
// deleteOrigin: false, // default(false) // deleteOrigin: false, // default(false)
// ); // );
// // debugPrint(info.toJson().toString()); // // debugBytedeskUtils.printLog(info.toJson().toString());
// String? afterPath = info.toJson()['path']; // String? afterPath = info.toJson()['path'];
// // print('video path: ${pickedFile.path}, compress path: $afterPath'); // // BytedeskUtils.printLog('video path: ${pickedFile.path}, compress path: $afterPath');
// // // //
// BlocProvider.of<MessageBloc>(context) // BlocProvider.of<MessageBloc>(context)
// ..add(UploadVideoEvent(filePath: afterPath)); // ..add(UploadVideoEvent(filePath: afterPath));
@ -733,14 +735,14 @@ class _ChatLSPageState extends State<ChatLSPage>
Fluttertoast.showToast(msg: '未录制视频'); Fluttertoast.showToast(msg: '未录制视频');
} }
} catch (e) { } catch (e) {
print('take video error ${e.toString()}'); BytedeskUtils.printLog('take video error ${e.toString()}');
Fluttertoast.showToast(msg: "未录制视频"); Fluttertoast.showToast(msg: "未录制视频");
} }
} }
// //
// Future<void> _loadMoreMessages() async { // Future<void> _loadMoreMessages() async {
// print('load more'); // BytedeskUtils.printLog('load more');
// // TODO: // // TODO:
// _getMessages(_page, _size); // _getMessages(_page, _size);
// } // }
@ -769,7 +771,7 @@ class _ChatLSPageState extends State<ChatLSPage>
} }
Future<Null> _appendMessage(Message message) async { Future<Null> _appendMessage(Message message) async {
// print('append:' + message!.mid); // BytedeskUtils.printLog('append:' + message!.mid);
_messageProvider.insert(message); _messageProvider.insert(message);
MessageWidget messageWidget = new MessageWidget( MessageWidget messageWidget = new MessageWidget(
message: message, message: message,
@ -798,7 +800,7 @@ class _ChatLSPageState extends State<ChatLSPage>
@override @override
void didChangeAppLifecycleState(AppLifecycleState state) { void didChangeAppLifecycleState(AppLifecycleState state) {
// print("didChangeAppLifecycleState:" + state.toString()); // BytedeskUtils.printLog("didChangeAppLifecycleState:" + state.toString());
switch (state) { switch (state) {
case AppLifecycleState.inactive: // case AppLifecycleState.inactive: //
break; break;
@ -816,7 +818,7 @@ class _ChatLSPageState extends State<ChatLSPage>
@override @override
void dispose() { void dispose() {
// print('chat_kf_page dispose'); // BytedeskUtils.printLog('chat_kf_page dispose');
SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, false); SpUtil.putBool(BytedeskConstants.isCurrentChatKfPage, false);
WidgetsBinding.instance!.removeObserver(this); WidgetsBinding.instance!.removeObserver(this);
_debounce?.cancel(); _debounce?.cancel();

@ -51,7 +51,7 @@ class _ChatWebViewPageState extends State<ChatWebViewPage> {
// padding: new EdgeInsets.only(right: 10), // padding: new EdgeInsets.only(right: 10),
// child: InkWell( // child: InkWell(
// onTap: () { // onTap: () {
// print('share'); // BytedeskUtils.printLog('share');
// // showShareSheet(context); // // showShareSheet(context);
// }, // },
// child: Image.asset( // child: Image.asset(
@ -120,7 +120,7 @@ class _ChatWebViewPageState extends State<ChatWebViewPage> {
// ); // );
// }).then((value) { // }).then((value) {
// // // //
// print('share $value'); // BytedeskUtils.printLog('share $value');
// if (value == 'wechat') { // if (value == 'wechat') {
// // TODO: // // TODO:
// } else if (value == 'weibo') { // } else if (value == 'weibo') {

@ -13,6 +13,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart'; import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter_html/flutter_html.dart'; import 'package:flutter_html/flutter_html.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
// //
class MessageWidget extends StatelessWidget { class MessageWidget extends StatelessWidget {
@ -124,7 +125,7 @@ class MessageWidget extends StatelessWidget {
]; ];
}, },
onSelected: (value) { onSelected: (value) {
print('send menu $value'); BytedeskUtils.printLog('send menu $value');
// //
if (value == 'copy') { if (value == 'copy') {
/// ///
@ -150,7 +151,7 @@ class MessageWidget extends StatelessWidget {
} }
}, },
onCancelled: () { onCancelled: () {
// print('cancel'); // BytedeskUtils.printLog('cancel');
}, },
); );
} }
@ -212,11 +213,11 @@ class MessageWidget extends StatelessWidget {
String imageUrl = commodityJson['imageUrl'].toString(); String imageUrl = commodityJson['imageUrl'].toString();
return InkWell( return InkWell(
onTap: () { onTap: () {
// print('message!.type ${message!.type}, message!.content ${message!.content}'); // BytedeskUtils.printLog('message!.type ${message!.type}, message!.content ${message!.content}');
if (customCallback != null) { if (customCallback != null) {
customCallback!(message.content!); customCallback!(message.content!);
} else { } else {
print('customCallback is null'); BytedeskUtils.printLog('customCallback is null');
} }
}, },
child: Row( child: Row(
@ -271,7 +272,7 @@ class MessageWidget extends StatelessWidget {
} else if (message.type == BytedeskConstants.MESSAGE_TYPE_VIDEO) { } else if (message.type == BytedeskConstants.MESSAGE_TYPE_VIDEO) {
return InkWell( return InkWell(
onTap: () { onTap: () {
print('play video'); BytedeskUtils.printLog('play video');
Navigator.of(context).push(new MaterialPageRoute(builder: (context) { Navigator.of(context).push(new MaterialPageRoute(builder: (context) {
return new VideoPlayPage(videoUrl: message.videoUrl); return new VideoPlayPage(videoUrl: message.videoUrl);
})); }));
@ -365,7 +366,7 @@ class MessageWidget extends StatelessWidget {
]; ];
}, },
onSelected: (value) { onSelected: (value) {
print('send menu $value'); BytedeskUtils.printLog('send menu $value');
// //
if (value == 'copy') { if (value == 'copy') {
/// ///
@ -389,7 +390,7 @@ class MessageWidget extends StatelessWidget {
} }
}, },
onCancelled: () { onCancelled: () {
// print('cancel'); // BytedeskUtils.printLog('cancel');
}, },
); );
} }
@ -464,7 +465,7 @@ class MessageWidget extends StatelessWidget {
}, },
onImageTap: (src, _, __, ___) { onImageTap: (src, _, __, ___) {
// //
// print("open image $src"); // BytedeskUtils.printLog("open image $src");
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
@ -491,7 +492,7 @@ class MessageWidget extends StatelessWidget {
); );
}, },
onImageError: (exception, stackTrace) { onImageError: (exception, stackTrace) {
print(exception); BytedeskUtils.printLog(exception);
}, },
), ),
), ),
@ -526,7 +527,7 @@ class MessageWidget extends StatelessWidget {
style: TextStyle(color: Colors.blue), style: TextStyle(color: Colors.blue),
), ),
onTap: () => { onTap: () => {
// print('object:' + answer.question), // BytedeskUtils.printLog('object:' + answer.question),
bytedeskEventBus.fire(QueryAnswerEventBus( bytedeskEventBus.fire(QueryAnswerEventBus(
answer.aid!, answer.aid!,
answer.question!, answer.question!,
@ -547,7 +548,7 @@ class MessageWidget extends StatelessWidget {
style: TextStyle(color: Theme.of(context).primaryColor), style: TextStyle(color: Theme.of(context).primaryColor),
), ),
onTap: () { onTap: () {
print('请求人工客服'); BytedeskUtils.printLog('请求人工客服');
bytedeskEventBus.fire(RequestAgentThreadEventBus()); bytedeskEventBus.fire(RequestAgentThreadEventBus());
}, },
) )
@ -601,7 +602,7 @@ class MessageWidget extends StatelessWidget {
style: TextStyle(color: Colors.blue), style: TextStyle(color: Colors.blue),
), ),
onTap: () => { onTap: () => {
// print(category.name), // BytedeskUtils.printLog(category.name),
bytedeskEventBus.fire(QueryCategoryEventBus( bytedeskEventBus.fire(QueryCategoryEventBus(
category.cid!, category.name!)) category.cid!, category.name!))
}), }),
@ -620,7 +621,7 @@ class MessageWidget extends StatelessWidget {
style: TextStyle(color: Theme.of(context).primaryColor), style: TextStyle(color: Theme.of(context).primaryColor),
), ),
onTap: () { onTap: () {
print('请求人工客服'); BytedeskUtils.printLog('请求人工客服');
bytedeskEventBus.fire(RequestAgentThreadEventBus()); bytedeskEventBus.fire(RequestAgentThreadEventBus());
}, },
) )
@ -648,11 +649,11 @@ class MessageWidget extends StatelessWidget {
String imageUrl = commodityJson['imageUrl'].toString(); String imageUrl = commodityJson['imageUrl'].toString();
return InkWell( return InkWell(
onTap: () { onTap: () {
// print('message!.type ${message!.type}, message!.content ${message!.content}'); // BytedeskUtils.printLog('message!.type ${message!.type}, message!.content ${message!.content}');
if (customCallback != null) { if (customCallback != null) {
customCallback!(message.content!); customCallback!(message.content!);
} else { } else {
print('customCallback is null'); BytedeskUtils.printLog('customCallback is null');
} }
}, },
child: Row( child: Row(
@ -707,7 +708,7 @@ class MessageWidget extends StatelessWidget {
} else if (message.type == BytedeskConstants.MESSAGE_TYPE_VIDEO) { } else if (message.type == BytedeskConstants.MESSAGE_TYPE_VIDEO) {
return InkWell( return InkWell(
onTap: () { onTap: () {
print('play video'); BytedeskUtils.printLog('play video');
Navigator.of(context).push(new MaterialPageRoute(builder: (context) { Navigator.of(context).push(new MaterialPageRoute(builder: (context) {
return new VideoPlayPage(videoUrl: message.videoUrl); return new VideoPlayPage(videoUrl: message.videoUrl);
})); }));

@ -7,6 +7,7 @@ import 'package:bytedesk_kefu/ui/widget/loading_widget.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
// import 'package:flutter_easyrefresh/phoenix_header.dart'; // import 'package:flutter_easyrefresh/phoenix_header.dart';
class HelpArticleListPage extends StatefulWidget { class HelpArticleListPage extends StatefulWidget {
@ -44,7 +45,7 @@ class _HelpArticleListPageState extends State<HelpArticleListPage>
body: BlocConsumer<HelpBloc, HelpState>(listener: (context, state) { body: BlocConsumer<HelpBloc, HelpState>(listener: (context, state) {
// do stuff here based on BlocA's state // do stuff here based on BlocA's state
if (state is HelpArticleState) { if (state is HelpArticleState) {
print('help article load success length: ' + BytedeskUtils.printLog('help article load success length: ' +
state.articleList.length.toString()); state.articleList.length.toString());
if (state.articleList.length == 0) { if (state.articleList.length == 0) {
// Toast.show('没有更多了哦'); // Toast.show('没有更多了哦');

@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart';
// import 'package:flutter_easyrefresh/phoenix_header.dart'; // import 'package:flutter_easyrefresh/phoenix_header.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
class HelpPage extends StatefulWidget { class HelpPage extends StatefulWidget {
final String? uid; final String? uid;
@ -43,7 +44,7 @@ class _HelpPageState extends State<HelpPage>
body: BlocConsumer<HelpBloc, HelpState>(listener: (context, state) { body: BlocConsumer<HelpBloc, HelpState>(listener: (context, state) {
// do stuff here based on BlocA's state // do stuff here based on BlocA's state
if (state is HelpCategoryState) { if (state is HelpCategoryState) {
print('help category load success length: ' + BytedeskUtils.printLog('help category load success length: ' +
state.categoryList.length.toString()); state.categoryList.length.toString());
if (state.categoryList.length == 0) { if (state.categoryList.length == 0) {
// Toast.show('没有更多了哦'); // Toast.show('没有更多了哦');

@ -6,6 +6,7 @@ import 'package:bytedesk_kefu/ui/widget/loading_widget.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
// import 'package:flutter_easyrefresh/phoenix_header.dart'; // import 'package:flutter_easyrefresh/phoenix_header.dart';
class FeedbackPage extends StatefulWidget { class FeedbackPage extends StatefulWidget {
@ -47,7 +48,7 @@ class _FeedbackPageState extends State<FeedbackPage>
BlocConsumer<FeedbackBloc, FeedbackState>(listener: (context, state) { BlocConsumer<FeedbackBloc, FeedbackState>(listener: (context, state) {
// do stuff here based on BlocA's state // do stuff here based on BlocA's state
if (state is FeedbackCategoryState) { if (state is FeedbackCategoryState) {
print('help category load success length: ' + BytedeskUtils.printLog('help category load success length: ' +
state.categoryList.length.toString()); state.categoryList.length.toString());
if (state.categoryList.length == 0) { if (state.categoryList.length == 0) {
// Toast.show('没有更多了哦'); // Toast.show('没有更多了哦');

@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttertoast/fluttertoast.dart'; import 'package:fluttertoast/fluttertoast.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:bytedesk_kefu/util/bytedesk_utils.dart';
class FeedbackSubmitPage extends StatefulWidget { class FeedbackSubmitPage extends StatefulWidget {
final HelpCategory? helpCategory; final HelpCategory? helpCategory;
@ -35,7 +36,7 @@ class _FeedbackSubmitPageState extends State<FeedbackSubmitPage> {
// //
if (_scrollController.position.pixels == if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) { _scrollController.position.maxScrollExtent) {
// print('scroll to bottom'); // BytedeskUtils.printLog('scroll to bottom');
} }
}); });
super.initState(); super.initState();
@ -44,7 +45,7 @@ class _FeedbackSubmitPageState extends State<FeedbackSubmitPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// //
print('fileList的内容: $_fileList'); BytedeskUtils.printLog('fileList的内容: $_fileList');
if (_selectedImageFile != null) { if (_selectedImageFile != null) {
_fileList.add(_selectedImageFile!); _fileList.add(_selectedImageFile!);
} }
@ -62,7 +63,7 @@ class _FeedbackSubmitPageState extends State<FeedbackSubmitPage> {
margin: EdgeInsets.only(right: 10), margin: EdgeInsets.only(right: 10),
child: InkWell( child: InkWell(
onTap: () { onTap: () {
print('submit'); BytedeskUtils.printLog('submit');
// TODO: // TODO:
BlocProvider.of<FeedbackBloc>(context) BlocProvider.of<FeedbackBloc>(context)
..add(SubmitFeedbackEvent( ..add(SubmitFeedbackEvent(
@ -222,7 +223,7 @@ class _FeedbackSubmitPageState extends State<FeedbackSubmitPage> {
try { try {
XFile? pickedFile = await picker.pickImage( XFile? pickedFile = await picker.pickImage(
source: ImageSource.gallery, maxWidth: 800, imageQuality: 95); source: ImageSource.gallery, maxWidth: 800, imageQuality: 95);
print('pick image path: ${pickedFile!.path}'); BytedeskUtils.printLog('pick image path: ${pickedFile!.path}');
setState(() { setState(() {
_selectedImageFile = File(pickedFile.path); _selectedImageFile = File(pickedFile.path);
}); });
@ -230,7 +231,7 @@ class _FeedbackSubmitPageState extends State<FeedbackSubmitPage> {
BlocProvider.of<FeedbackBloc>(context) BlocProvider.of<FeedbackBloc>(context)
..add(UploadImageEvent(filePath: pickedFile.path)); ..add(UploadImageEvent(filePath: pickedFile.path));
} catch (e) { } catch (e) {
print('pick image error ${e.toString()}'); BytedeskUtils.printLog('pick image error ${e.toString()}');
Fluttertoast.showToast(msg: "未选取图片"); Fluttertoast.showToast(msg: "未选取图片");
} }
} }
@ -244,7 +245,7 @@ class _FeedbackSubmitPageState extends State<FeedbackSubmitPage> {
try { try {
XFile? pickedFile = await picker.pickImage( XFile? pickedFile = await picker.pickImage(
source: ImageSource.camera, maxWidth: 800, imageQuality: 95); source: ImageSource.camera, maxWidth: 800, imageQuality: 95);
print('take image path: ${pickedFile!.path}'); BytedeskUtils.printLog('take image path: ${pickedFile!.path}');
setState(() { setState(() {
_selectedImageFile = File(pickedFile.path); _selectedImageFile = File(pickedFile.path);
}); });
@ -252,7 +253,7 @@ class _FeedbackSubmitPageState extends State<FeedbackSubmitPage> {
BlocProvider.of<FeedbackBloc>(context) BlocProvider.of<FeedbackBloc>(context)
..add(UploadImageEvent(filePath: pickedFile.path)); ..add(UploadImageEvent(filePath: pickedFile.path));
} catch (e) { } catch (e) {
print('take image error ${e.toString()}'); BytedeskUtils.printLog('take image error ${e.toString()}');
Fluttertoast.showToast(msg: "未选取图片"); Fluttertoast.showToast(msg: "未选取图片");
} }
} }
@ -270,7 +271,7 @@ class _FeedbackSubmitPageState extends State<FeedbackSubmitPage> {
// ImagePicker.pickImage(source: source).then((result) { // ImagePicker.pickImage(source: source).then((result) {
// setState(() { // setState(() {
// _selectedImageFile = result; // _selectedImageFile = result;
// print("执行刷新:"); // BytedeskUtils.printLog("执行刷新:");
// }); // });
// }); // });
// }, // },

@ -52,7 +52,7 @@ class _LeaveMsgPageState extends State<LeaveMsgPage> {
// //
if (_scrollController.position.pixels == if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) { _scrollController.position.maxScrollExtent) {
// print('scroll to bottom'); // BytedeskUtils.printLog('scroll to bottom');
} }
}); });
super.initState(); super.initState();
@ -61,7 +61,7 @@ class _LeaveMsgPageState extends State<LeaveMsgPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// //
// print('fileList的内容: $_fileList'); // BytedeskUtils.printLog('fileList的内容: $_fileList');
// if (_selectedImageFile != null) { // if (_selectedImageFile != null) {
// _fileList.add(_selectedImageFile!); // _fileList.add(_selectedImageFile!);
// } // }
@ -282,7 +282,7 @@ class _LeaveMsgPageState extends State<LeaveMsgPage> {
// try { // try {
// XFile? pickedFile = await picker.pickImage( // XFile? pickedFile = await picker.pickImage(
// source: ImageSource.gallery, maxWidth: 800, imageQuality: 95); // source: ImageSource.gallery, maxWidth: 800, imageQuality: 95);
// print('pick image path: ${pickedFile!.path}'); // BytedeskUtils.printLog('pick image path: ${pickedFile!.path}');
// setState(() { // setState(() {
// _selectedImageFile = File(pickedFile.path); // _selectedImageFile = File(pickedFile.path);
// }); // });
@ -290,7 +290,7 @@ class _LeaveMsgPageState extends State<LeaveMsgPage> {
// BlocProvider.of<LeaveMsgBloc>(context) // BlocProvider.of<LeaveMsgBloc>(context)
// ..add(UploadImageEvent(filePath: pickedFile.path)); // ..add(UploadImageEvent(filePath: pickedFile.path));
// } catch (e) { // } catch (e) {
// print('pick image error ${e.toString()}'); // BytedeskUtils.printLog('pick image error ${e.toString()}');
// Fluttertoast.showToast(msg: "未选取图片"); // Fluttertoast.showToast(msg: "未选取图片");
// } // }
// } // }
@ -304,7 +304,7 @@ class _LeaveMsgPageState extends State<LeaveMsgPage> {
// try { // try {
// XFile? pickedFile = await picker.pickImage( // XFile? pickedFile = await picker.pickImage(
// source: ImageSource.camera, maxWidth: 800, imageQuality: 95); // source: ImageSource.camera, maxWidth: 800, imageQuality: 95);
// print('take image path: ${pickedFile!.path}'); // BytedeskUtils.printLog('take image path: ${pickedFile!.path}');
// setState(() { // setState(() {
// _selectedImageFile = File(pickedFile.path); // _selectedImageFile = File(pickedFile.path);
// }); // });
@ -312,7 +312,7 @@ class _LeaveMsgPageState extends State<LeaveMsgPage> {
// BlocProvider.of<LeaveMsgBloc>(context) // BlocProvider.of<LeaveMsgBloc>(context)
// ..add(UploadImageEvent(filePath: pickedFile.path)); // ..add(UploadImageEvent(filePath: pickedFile.path));
// } catch (e) { // } catch (e) {
// print('take image error ${e.toString()}'); // BytedeskUtils.printLog('take image error ${e.toString()}');
// Fluttertoast.showToast(msg: "未选取图片"); // Fluttertoast.showToast(msg: "未选取图片");
// } // }
// } // }

@ -61,7 +61,7 @@ class PhotoViewWrapper extends StatelessWidget {
// color: Colors.pink, // color: Colors.pink,
child: InkWell( child: InkWell(
onTap: () { onTap: () {
print('imageurl: $imageUrl'); BytedeskUtils.printLog('imageurl: $imageUrl');
BytedeskUtils.saveImage(imageUrl!); BytedeskUtils.saveImage(imageUrl!);
}, },
child: Text( child: Text(

@ -18,7 +18,7 @@ class BytedeskConstants {
// static const String httpUploadUrl = 'http://' + mqttHost + ':8000'; // static const String httpUploadUrl = 'http://' + mqttHost + ':8000';
// static const String host = mqttHost + ':8000'; // static const String host = mqttHost + ':8000';
// static const int mqttPort = 3883; // not secure // 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; // static const bool isDebug = true;
@ -30,8 +30,8 @@ class BytedeskConstants {
// static const String httpBaseUrlAndroid = 'http://' + mqttHost + ':8000'; // static const String httpBaseUrlAndroid = 'http://' + mqttHost + ':8000';
// static const String httpBaseUrliOS = 'http://' + mqttHost + ':8000'; // static const String httpBaseUrliOS = 'http://' + mqttHost + ':8000';
// static const String httpUploadUrl = '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 host = mqttHost + ':8000';
// static const String mqttHost = '127.0.0.1';
// static const String mqttHost = '10.0.2.2'; // // static const String mqttHost = '10.0.2.2'; //
// //
@ -45,7 +45,7 @@ class BytedeskConstants {
// static const String httpBaseUrliOS = 'http://' + mqttHost + ':8000'; // static const String httpBaseUrliOS = 'http://' + mqttHost + ':8000';
// static const String httpUploadUrl = 'http://' + mqttHost + ':8000'; // static const String httpUploadUrl = 'http://' + mqttHost + ':8000';
// static const String host = 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; static const bool isDebug = false; // false;

@ -39,6 +39,12 @@ class BytedeskUtils {
static bool get isFuchsia => Platform.isFuchsia; static bool get isFuchsia => Platform.isFuchsia;
static bool get isIOS => Platform.isIOS; static bool get isIOS => Platform.isIOS;
static void printLog(content) {
if (BytedeskConstants.isDebug) {
print(content);
}
}
static String client() { static String client() {
if (isWeb) { if (isWeb) {
return 'flutter_web'; return 'flutter_web';
@ -235,7 +241,7 @@ class BytedeskUtils {
// https://pub.dev/packages/flutter_image_compress // https://pub.dev/packages/flutter_image_compress
// static Future<File> compressImage(File file, String targetPath) async { // static Future<File> compressImage(File file, String targetPath) async {
// // print("compressImage"); // // BytedeskUtils.printLog("compressImage");
// final result = await FlutterImageCompress.compressAndGetFile( // final result = await FlutterImageCompress.compressAndGetFile(
// file.absolute.path, // file.absolute.path,
// targetPath, // targetPath,
@ -307,7 +313,7 @@ class BytedeskUtils {
} }
static Future<bool> requestPermission() async { static Future<bool> requestPermission() async {
print('请求定位'); BytedeskUtils.printLog('请求定位');
return true; return true;
// FIXME: // FIXME:
// if (await Permission.location.request().isGranted) { // if (await Permission.location.request().isGranted) {
@ -402,9 +408,9 @@ class BytedeskUtils {
if (result == null || result == '') throw '图片保存失败'; if (result == null || result == '') throw '图片保存失败';
// //
Fluttertoast.showToast(msg: "保存成功"); Fluttertoast.showToast(msg: "保存成功");
print("保存成功"); BytedeskUtils.printLog("保存成功");
} catch (e) { } catch (e) {
print(e.toString()); BytedeskUtils.printLog(e.toString());
} }
} }

@ -1,6 +1,6 @@
name: bytedesk_kefu 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. 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 homepage: https://www.weikefu.net
environment: environment:
@ -49,7 +49,6 @@ dependencies:
# https://pub.dev/packages/flutter_easyloading # https://pub.dev/packages/flutter_easyloading
flutter_easyloading: ^3.0.3 flutter_easyloading: ^3.0.3
# H5-webchat https://pub.dev/packages/webview_flutter # H5-webchat https://pub.dev/packages/webview_flutter
# webview_flutter: ^3.0.2
webview_flutter: ^2.0.4 webview_flutter: ^2.0.4
# https://pub.dev/packages/device_info # https://pub.dev/packages/device_info
device_info: ^2.0.3 device_info: ^2.0.3

Loading…
Cancel
Save