Why are messages being deleted after a short time?

After I use this code, I see the channel and the message appear on backendless console. But after a short time, it disappears. Why?

Backendless.Messaging.publish(“channelName”, MainActivity.valuesLocal.get(0), new AsyncCallback<MessageStatus>()
{
@Override
public void handleResponse( MessageStatus response )
{

						            	Toast.makeText(getApplicationContext(), "response ok", Toast.LENGTH_LONG).show();
						            	
						            }


						            @Override
						            public void handleFault( BackendlessFault fault )
						            {
						            	Toast.makeText(getApplicationContext(), "response down", Toast.LENGTH_LONG).show();
						            }
						          } );

Our system processes hundreds of thousands of messages. Storing each and every message would be extremely inefficient and costly.

Regards,
Mark

but why then you call it messages? if i even can’t realise even simple mechanic of messaging (like imessages for example) beatween 2 people. And anyway need to somehow keep all in date base and make code for it. or is there any other ways?
Thanks

I am not going to argue what it should be called. We call it messages and that is not going to change.

Android, iOS, JS and Flex SDK include a ready-to-go example which demonstrates a “simple mechanic of messaging between 2 people”…

Please be specific and describe what you are trying to do and what seems to be the problem.

oh… i’m not arguing :slight_smile: just asking, no more :slight_smile: Probably missed something in your example. Look through once more and let you know if will have a questions with more details. Thanks

What do you develop for? iOS, Android, JS?

iOS

Try this:

    select your app in console click the Code Generation icon select iOS in the menu click Sample Chat under Messaging > Publish/Subscribe.
That will generate a project with source code for your app which demonstrates basic chat between 2 people.

Regards,
Mark

I’m guessing Kirill meant keeping a chat history indefinitely

Chat history can be implemented with custom server-side code. All one needs to do is to add a “beforePublish” or “afterPublish” handler and store the published messages in the Data service.

Yep, but still will have a problem if user gets messages when he not in application. Then i probably need to use some timer to check server is there any new messages, or probably we could realise it on some other way? Could you help us manage this issue?

Hi Kirill,

The best way to preserve messages is by writing custom server-code for the message “publish” event and store incoming messages in our data store. When users come online, your app would first check in the data store (using Data Service API) and then use messaging “subscribe” function to receive messages from the Messaging Service.

Does it make sense?

Regards,
Mark

Hi Mark

Please would you give some code sample that implements message storing in data service?
1- which api should be used to check the new messages in data store?
2- How recipient to receive the stored message by subscribing ?

Regards
Mousa

Am really scratching my head around this . Problem with implementing server-side-code, in Android, is one would need two adapters, one to populate data from the stored record API and another to populate from the messaging API. Which one do u show coz one cannot show both simultaneously ? i stand corrected.

I apologize, I cannot understand what you’re asking. Could you possibly rephrase the question(s)?

He is trying to say he will need two different sources of data for the chat view. In iOS terms - datasources for ViewController, in Android terms adapters for Activity.

In this case, creating a facade adapter that pulls data from both sources and returns a unified collection would be an approach I’d experiment with.

The apparent problem is the synchronization - should the app fetch Messages or BackendlessEntities to fill UITableView (or ListView)?

Perhaps there ought to be yet another object - a ViewModel for the TableViewCell, that will be created with a Message or with Entity.

It really is a strange setup at least from my experience with other messaging systems like socket.io. I’m not sure if there is any performance advantage as we have to save the messages to the database anyway.

Could you give us hint on how to do it in Javascript backend? This is what I have got so far from the generated code:

Backendless.ServerCode.Messaging.beforePublish('*', function(req) {
 //add your code here
	var chatObject = new ChatMessage( {	
 text: "", // how do I get it?
userId: "",
 conversationId: "",
	});
	 
	var savedContact = Backendless.Persistence.of( Contact ).save( chatObject );
});

I’m looking at this in Java documentation

public void beforePublish( RunnerContext context, Object message, PublishOptions publishOptions, DeliveryOptions deliveryOptions ) throws Exception

I didn’t find anything similar in JS docs, neither How to get the message data so I can create a ChatMessage object?

Hi! About messages history. Is there any way to enable this feature by default in local Backendless installation?

I mean without need to store history as Mark advised above.
Thanks in advance.