Search in sources :

Example 1 with InvitationListener

use of org.jivesoftware.smackx.muc.InvitationListener in project ecf by eclipse.

the class XMPPChatRoomManager method setConnection.

public void setConnection(Namespace connectNamespace, ID connectedID, ECFConnection connection) {
    this.connectNamespace = connectNamespace;
    this.connectedID = connectedID;
    this.ecfConnection = connection;
    if (connection != null) {
        // Setup invitation requestListener
        MultiUserChat.addInvitationListener(ecfConnection.getXMPPConnection(), new InvitationListener() {

            public void invitationReceived(Connection arg0, String arg1, String arg2, String arg3, String arg4, Message arg5) {
                fireInvitationReceived(createRoomIDFromName(arg1), createUserIDFromName(arg2), createUserIDFromName(arg5.getTo()), arg5.getSubject(), arg3);
            }
        });
    } else {
        disposeChatRooms();
    }
}
Also used : InvitationListener(org.jivesoftware.smackx.muc.InvitationListener) IChatRoomInvitationListener(org.eclipse.ecf.presence.chatroom.IChatRoomInvitationListener) Message(org.jivesoftware.smack.packet.Message) Connection(org.jivesoftware.smack.Connection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ECFConnection(org.eclipse.ecf.internal.provider.xmpp.smack.ECFConnection)

Example 2 with InvitationListener

use of org.jivesoftware.smackx.muc.InvitationListener in project Zom-Android by zom.

the class XmppConnection method initConnectionAndLogin.

private void initConnectionAndLogin(Imps.ProviderSettings.QueryMap providerSettings, String userName) throws InterruptedException, IOException, SmackException, XMPPException, KeyManagementException, NoSuchAlgorithmException, IllegalStateException, RuntimeException {
    // Roster.SubscriptionMode.accept_all;//load this from a preference
    Roster.SubscriptionMode subMode = Roster.SubscriptionMode.manual;
    // only activates if Debug TRUE is set, so you can leave this in!
    Debug.onConnectionStart();
    initConnection(providerSettings, userName);
    if (mConnection.isConnected() && mConnection.isSecureConnection() && (!mConnection.isAuthenticated())) {
        mResource = providerSettings.getXmppResource();
        mRoster = Roster.getInstanceFor(mConnection);
        mRoster.setRosterLoadedAtLogin(true);
        mRoster.setSubscriptionMode(subMode);
        getContactListManager().listenToRoster(mRoster);
        ReconnectionManager manager = ReconnectionManager.getInstanceFor(mConnection);
        manager.disableAutomaticReconnection();
        mChatManager = ChatManager.getInstanceFor(mConnection);
        mPingManager = PingManager.getInstanceFor(mConnection);
        mPingManager.setPingInterval(PING_INTERVAL);
        if (mUser == null)
            mUser = makeUser(providerSettings, mContext.getContentResolver());
        try {
            getOmemo();
        } catch (Exception e) {
            debug(TAG, "error init'ing omemo during connectoin", e);
        }
        MultiUserChatManager.getInstanceFor(mConnection).addInvitationListener(new InvitationListener() {

            @Override
            public void invitationReceived(XMPPConnection xmppConnection, MultiUserChat muc, EntityJid entityJid, String reason, String password, org.jivesoftware.smack.packet.Message message, MUCUser.Invite invite) {
                try {
                    getChatGroupManager().acceptInvitationAsync(invite.getFrom().toString());
                    XmppAddress xa = new XmppAddress(muc.getRoom().toString());
                    mChatGroupManager.joinChatGroupAsync(xa, reason);
                    ChatSession session = mSessionManager.findSession(muc.getRoom());
                    // create a session
                    if (session == null) {
                        ImEntity participant = findOrCreateParticipant(xa.getAddress(), true);
                        if (participant != null)
                            session = mSessionManager.createChatSession(participant, false);
                        if (session != null)
                            ((ChatGroup) session.getParticipant()).setName(muc.getSubject());
                    }
                } catch (Exception se) {
                    Log.e(TAG, "error accepting invite", se);
                }
            }
        });
        mConnection.login(mUsername, mPassword, Resourcepart.from(mResource));
        mStreamHandler.notifyInitialLogin();
        initServiceDiscovery();
        getContactListManager().loadContactListsAsync();
        execute(new Runnable() {

            public void run() {
                sendPresencePacket();
                sendVCard();
            }
        });
    } else {
        // throw some meaningful error message here
        throw new SmackException("Unable to securely conenct to server");
    }
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) ReconnectionManager(org.jivesoftware.smack.ReconnectionManager) SmackException(org.jivesoftware.smack.SmackException) ChatGroup(org.awesomeapp.messenger.model.ChatGroup) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) KeyStoreException(java.security.KeyStoreException) UndecidedOmemoIdentityException(org.jivesoftware.smackx.omemo.exceptions.UndecidedOmemoIdentityException) XMPPException(org.jivesoftware.smack.XMPPException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ImException(org.awesomeapp.messenger.model.ImException) KeyManagementException(java.security.KeyManagementException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SmackException(org.jivesoftware.smack.SmackException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) MultiUserChatException(org.jivesoftware.smackx.muc.MultiUserChatException) CryptoFailedException(org.jivesoftware.smackx.omemo.exceptions.CryptoFailedException) CertificateException(java.security.cert.CertificateException) ChatSession(org.awesomeapp.messenger.model.ChatSession) IChatSession(org.awesomeapp.messenger.service.IChatSession) EntityJid(org.jxmpp.jid.EntityJid) Roster(org.jivesoftware.smack.roster.Roster) InvitationListener(org.jivesoftware.smackx.muc.InvitationListener) ImEntity(org.awesomeapp.messenger.model.ImEntity)

Aggregations

XMPPConnection (org.jivesoftware.smack.XMPPConnection)2 InvitationListener (org.jivesoftware.smackx.muc.InvitationListener)2 RemoteException (android.os.RemoteException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ChatGroup (org.awesomeapp.messenger.model.ChatGroup)1 ChatSession (org.awesomeapp.messenger.model.ChatSession)1 ImEntity (org.awesomeapp.messenger.model.ImEntity)1 ImException (org.awesomeapp.messenger.model.ImException)1 IChatSession (org.awesomeapp.messenger.service.IChatSession)1 ECFConnection (org.eclipse.ecf.internal.provider.xmpp.smack.ECFConnection)1 IChatRoomInvitationListener (org.eclipse.ecf.presence.chatroom.IChatRoomInvitationListener)1 AbstractXMPPConnection (org.jivesoftware.smack.AbstractXMPPConnection)1 Connection (org.jivesoftware.smack.Connection)1 ReconnectionManager (org.jivesoftware.smack.ReconnectionManager)1