Search in sources :

Example 86 with Presence

use of org.jivesoftware.smack.packet.Presence in project intellij-plugins by JetBrains.

the class JabberTransport_ConnectionTest method testUserOnlineOffline.

public void testUserOnlineOffline() throws Throwable {
    addEventListener();
    String userName = "bob" + System.currentTimeMillis();
    XMPPConnection contact = createLocalConnectionWithJabberUser(userName, null);
    Roster roster = myTransport.getFacade().getConnection().getRoster();
    String jabberUser = getUser(contact);
    final User bob = UserImpl.create(jabberUser, myTransport.getName());
    myEvents.clear();
    roster.createEntry(jabberUser, "Bob", new String[0]);
    new WaitFor(TIMEOUT) {

        @Override
        protected boolean condition() {
            return myEvents.size() == 2;
        }
    };
    assertTrue("Bob should be online", bob.isOnline());
    assertEquals("/ideTalk/jabber.png", myTransport.getIcon(bob.getPresence()));
    assertEquals("One user in UserModel expected:" + Arrays.asList(myUserModel.getAllUsers()), 1, myUserModel.getAllUsers().length);
    UserEvent.Online online = ((UserEvent.Online) myEvents.get(1));
    assertEquals("Online event expected", bob, online.getUser());
    myEvents.clear();
    Presence presence = new Presence(Presence.Type.unavailable);
    contact.sendPacket(presence);
    new WaitFor(TIMEOUT) {

        @Override
        protected boolean condition() {
            return myEvents.size() == 1;
        }
    };
    assertFalse("Should become offline", bob.isOnline());
    assertEquals("/ideTalk/offline.png", myTransport.getIcon(myTransport.getUserPresence(bob)));
    assertEquals("Bob should go offline", bob, ((UserEvent.Offline) checkEvent(true)).getUser());
}
Also used : User(jetbrains.communicator.core.users.User) WaitFor(jetbrains.communicator.util.WaitFor) Presence(org.jivesoftware.smack.packet.Presence) UserPresence(jetbrains.communicator.core.users.UserPresence) UserEvent(jetbrains.communicator.core.users.UserEvent)

Example 87 with Presence

use of org.jivesoftware.smack.packet.Presence in project intellij-plugins by JetBrains.

the class JabberFacade_ConnectionTest method testPresenceAfterConnection.

public void testPresenceAfterConnection() throws Throwable {
    createGoodAccount(myUser, myFacade);
    final String me = myFacade.getConnection().getUser();
    myFacade.getConnection().getRoster().setSubscriptionMode(Roster.SubscriptionMode.accept_all);
    final JabberFacadeImpl another = new JabberFacadeImpl(myIDEFacade);
    createGoodAccount("ddd" + System.currentTimeMillis(), another);
    another.addUsers("group", Arrays.asList(me));
    new WaitFor(3000) {

        @Override
        protected boolean condition() {
            return another.getConnection().getRoster().getPresence(me) != null;
        }
    };
    Presence presence = another.getConnection().getRoster().getPresence(me);
    assertNotNull(presence);
    assertEquals(Presence.Type.available, presence.getType());
    assertEquals(Presence.Mode.available, presence.getMode());
}
Also used : WaitFor(jetbrains.communicator.util.WaitFor) Presence(org.jivesoftware.smack.packet.Presence)

Example 88 with Presence

use of org.jivesoftware.smack.packet.Presence in project Essentials by drtshock.

the class XMPPManager method disconnect.

public final void disconnect() {
    if (loggerThread != null) {
        loggerThread.interrupt();
    }
    if (chatManager != null) {
        chatManager.removeChatListener(this);
        chatManager = null;
    }
    if (connection != null) {
        connection.disconnect(new Presence(Presence.Type.unavailable));
    }
}
Also used : Presence(org.jivesoftware.smack.packet.Presence)

Example 89 with Presence

use of org.jivesoftware.smack.packet.Presence in project Essentials by drtshock.

the class XMPPManager method updatePresence.

public final void updatePresence() {
    final int usercount;
    final StringBuilder stringBuilder = new StringBuilder();
    usercount = parent.getEss().getOnlinePlayers().size();
    if (usercount == 0) {
        final String presenceMsg = "No one online.";
        connection.sendPacket(new Presence(Presence.Type.available, presenceMsg, 2, Presence.Mode.dnd));
    }
    if (usercount == 1) {
        final String presenceMsg = "1 player online.";
        connection.sendPacket(new Presence(Presence.Type.available, presenceMsg, 2, Presence.Mode.available));
    }
    if (usercount > 1) {
        stringBuilder.append(usercount).append(" players online.");
        connection.sendPacket(new Presence(Presence.Type.available, stringBuilder.toString(), 2, Presence.Mode.available));
    }
}
Also used : Presence(org.jivesoftware.smack.packet.Presence)

Aggregations

Presence (org.jivesoftware.smack.packet.Presence)89 Message (org.jivesoftware.smack.packet.Message)17 MessageTypeFilter (org.jivesoftware.smack.filter.MessageTypeFilter)10 StanzaCollector (org.jivesoftware.smack.StanzaCollector)7 AndFilter (org.jivesoftware.smack.filter.AndFilter)7 Jid (org.jxmpp.jid.Jid)7 Resourcepart (org.jxmpp.jid.parts.Resourcepart)7 UserPresence (jetbrains.communicator.core.users.UserPresence)6 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)5 MUCInitialPresence (org.jivesoftware.smackx.muc.packet.MUCInitialPresence)5 Test (org.junit.Test)5 BareJid (org.jxmpp.jid.BareJid)5 EntityFullJid (org.jxmpp.jid.EntityFullJid)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 WaitFor (jetbrains.communicator.util.WaitFor)4 AccountItem (com.xabber.android.data.account.AccountItem)3 ClientInfo (com.xabber.android.data.extension.capability.ClientInfo)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 XMPPException (org.jivesoftware.smack.XMPPException)3