Package com.calclab.emite.core.stanzas

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


  @Override
  public void onBeforeMessageSent(final BeforeMessageSentEvent event) {
    // Only Messages are listened not presence events
    // But sendStateMessage goes through here.
    final Message message = event.getMessage();
    final boolean alreadyWithState = getStateFromMessage(message) != null;
    if (!alreadyWithState && ownState != ChatState.active && message.getXML().getFirstChild(bodySubjectThreadMatchter) != null) {
      if (ownState == ChatState.composing) {
        pauseTimer.cancel();
      }

      logger.finer("Setting own status to: " + ownState + " because we send a body or a subject");
      ownState = ChatState.active;
      message.getXML().addChild(ChatState.active.toString(), XmppNamespaces.CHATSTATES);
    }
    if (ownState != ChatState.inactive) {
      inactiveTimer.schedule(inactiveDelay);
    }
  }
View Full Code Here


    }
  }

  @Override
  public void onMessageReceived(final MessageReceivedEvent event) {
    final Message message = event.getMessage();
    final ChatState state = getStateFromMessage(message);
    if (state != null) {
      final XmppURI from = message.getFrom();
      othersState.put(from, state);
      eventBus.fireEventFromSource(new RoomChatStateNotificationEvent(message.getFrom(), state), this);
    }
  }
View Full Code Here

    // However, every content message SHOULD contain an <active/>
    // notification.
    if (ownState == null || !ownState.equals(chatState)) {
      ownState = chatState;
      logger.finer("Setting own status to: " + chatState.toString());
      final Message message = new Message();
      message.setTo(room.getRoomURI());
      message.getXML().addChild(chatState.toString(), XmppNamespaces.CHATSTATES);
      room.send(message);
    }
    if (ownState == ChatState.composing) {
      pauseTimer.schedule(pauseDelay);
    }
View Full Code Here

    }
  }
 
  @Override
  public final void onMessageReceived(final MessageReceivedEvent event) {
    final Message message = event.getMessage();
   
    final XMLPacket x = message.getExtension("x", XmppNamespaces.MUC_USER);
    if (x != null && x.hasChild("invite")) {
      final XMLPacket invite = x.getFirstChild("invite");
      final RoomInvitation invitation = new RoomInvitation(XmppURI.uri(invite.getAttribute("from")), message.getFrom(), invite.getChildText("reason"));
      eventBus.fireEventFromSource(new RoomInvitationReceivedEvent(invitation), this);
      return;
    }
   
    final RoomChat chat = getRoom(message.getFrom());
    if (chat != null) {
      chat.receiveMessage(message);
    }
  }
View Full Code Here

    chat.addBeforeMessageSentHandler(this);
  }

  @Override
  public void onMessageReceived(final MessageReceivedEvent event) {
    final Message message = event.getMessage();

    for (final ChatState chatState : ChatState.values()) {
      final String typeSt = chatState.toString();
      // TODO: check namespace
      if (message.getXML().hasChild(typeSt) || message.getXML().hasChild("cha:" + typeSt)) {
        otherState = chatState;
        if (negotiationStatus.equals(NegotiationStatus.notStarted)) {
          sendStateMessage(ChatState.active);
        }
        if (chatState.equals(ChatState.gone)) {
View Full Code Here

    }
  }

  @Override
  public void onBeforeMessageSent(final BeforeMessageSentEvent event) {
    final Message message = event.getMessage();

    switch (negotiationStatus) {
    case notStarted:
      negotiationStatus = NegotiationStatus.started;
      //$FALL-THROUGH$
    case accepted:
      boolean alreadyWithState = false;
      for (final ChatState state : ChatState.values()) {
        if (message.getXML().hasChild(state.toString())) {
          alreadyWithState = true;
        }
      }
      if (!alreadyWithState) {
        message.getXML().addChild(ChatState.active.toString(), XmppNamespaces.CHATSTATES);
      }
      break;
    case rejected:
    case started:
      // do nothing
View Full Code Here

    }
  }
 
  @Override
  public final void onMessageReceived(final MessageReceivedEvent event) {
    final Message message = event.getMessage();
   
    if (Message.Type.groupchat.equals(message.getType()))
      return;
   
    PairChat chat = getChat(message.getFrom());
    if (chat == null && message.getBody() != null) {
      // we need to create a chat for this incoming message
      chat = openChat(message.getFrom());
    }
   
    if (chat != null) {
      chat.receiveMessage(message);
    }
View Full Code Here

  @Test
  public void shouldFireListenersWhenMessage() {
    final MessageReceivedTestHandler handler = new MessageReceivedTestHandler();
    room.addMessageReceivedHandler(handler);
    final Message message = new Message("message", uri("room@domain"), uri("someone@domain/res"));
    eventBus.fireEvent(new MessageReceivedEvent(message));
    assertEquals(message, handler.getLastMessage());
  }
View Full Code Here

  public void shouldFireListenersWhenSubjectChange() {
    final RoomSubjectChangedTestHandler handler = new RoomSubjectChangedTestHandler();
    room.addRoomSubjectChangedHandler(handler);

    final XmppURI occupantURI = uri("someone@domain/res");
    final Message subject = new Message(null, uri("room@domain"), occupantURI);
    subject.setSubject("the subject");
    eventBus.fireEvent(new MessageReceivedEvent(subject));
    assertEquals(1, handler.getCalledTimes());

    assertEquals(occupantURI, handler.getLastEvent().getOccupantUri());
    assertEquals("the subject", handler.getLastEvent().getSubject());
View Full Code Here

        + "<message from='self@domain/res' to='other@domain/other' type='chat'>" + "<pause xmlns='http://jabber.org/protocol/chatstates'/></message>");
  }

  @Test
  public void shouldStartStateAfterNegotiation() {
    chat.send(new Message("test message"));
    session.receives("<message from='other@domain/other' to='self@domain/res' type='chat'>"
        + "<active xmlns='http://jabber.org/protocol/chatstates'/></message>");
    final Message message = new Message("test message", OTHER, MYSELF);
    message.getXML().addChild(ChatStateHook.ChatState.active.toString(), "http://jabber.org/protocol/chatstates");
    chatStateHook.setOwnState(ChatStateHook.ChatState.composing);
    session.verifySent(message.toString() + "<message from='self@domain/res' to='other@domain/other' type='chat'>"
        + "<composing xmlns='http://jabber.org/protocol/chatstates'/></message>");
  }
View Full Code Here

TOP

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

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.