Search in sources :

Example 1 with MucCreateConfigFormHandle

use of org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle in project Smack by igniterealtime.

the class MucBookmarkAutojoinManager method autojoinBookmarkedConferences.

public void autojoinBookmarkedConferences() {
    List<BookmarkedConference> bookmarkedConferences;
    try {
        bookmarkedConferences = bookmarkManager.getBookmarkedConferences();
    } catch (NotConnectedException | InterruptedException e) {
        LOGGER.log(Level.FINER, "Could not get MUC bookmarks", e);
        return;
    } catch (NoResponseException | XMPPErrorException e) {
        LOGGER.log(Level.WARNING, "Could not get MUC bookmarks", e);
        return;
    }
    final XMPPConnection connection = connection();
    Resourcepart defaultNick = connection.getUser().getResourcepart();
    for (BookmarkedConference bookmarkedConference : bookmarkedConferences) {
        if (!bookmarkedConference.isAutoJoin()) {
            continue;
        }
        Resourcepart nick = bookmarkedConference.getNickname();
        if (nick == null) {
            nick = defaultNick;
        }
        String password = bookmarkedConference.getPassword();
        MultiUserChat muc = multiUserChatManager.getMultiUserChat(bookmarkedConference.getJid());
        try {
            MucCreateConfigFormHandle handle = muc.createOrJoinIfNecessary(nick, password);
            if (handle != null) {
                handle.makeInstant();
            }
        } catch (NotConnectedException | InterruptedException e) {
            LOGGER.log(Level.FINER, "Could not autojoin bookmarked MUC", e);
            // abort here
            break;
        } catch (NotAMucServiceException | NoResponseException | XMPPErrorException e) {
            // Do no abort, just log,
            LOGGER.log(Level.WARNING, "Could not autojoin bookmarked MUC", e);
        }
    }
}
Also used : MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) XMPPConnection(org.jivesoftware.smack.XMPPConnection) BookmarkedConference(org.jivesoftware.smackx.bookmarks.BookmarkedConference) NotAMucServiceException(org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) MucCreateConfigFormHandle(org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle)

Example 2 with MucCreateConfigFormHandle

use of org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle in project Smack by igniterealtime.

the class MultiUserChatLowLevelIntegrationTest method testMucBookmarksAutojoin.

@SmackIntegrationTest
public void testMucBookmarksAutojoin(XMPPTCPConnection connection) throws InterruptedException, TestNotPossibleException, XMPPException, SmackException, IOException {
    final BookmarkManager bookmarkManager = BookmarkManager.getBookmarkManager(connection);
    if (!bookmarkManager.isSupported()) {
        throw new TestNotPossibleException("Private data storage not supported");
    }
    final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);
    final Resourcepart mucNickname = Resourcepart.from("Nick-" + StringUtils.randomString(6));
    final String randomMucName = StringUtils.randomString(6);
    final DomainBareJid mucComponent = multiUserChatManager.getXMPPServiceDomains().get(0);
    final MultiUserChat muc = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom(Localpart.from(randomMucName), mucComponent));
    MucCreateConfigFormHandle handle = muc.createOrJoin(mucNickname);
    if (handle != null) {
        handle.makeInstant();
    }
    muc.leave();
    bookmarkManager.addBookmarkedConference("Smack Inttest: " + testRunId, muc.getRoom(), true, mucNickname, null);
    connection.disconnect();
    connection.connect().login();
    // MucBookmarkAutojoinManager is also able to do its task automatically
    // after every login, it's not determinstic when this will be finished.
    // So we trigger it manually here.
    MucBookmarkAutojoinManager.getInstanceFor(connection).autojoinBookmarkedConferences();
    assertTrue(muc.isJoined());
    // If the test went well, leave the MUC
    muc.leave();
}
Also used : TestNotPossibleException(org.igniterealtime.smack.inttest.TestNotPossibleException) DomainBareJid(org.jxmpp.jid.DomainBareJid) MucCreateConfigFormHandle(org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle) BookmarkManager(org.jivesoftware.smackx.bookmarks.BookmarkManager) Resourcepart(org.jxmpp.jid.parts.Resourcepart) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 3 with MucCreateConfigFormHandle

use of org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle in project Smack by igniterealtime.

the class MultiUserChatLowLevelIntegrationTest method testMucBookmarksAutojoin.

@SmackIntegrationTest
public void testMucBookmarksAutojoin(AbstractXMPPConnection connection) throws InterruptedException, TestNotPossibleException, XMPPException, SmackException, IOException {
    final BookmarkManager bookmarkManager = BookmarkManager.getBookmarkManager(connection);
    if (!bookmarkManager.isSupported()) {
        throw new TestNotPossibleException("Private data storage not supported");
    }
    final MultiUserChatManager multiUserChatManager = MultiUserChatManager.getInstanceFor(connection);
    final Resourcepart mucNickname = Resourcepart.from("Nick-" + StringUtils.randomString(6));
    final String randomMucName = StringUtils.randomString(6);
    final DomainBareJid mucComponent = multiUserChatManager.getMucServiceDomains().get(0);
    final MultiUserChat muc = multiUserChatManager.getMultiUserChat(JidCreate.entityBareFrom(Localpart.from(randomMucName), mucComponent));
    MucCreateConfigFormHandle handle = muc.createOrJoin(mucNickname);
    if (handle != null) {
        handle.makeInstant();
    }
    muc.leave();
    bookmarkManager.addBookmarkedConference("Smack Inttest: " + testRunId, muc.getRoom(), true, mucNickname, null);
    connection.disconnect();
    connection.connect().login();
    // MucBookmarkAutojoinManager is also able to do its task automatically
    // after every login, it's not deterministic when this will be finished.
    // So we trigger it manually here.
    MucBookmarkAutojoinManager.getInstanceFor(connection).autojoinBookmarkedConferences();
    assertTrue(muc.isJoined());
    // If the test went well, leave the MUC
    muc.leave();
}
Also used : TestNotPossibleException(org.igniterealtime.smack.inttest.TestNotPossibleException) DomainBareJid(org.jxmpp.jid.DomainBareJid) MucCreateConfigFormHandle(org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle) BookmarkManager(org.jivesoftware.smackx.bookmarks.BookmarkManager) Resourcepart(org.jxmpp.jid.parts.Resourcepart) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)

Aggregations

MucCreateConfigFormHandle (org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle)3 Resourcepart (org.jxmpp.jid.parts.Resourcepart)3 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)2 BookmarkManager (org.jivesoftware.smackx.bookmarks.BookmarkManager)2 DomainBareJid (org.jxmpp.jid.DomainBareJid)2 SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)1 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)1 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)1 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1 BookmarkedConference (org.jivesoftware.smackx.bookmarks.BookmarkedConference)1 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)1 NotAMucServiceException (org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException)1