Offline-inline messages (no chat)

Hi you all!

I’'m having a lot of problems trying to do what in a simple view must must be simple…

I’'m working on a simple web client that only have to see the messages that a user has when he conects. (And maybe show those messages).

The problem is that I really don’'t know what to use: PacketListener/PacketCollector becaous both of them seem to be used when you are working in an on-line chat to interact, etc.

I only wanna see a list with the messages that an user has in his “repository” when he connects.

About offline users I’‘ve read that I should use the PacketCollector before loging the user ¿?¿? I don’‘t know if I’'ve understood well at all… how does SMACK knows which messages has to show?

If anybody knows how I must do this, please post a snippet or something like that.

Sorry about my english.

Thanks in advance!

Hola Miguel,

Tu mensaje se entendió lo más bien.

From the point of view of the client, XMPP does not make much difference if the message was sent to the user when the user was online or offline. The only difference is that offline messages include extra information about the time when the message was sent to the user. Take in consideration that some servers may not store messages for offline users whilst others may store them until a certain limit in the database.

Having said that, when a user becomes online the server will check if there are stored messages while the user was offline and then send them to the user. Since those messages are being sent immediately after the user logged into the server, it is necessary to configure the listeners or collectors before doing the login. Check MessageTest#testOfflineMessage() to see a running example on how to get those messages.

Saludos,

– Gato

Hi Gato!

First of all, thanks a lot for your answering, I’'m undestanding it better…

To complete my question I wanted to know when an user have/not messages (even inline or offline) I need this feature because as I said, I’'m not working in a chat (on-line im) so I can´t do a “while(true)” loop to wait form messages.

In another hand, I have to wait for a moment to get the messages, laike in the code I show below…

//Creando la conexión al servidor

XMPPConnection conn = new XMPPConnection(server, port);

//Loggando al usuario

try

{

conn.login(jid, pass);

//Create the filter:

PacketFilter filter = new PacketTypeFilter(Message.class);

PacketListener list = new PacketListener(){

public void processPacket(Packet packet){

Message message = (Message)packet;

// I can see the messages in the console, but how I got them to show in ma page?

System.out.println("pepe: " +message.getFrom());

System.out.println(message.getBody());

acumula += " \n";

acumula += " \n";

acumula = message.getFrom() “\n”;

acumula += " \n";

acumula += " \n";

acumula = message.getBody() “\n”;

acumula += " \n";

acumula += " \n";

}};

acumula = “”;

conn.addPacketListener(list, filter);

long cont = 0;

while (cont < 99999999)

{

cont++;

}

acumula += “”;

%>

<%=acumula%>

<%

}catch (XMPPException e)

{

}

%>

I’‘m doing an active-waiting (<- don’‘t know how to say this) to let the XMPPConnection time enough to receive the messages… I know it isn’‘t all right at all, but I don’'t know how to do it. (If I had a method to know that thers no messages, or there are no messages left, I could finish the “building of acumula” in a better way.

Sorry, but I don’'t know where can I find the MessageTes#testOffflineMessages that you mentioned…

THanks again

Another question related with this feature…

If there is a way to ask if I have any messages… Could I ask for it without loosing the messages from the server?

Well, the best I can reach is to show in the web the number of messages that an user have and let him/her to see then when they wanted to. So I need a way to know how messages they have and later receive them (with the packetlistener or something like that).

Thanks a lot in advance!

Saludos,

Migue

Miguel,

“Out-of-the-box” XMPP does not provide a way to discover if a user has stored messages or not. The server just sends the messages (stored when offline or not) to the target user as close to real time as possible.

I don’‘t have more information about the problem you are trying to solve but if you are using Jive Messenger as the server then you can write a plugin. This plugin could let you discover the number of stored messages (i.e. messages sent to a user when the user was offline) so you can get that number even before the user logs into the server or while receiving the messages so you don’'t have to do the “active-waiting”.

Avisame si tenes alguna duda.

Saludos,

– Gato

Hola de nuevo Gato!

I think it’‘s could be useful to implement that plugin… but don’'t know where to begin…

Where does those messages are stored? etc

Don’'t you know where can I look first to get into work?

thanks a lot!

Saludos,

– Migue!

I’'ve added a question about how to make a plugin

Yep, I saw the other threads.

Saludos,

– Gato