hello
i using cloud99 plan
but massages are sending after some delay
is this plan bug or my fault?
if this bug is for free paln،i want to by an account for my app
Can you please share more details? I’ve noticed you use Flutter SDK. Can you share your code and tell us what do you mean by “delay”?
Best Regards,
Maksym
Future onMessageSubmitted(String message) async {
Backendless.messaging.publish(message, channelName: channelName, publishOptions: PublishOptions()..headers = {"sender": widget.userId.toString(), "receiver": widget.contactId.toString()});
myController.clear();
await insertDataToChatHistory(message, int.parse(widget.userId.toString()), widget.userName, widget.userAvatarImage, int.parse(widget.contactId.toString()), widget.contactName, widget.contactAvatarImage, 0, 0);
}
Future onMessageReceived(PublishMessageInfo messageInfo) async {
try {
if (messageInfo.headers['receiver'] == widget.userId.toString() || messageInfo.headers['sender'] == widget.userId.toString()) {
if (Configs.isDebugMode)
print(messageInfo.message.toString() + ' from ' + messageInfo.headers['sender'] + ' to ' + messageInfo.headers['receiver']);
int id = int.parse(messageInfo.headers['sender']);
bool isFromMe = messageInfo.headers['receiver'] != widget.userId.toString();
ChatMessage message = new ChatMessage(messageInfo.message, isFromMe);
setState(() => _chatHistoryItems.insert(0, message));
senderId = id;
}
}catch(e){
log.Logger.log(CLASS_NAME, "onMessageReceived", e.toString());
}
}
getHistoryItems(int ofst) {
setState(() => showProgress = true );
try{
//final DataQueryBuilder queryBuilderCount = DataQueryBuilder()..whereClause = "group_id = ${widget.groupId} "..properties = ["Count(id) as totalCount"];
DataQueryBuilder queryBuilderCount = DataQueryBuilder()..whereClause = "(contact_id = $subscriberId OR contact_id = ${ widget.contactId} OR contact_id = ${widget.userId})" +
" AND (user_id = $subscriberId OR user_id = ${widget.contactId} OR user_id = ${widget.userId} )"..properties = ["Count(id) as totalCount"];
chatTableDataStore.find(queryBuilderCount).then((data) {
totalRows = data[0]['totalCount'];
//print('totalRows : ' + totalRows.toString());
});
DataQueryBuilder queryBuilder = DataQueryBuilder()..whereClause = "(contact_id = $subscriberId OR contact_id = ${ widget.contactId} OR contact_id = ${widget.userId})" +
" AND (user_id = $subscriberId OR user_id = ${widget.contactId} OR user_id = ${widget.userId} )"..sortBy = ['created DESC']..pageSize =100 ..offset = ofst;
chatTableDataStore.find(queryBuilder).then((mapList) {
if (mapList != null && mapList.length > 0){
for (int i = 0; i < mapList.length; i++) {
bool isFromMe = mapList[i]['user_id'] == widget.userId ? true : false;
_chatHistoryItems.add(new ChatMessage(mapList[i]['message'], isFromMe));
}
}
setState((){showProgress = false; _chatHistoryItems;});
});
} on SocketException catch (e1) {
log.Logger.log(CLASS_NAME, "getHistoryItems", e1.toString());
setState(() => showProgress = false );
} on FormatException catch (e2) {
log.Logger.log(CLASS_NAME, "getHistoryItems", e2.toString());
setState(() => showProgress = false );
} on BackendlessException catch (e3) {
log.Logger.log(CLASS_NAME, "getHistoryItems", e3.toString());
setState(() => showProgress = false );
} on PlatformException catch (e4) {
log.Logger.log(CLASS_NAME, "getHistoryItems", e4.toString());
setState(() => showProgress = false );
} on IOException catch (e5) {
log.Logger.log(CLASS_NAME, "getHistoryItems", e5.toString());
setState(() => showProgress = false );
} on Exception catch (e6) {
log.Logger.log(CLASS_NAME, "getHistoryItems", e6.toString());
setState(() => showProgress = false );
} catch (e7) {
log.Logger.log(CLASS_NAME, "getHistoryItems", e7.toString());
setState(() => showProgress = false );
}
}
@override
void initState() {
super.initState();
Backendless.setUrl(Configs.backendlessApiHostAddress);
Backendless.initApp(Configs.backendlessSdkApplicationId, Configs.backendlessSdkAndroidApiKey, Configs.backendlessSdkIosApiKey);
SystemChannels.textInput.invokeMethod('TextInput.hide');
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
_chatProvider = provider.Provider.of<ChatProvider>(context, listen: false);
_chatProvider.resetAllStates();
});
DBProvider.db.getSubscriberId().then((sid) {
subscriberId = sid;
getHistoryItems(0);
});
initChatListeners();
//PersianDate persianDate = PersianDate(format: " d MM ");
//todayDate = persianDate.now;
initScrollListener();
updateMessagesSeenStatus();
}
Future updateMessagesSeenStatus() async{
Map changes = {"is_read": 1};
await chatTableDataStore.update("contact_id = ${widget.userId} AND user_id = ${widget.contactId}", changes);//.then((objectsUpdated) {
//print("Server has updated $objectsUpdated objects");
//});
}
initChatListeners() {
try{
Backendless.messaging.subscribe(channelName).then((channel) {
channel.addMessageListener(onMessageReceived);
});
} catch(e){
log.Logger.log(CLASS_NAME, 'initChatListeners', e.toString());
}
}
When I send a message, the message is displayed after three seconds
Such a delay is normal. It depends on your network state and speed. I tried your code and get a message within 1.5-2 seconds. Is such delay so critical to you?
thanks,
yes this is critical for us
Is there a way to solve this problem?
To ensure that is a Backendless related issue, please create a minimal, reproducible example for your problem. Remove all of your code except the one for message publishing. Since I cannot get such a big delay with my sample project, it’s most likely the problem is caused by your code.
Best Regards,
Maksym
thanks