Search in sources :

Example 6 with UserPresence

use of jetbrains.communicator.core.users.UserPresence in project intellij-plugins by JetBrains.

the class ToggleFileAccessCommandTest method testMultipleSelection_OfflineUsersHidden.

public void testMultipleSelection_OfflineUsersHidden() throws Exception {
    final User user1 = myUserModel.createUser("user1", MockTransport.NAME);
    final User user2 = myUserModel.createUser("user2", MockTransport.NAME);
    Pico.getInstance().unregisterComponent(Pico.getInstance().getComponentInstanceOfType(Transport.class));
    MockTransport mockTransport = new MockTransport() {

        @Override
        public UserPresence getUserPresence(User user) {
            return user == user1 ? new UserPresence(true) : new UserPresence(false);
        }
    };
    Pico.getInstance().registerComponentInstance(mockTransport);
    myUserListComponent.stubs().method("getSelectedNodes").will(returnValue(new Object[] { "grp", user2 }));
    myUserModel.addUser(user1);
    myUserModel.addUser(user2);
    user1.setGroup("grp", myUserModel);
    user2.setCanAccessMyFiles(true, myUserModel);
    assertFalse("Different state of canAccess flag", myCommand.isEnabled());
    OptionFlag.OPTION_HIDE_OFFLINE_USERS.change(true);
    assertTrue("Only online user should be considered", myCommand.isEnabled());
    myCommand.execute();
    assertTrue("Should change online user", user1.canAccessMyFiles());
    assertTrue("Should keep offline user", user2.canAccessMyFiles());
}
Also used : User(jetbrains.communicator.core.users.User) MockUser(jetbrains.communicator.mock.MockUser) MockTransport(jetbrains.communicator.mock.MockTransport) UserPresence(jetbrains.communicator.core.users.UserPresence) MockTransport(jetbrains.communicator.mock.MockTransport) Transport(jetbrains.communicator.core.transport.Transport)

Example 7 with UserPresence

use of jetbrains.communicator.core.users.UserPresence in project intellij-plugins by JetBrains.

the class AbstractTransportTestCase method testSetOwnPresence_OnlineOffline.

public void testSetOwnPresence_OnlineOffline() throws Exception {
    assertTrue("Should be online by default", myTransport.isOnline());
    myTransport.setOwnPresence(new UserPresence(false));
    assertFalse("Should become offline", myTransport.isOnline());
    new WaitFor(1000) {

        @Override
        protected boolean condition() {
            return !mySelf.isOnline();
        }
    };
    assertFalse("Self user should become online", mySelf.isOnline());
    myTransport.setOwnPresence(new UserPresence(true));
    assertTrue("Should become online", myTransport.isOnline());
}
Also used : WaitFor(jetbrains.communicator.util.WaitFor) UserPresence(jetbrains.communicator.core.users.UserPresence)

Example 8 with UserPresence

use of jetbrains.communicator.core.users.UserPresence in project intellij-plugins by JetBrains.

the class UserActivityMonitor method run.

@Override
public void run() {
    try {
        myThreadDisposed = false;
        while (!myStop) {
            UserPresence userPresence = calculatePresence();
            LOG.debug("Calculated own presence: " + userPresence);
            for (Object o : Pico.getInstance().getComponentInstancesOfType(Transport.class)) {
                Transport transport = (Transport) o;
                if (transport.isOnline()) {
                    transport.setOwnPresence(userPresence);
                }
            }
            synchronized (myMonitor) {
                myMonitor.wait(myRefreshInterval);
            }
        }
    } catch (InterruptedException e) {
        LOG.info("Interrupted");
    } finally {
        myThreadDisposed = true;
    }
}
Also used : UserPresence(jetbrains.communicator.core.users.UserPresence) Transport(jetbrains.communicator.core.transport.Transport)

Example 9 with UserPresence

use of jetbrains.communicator.core.users.UserPresence in project intellij-plugins by JetBrains.

the class JabberTransport_ConnectionTest method testSetOwnPresence_Status.

public void testSetOwnPresence_Status() throws Exception {
    String bobName = "bob" + System.currentTimeMillis();
    final XMPPConnection bob = createLocalConnectionWithJabberUser(bobName, null);
    final String user = selfJabberId();
    bob.getRoster().createEntry(user, user, new String[0]);
    myFacade.addUsers("grp", Arrays.asList(getUser(bob)));
    new WaitFor(TIMEOUT) {

        @Override
        protected boolean condition() {
            return null != bob.getRoster().getPresence(user);
        }
    };
    assert null != bob.getRoster().getPresence(user);
    // First, change own presence and check it's changed from bob's point of view
    UserPresence presence = new UserPresence(PresenceMode.AWAY);
    assert presence.isOnline();
    myTransport.setOwnPresence(presence);
    new WaitFor(TIMEOUT) {

        @Override
        protected boolean condition() {
            return Presence.Mode.away == bob.getRoster().getPresence(user).getMode();
        }
    };
    Presence p = bob.getRoster().getPresence(user);
    assertSame("Own presence should be away", Presence.Mode.away, p.getMode());
    assertEquals("", p.getStatus());
    // Now, change bob's presence
    new WaitFor(TIMEOUT) {

        @Override
        protected boolean condition() {
            return myEvents.size() > 2;
        }
    };
    myEvents.clear();
    bob.sendPacket(new Presence(Presence.Type.available, "", 0, Presence.Mode.dnd));
    final User bobUser = myUserModel.findUser(getUser(bob), myTransport.getName());
    new WaitFor(TIMEOUT) {

        @Override
        protected boolean condition() {
            return PresenceMode.DND == bobUser.getPresence().getPresenceMode();
        }
    };
    assertSame("Should take bob's presence", PresenceMode.DND, bobUser.getPresence().getPresenceMode());
    UserEvent.Updated event = (UserEvent.Updated) checkEvent(true);
    assertEquals(bobUser, event.getUser());
    assertEquals("presence", event.getPropertyName());
    assertEquals(PresenceMode.DND, event.getNewValue());
    assertEquals(PresenceMode.AVAILABLE, event.getOldValue());
    // Now, change bob's presence + set time
    bob.sendPacket(new Presence(Presence.Type.available, "some status", 0, Presence.Mode.xa));
    new WaitFor(TIMEOUT) {

        @Override
        protected boolean condition() {
            return PresenceMode.EXTENDED_AWAY == bobUser.getPresence().getPresenceMode();
        }
    };
    assertSame("Should take bob's presence", PresenceMode.EXTENDED_AWAY, bobUser.getPresence().getPresenceMode());
}
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) UserPresence(jetbrains.communicator.core.users.UserPresence) UserEvent(jetbrains.communicator.core.users.UserEvent)

Aggregations

UserPresence (jetbrains.communicator.core.users.UserPresence)9 User (jetbrains.communicator.core.users.User)5 Transport (jetbrains.communicator.core.transport.Transport)2 MockTransport (jetbrains.communicator.mock.MockTransport)2 WaitFor (jetbrains.communicator.util.WaitFor)2 Presence (org.jivesoftware.smack.packet.Presence)2 PresenceMode (jetbrains.communicator.core.users.PresenceMode)1 UserEvent (jetbrains.communicator.core.users.UserEvent)1 MockUser (jetbrains.communicator.mock.MockUser)1