Server Accept Account for Android

I am trying to make a chat application using XMPP. For this, I mentioned this tutorial and successfully implemented it. But now I can’t get the specific message received by the server and update my local DB. Please let me know how to do this.

I am saving a message with chatId. So, from which smack method do I get this receipt id?

+2
source share
2 answers
  • You need to save your messages by message identifier, you can get the identifier through message.getStanzaId ().
  • You need to enable flow control .

    static { XMPPTCPConnection.setUseStreamManagementDefault(true); XMPPTCPConnection.setUseStreamManagementResumptiodDefault(true); } 
  • when you send a message, you add a listener for that message, for example.

     try { if (mConnection.isSmEnabled()) { try { mConnection.addStanzaIdAcknowledgedListener(message.getStanzaId(), new StanzaListener() { @Override public void processPacket(Stanza packet) throws NotConnectedException { updateMessageStatus(packet); } }); } catch (StreamManagementException.StreamManagementNotEnabledException e) { e.printStackTrace(); } } mConnection.sendStanza(message); } catch (NotConnectedException e) { e.printStackTrace(); } 

    Now, inside the updateMessageStatus method (packet), you will find a message in your database by id (packet.getStanzaId ()) and update the status from “pending” to “sent”.

    Please note that your server also needs to enable flow control.

+12
source
 connection.setUseStreamManagement(true); 

This will allow flow control (XEP-198) on the client side.

http://xmpp.org/extensions/xep-0198.html#acking

NB: it will only work if the server supports XEP-198.

+2
source

Source: https://habr.com/ru/post/984287/


All Articles