Package com.calclab.emite.core.stanzas

Examples of com.calclab.emite.core.stanzas.Presence


    }
  }

  @Override
  public void onPresenceReceived(final PresenceReceivedEvent event) {
    final Presence presence = event.getPresence();
    final RosterItem item = getItemByJID(presence.getFrom());
    if (item != null) {
      final String resource = presence.getFrom().getResource();

      boolean hasChanged = false;

      final boolean wasAvailable = item.getAvailableResources().contains(resource);

      if (presence.getType() == Presence.Type.unavailable) {
        if (wasAvailable) {
          hasChanged = true;
          item.setAvailable(false, resource);
        }
      } else {
        if (!wasAvailable) {
          hasChanged = true;
          item.setAvailable(true, resource);
        }
      }
     
      if (!presence.getShow().equals(item.getShow())) {
        hasChanged = true;
        item.setShow(presence.getShow());
      }

      if (item.getStatus() == null && presence.getStatus() != null || item.getStatus() != null && !item.getStatus().equals(presence.getStatus())) {
        hasChanged = true;
        item.setStatus(presence.getStatus());
      }

      if (hasChanged) {
        final RosterItemChangedEvent changeEvent = new RosterItemChangedEvent(ChangeType.modified, item);
        eventBus.fireEventFromSource(changeEvent, this);
View Full Code Here


  }

  @Test
  public void shouldBroadcastPresenceIfLoggedin() {
    session.setLoggedIn("myself@domain");
    final Presence newOwn = new Presence();
    newOwn.setStatus("this is my new status");
    newOwn.setShow(Show.away);
    manager.changeOwnPresence(newOwn);
    session.verifySent("<presence><show>away</show>" + "<status>this is my new status</status></presence>");
    final Presence current = manager.getOwnPresence();
    assertEquals(Show.away, current.getShow());
    assertEquals("this is my new status", current.getStatus());
  }
View Full Code Here

  @Test
  public void shouldEventOwnPresence() {
    session.setLoggedIn(uri("myself@domain"));
    final OwnPresenceChangedTestHandler handler = new OwnPresenceChangedTestHandler();
    manager.addOwnPresenceChangedHandler(handler);
    final Presence newOwn = new Presence();
    newOwn.setStatus("status");
    newOwn.setShow(Show.away);
    manager.changeOwnPresence(newOwn);
    assertTrue(handler.isCalledOnce());
    assertEquals("status", handler.getCurrentPresence().getStatus());
    assertEquals(Show.away, handler.getCurrentPresence().getShow());
  }
View Full Code Here

  }

  @Test
  public void shouldResetOwnPresenceWhenLoggedOut() {
    session.setLoggedIn(uri("myself@domain"));
    final Presence newOwn = new Presence();
    newOwn.setStatus("status");
    newOwn.setShow(Show.away);
    manager.changeOwnPresence(newOwn);
    assertEquals("status", manager.getOwnPresence().getStatus());
    session.logout();
    assertEquals(Presence.Type.unavailable, manager.getOwnPresence().getType());
  }
View Full Code Here

      }
    } else {
      if ("message".equals(name)) {
        eventBus.fireEventFromSource(new MessageReceivedEvent(new Message(stanza)), this);
      } else if ("presence".equals(name)) {
        eventBus.fireEventFromSource(new PresenceReceivedEvent(new Presence(stanza)), this);
      } else if ("iq".equals(name)) {
        final IQ iq = new IQ(stanza);
        final IQ.Type type = iq.getType();
        if (IQ.Type.get.equals(type) || IQ.Type.set.equals(type)) {
          eventBus.fireEventFromSource(new IQRequestReceivedEvent(iq), this);
View Full Code Here

   * Show values unknown and show should never be serialized to the stanza.
   * Issue 264
   */
  @Test
  public void shouldSetShowCorrectly() {
    final Presence presence = new Presence();
    presence.setShow(Show.unknown);
    assertEquals(-1, presence.toString().indexOf("unknown"));
  }
View Full Code Here

    assertEquals(-1, presence.toString().indexOf("unknown"));
  }

  @Test
  public void shouldSetStatus() {
    final Presence presence = new Presence();
    presence.setStatus("the status");
    assertEquals("the status", presence.getStatus());
    presence.setStatus("the status2");
    assertEquals("the status2", presence.getStatus());
  }
View Full Code Here

    assertEquals("the status2", presence.getStatus());
  }

  @Test
  public void shouldSetType() {
    final Presence presence = new Presence();
    for (final Type type : Type.values()) {
      presence.setType(type);
      assertEquals(type, presence.getType());
    }
  }
View Full Code Here

public class PresenceTest {

  @Test
  public void shouldGetPriority() {
    Presence presence = new Presence();
    assertEquals(0, presence.getPriority());
    presence = new Presence(XMLBuilder.create("presence").childText("priority", "5").getXML());
    assertEquals(5, presence.getPriority());
    presence = new Presence(XMLBuilder.create("presence").childText("priority", "not valid").getXML());
    assertEquals(0, presence.getPriority());
  }
View Full Code Here

    assertEquals(0, presence.getPriority());
  }

  @Test
  public void shouldGetShow() {
    Presence presence = new Presence();
    assertEquals(Show.notSpecified, presence.getShow());
    presence = new Presence(XMLBuilder.create("presence").childText("show", Show.chat.toString()).getXML());
    assertEquals(Show.chat, presence.getShow());
    presence = new Presence(XMLBuilder.create("presence").childText("show", "not valid show").getXML());
    assertEquals(Show.unknown, presence.getShow());
  }
View Full Code Here

TOP

Related Classes of com.calclab.emite.core.stanzas.Presence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.