MultiUserChatLight Group Message Listener

200 Views Asked by At

Developing a Chat APP Group function using MucLight XEP with smack library ,the problem is I m able to send the message to group successfully but when its come to message listening I get confused,in smack library we have

 multiUserChatLight.addMessageListener (new MessageListener ( ) {
                @Override
                public void processMessage(Message message) {

                }
            });

But its group Specific listener , means Its only listen to multiuserchatlight reference group, which some how not what I need,because every time whenever I reconnected with the chat server I need to register this listener against every group in which I involved , which is not good in opinion . the other approach is to register packetlistener which is also little problematic with some cases like as member of group I received the message which I send into the group ,

So there is any alternative?

Can some one tell me where i am wrong ?

1

There are 1 best solutions below

0
On

whenever you connected with server and authenticated you need to register always message listener. i have done using StanzaListener to add MucLight listener.

  public RegisterXmppListener registerXmppListener;

  public void registerMessageListener(){
    debugLog("registerMessageListener");
    if(mStanzaListener !=null)
        connection.removeSyncStanzaListener(mStanzaListener);

    StanzaTypeFilter filter = new StanzaTypeFilter(Message.class);

    mStanzaListener=new StanzaListener() {
        @Override
        public void processStanza(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException {
            if(registerXmppListener!=null) {
                registerXmppListener.onMessageReceived(stanza);
            }
        }
    };
    connection.addSyncStanzaListener(mStanzaListener, filter);
}

registerMessageListener register when you have authenticated with server.