Java Code Examples for org.jivesoftware.smackx.muc.MultiUserChatManager#getMultiUserChat()

The following examples show how to use org.jivesoftware.smackx.muc.MultiUserChatManager#getMultiUserChat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmppConnection.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
public void reconnectAll ()
{
    MultiUserChatManager mucMgr = MultiUserChatManager.getInstanceFor(mConnection);
    mucMgr.setAutoJoinOnReconnect(true);

    Enumeration<MultiUserChat> eMuc = mMUCs.elements();
    while (eMuc.hasMoreElements())
    {
        MultiUserChat muc = eMuc.nextElement();

        MultiUserChat reMuc = mucMgr.getMultiUserChat(muc.getRoom());

        try {
            DiscussionHistory history = new DiscussionHistory();
            history.setMaxStanzas(Integer.MAX_VALUE);
            reMuc.join(Resourcepart.from(mUser.getName()), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());

            mMUCs.put(muc.getRoom().toString(),reMuc);
            ChatGroup group = mGroups.get(muc.getRoom().toString());

            addMucListeners(reMuc, group);
            loadMembers(muc, group);

            queryArchive(muc.getRoom());

        } catch (Exception e) {
            Log.w(TAG,"unable to join MUC: " + e.getMessage());
        }
    }
}
 
Example 2
Source File: OmemoService.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Return the joined MUC with EntityBareJid jid, or null if its not a room and/or not joined.
 *
 * @param connection xmpp connection
 * @param jid jid (presumably) of the MUC
 * @return MultiUserChat or null if not a MUC.
 */
private static MultiUserChat getMuc(XMPPConnection connection, Jid jid) {
    EntityBareJid ebj = jid.asEntityBareJidIfPossible();
    if (ebj == null) {
        return null;
    }

    MultiUserChatManager mucm = MultiUserChatManager.getInstanceFor(connection);
    Set<EntityBareJid> joinedRooms = mucm.getJoinedRooms();
    if (joinedRooms.contains(ebj)) {
        return mucm.getMultiUserChat(ebj);
    }

    return null;
}
 
Example 3
Source File: XmppConnection.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
@Override
        public void joinChatGroupAsync(Address address, String reason) {

            String chatRoomJid = address.getBareAddress();
            String[] parts = chatRoomJid.split("@");
            String room = parts[0];

            try {

                if (mConnection == null || (!mConnection.isAuthenticated()))
                    return;

//                mBookmarkManager.addBookmarkedConference(address.getUser(),JidCreate.entityBareFrom(chatRoomJid),true,null,null);

                // Create a MultiUserChat using a Connection for a room
                MultiUserChatManager mucMgr = MultiUserChatManager.getInstanceFor(mConnection);
                mucMgr.setAutoJoinOnReconnect(true);
                EntityBareJid crJid = JidCreate.entityBareFrom(chatRoomJid);
                MultiUserChat muc = mucMgr.getMultiUserChat( crJid);

                DiscussionHistory history = new DiscussionHistory();
                history.setMaxStanzas(Integer.MAX_VALUE);
                muc.join(Resourcepart.from(mUser.getName()), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());
                String subject = muc.getSubject();

                if (TextUtils.isEmpty(subject))
                    subject = room;

                ChatGroup chatGroup = mGroups.get(chatRoomJid);

                if (chatGroup == null) {
                    chatGroup = new ChatGroup(address, subject, this);
                    mGroups.put(chatRoomJid, chatGroup);
                }

                mMUCs.put(chatRoomJid, muc);

                addMucListeners(muc, chatGroup);
                loadMembers(muc, chatGroup);

                queryArchive(crJid);

            } catch (Exception e) {
                debug(TAG,"error joining MUC",e);
            }

        }