org.jivesoftware.smack.packet.Message Java Examples

The following examples show how to use org.jivesoftware.smack.packet.Message. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SendMessage.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    // sending message
    String recipient = sampler.getPropertyAsString(RECIPIENT);
    String body = sampler.getPropertyAsString(BODY);
    boolean wait_response = sampler.getPropertyAsBoolean(WAIT_RESPONSE);
    if (wait_response) {
        body += "\r\n" + System.currentTimeMillis() + "@" + NEED_RESPONSE_MARKER;
    }

    Message msg = new Message(recipient);
    msg.setType(Message.Type.fromString(sampler.getPropertyAsString(TYPE, Message.Type.normal.toString())));
    msg.addBody("", body);
    res.setSamplerData(msg.toXML().toString());
    sampler.getXMPPConnection().sendPacket(msg);
    res.setSamplerData(msg.toXML().toString()); // second time to reflect the changes made to packet by conn

    if (wait_response) {
        return waitResponse(res, recipient);
    }
    return res;
}
 
Example #2
Source File: MamResultProviderTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Test
public void checkResultsParse() throws Exception {
    Message message = PacketParserUtils.parseStanza(exampleResultMessage);
    MamResultExtension mamResultExtension = MamResultExtension.from(message);

    assertEquals(mamResultExtension.getQueryId(), "f27");
    assertEquals(mamResultExtension.getId(), "28482-98726-73623");

    GregorianCalendar calendar = new GregorianCalendar(2010, 7 - 1, 10, 23, 8, 25);
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    Date date = calendar.getTime();

    Forwarded forwarded = mamResultExtension.getForwarded();
    assertEquals(forwarded.getDelayInformation().getStamp(), date);

    Message forwardedMessage = (Message) forwarded.getForwardedStanza();
    assertEquals(forwardedMessage.getFrom().toString(), "[email protected]");
    assertEquals(forwardedMessage.getTo().toString(), "[email protected]");
    assertEquals(forwardedMessage.getBody(), "Hail to thee");
}
 
Example #3
Source File: ChatRoom.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Add a <code>ChatResponse</chat> to the current discussion chat area.
 *
 * @param message    the message to add to the transcript list
 * @param updateDate true if you wish the date label to be updated with the
 *                   date and time the message was received.
 */
public void addToTranscript(Message message, boolean updateDate) {
    // Create message to persist.
    final Message newMessage = new Message();
    newMessage.setTo(message.getTo());
    newMessage.setFrom(message.getFrom());
    newMessage.setBody(message.getBody());
    final Map<String, Object> properties = new HashMap<>();
    properties.put( "date", new Date() );
    newMessage.addExtension( new JivePropertiesExtension( properties ) );

    transcript.add(newMessage);

    // Add current date if this is the current agent
    if (updateDate && transcriptWindow.getLastUpdated() != null) {
        // Set new label date
        notificationLabel.setIcon(SparkRes.getImageIcon(SparkRes.SMALL_ABOUT_IMAGE));
        notificationLabel.setText(Res.getString("message.last.message.received", SparkManager.DATE_SECOND_FORMATTER.format(transcriptWindow.getLastUpdated())));
    }

    scrollToBottom();
}
 
Example #4
Source File: BoBExtension.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
    XmlStringBuilder xml = new XmlStringBuilder(this);
    xml.rightAngleBracket();

    xml.halfOpenElement(Message.BODY);
    xml.xmlnsAttribute(XHTMLText.NAMESPACE);
    xml.rightAngleBracket();

    xml.openElement(XHTMLText.P);
    xml.optEscape(paragraph);

    xml.halfOpenElement(XHTMLText.IMG);
    xml.optAttribute("alt", alt);
    xml.attribute("src", bobHash.toSrc());
    xml.closeEmptyElement();

    xml.closeElement(XHTMLText.P);
    xml.closeElement(Message.BODY);
    xml.closeElement(this);
    return xml;
}
 
Example #5
Source File: MucChatService.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void createNewRoom(Message message) {
	Room room = new Room();
	room.setLastMessage("被加入新群组");
	room.setLastChatAt(System.currentTimeMillis());
	room.setMsgSum(0);
	room.setName(mucGetInfo(message.getFrom().toString()).getName());
	room.setRoomId(message.getFrom().asEntityBareJidIfPossible().toString()); // 注意邀请消息和muc消息的from不同
	room.setTotalReadCount(0);
	room.setUpdatedAt("2018-01-01T06:38:55.119Z");
	room.setType("m");
	room.setUnreadCount(0);
	room.setCreatorName(JID.usernameByJid(message.getFrom().asEntityBareJidIfPossible().toString()));
	room.setCreatorId(JID.usernameByJid(message.getFrom().asEntityBareJidIfPossible().toString()));

	Launcher.roomService.insertOrUpdate(room);

	updateLeftAllUI();
}
 
Example #6
Source File: MucChatService.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void join(Message message) {
	// TODO 收到加入群的离线消息,被邀请进入群
	MucInvitation mi = message.getExtension("x", "xytalk:muc:invitation");
	String jid = mi.getRoomid();
	String roomname = mi.getRoomName();
	MultiUserChat muc;
	try {
		muc = MultiUserChatManager.getInstanceFor(Launcher.connection)
				.getMultiUserChat(JidCreate.entityBareFrom(jid));
		muc.join(Resourcepart.from(UserCache.CurrentUserName + "-" + UserCache.CurrentUserRealName));
		// 更新左侧panel,将群组UI新建出来
		createNewRoomByInvitation(jid, roomname);
	} catch (NotAMucServiceException | NoResponseException | XMPPErrorException | NotConnectedException
			| XmppStringprepException | InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
Example #7
Source File: SpoilerTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Test
public void i18nHintSpoilerTest() throws Exception {
    final String xml = "<spoiler xml:lang='de' xmlns='urn:xmpp:spoiler:0'>Der Kuchen ist eine Lüge!</spoiler>";

    Message message = StanzaBuilder.buildMessage().build();
    SpoilerElement.addSpoiler(message, "de", "Der Kuchen ist eine Lüge!");

    SpoilerElement i18nHint = (SpoilerElement) message.getExtensionElement(SpoilerElement.ELEMENT, SpoilerManager.NAMESPACE_0);

    assertEquals("Der Kuchen ist eine Lüge!", i18nHint.getHint());
    assertEquals("de", i18nHint.getLanguage());

    assertXmlSimilar(xml, i18nHint.toXML().toString());

    XmlPullParser parser = TestUtils.getParser(xml);
    SpoilerElement parsed = SpoilerProvider.INSTANCE.parse(parser);
    assertEquals(i18nHint.getLanguage(), parsed.getLanguage());

    assertXmlSimilar(xml, parsed.toXML().toString());
}
 
Example #8
Source File: SendMessage.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
private SampleResult waitResponse(SampleResult res, String recipient) throws InterruptedException, SmackException {
    long time = 0;
    do {
        Iterator<Message> packets = responseMessages.iterator();
        Thread.sleep(conn.getPacketReplyTimeout() / 100); // optimistic
        while (packets.hasNext()) {
            Packet packet = packets.next();
            Message response = (Message) packet;
            if (XmppStringUtils.parseBareAddress(response.getFrom()).equals(recipient)) {
                packets.remove();
                res.setResponseData(response.toXML().toString().getBytes());
                if (response.getError() != null) {
                    res.setSuccessful(false);
                    res.setResponseCode("500");
                    res.setResponseMessage(response.getError().toString());
                }
                return res;
            }
        }
        time += conn.getPacketReplyTimeout() / 10;
        Thread.sleep(conn.getPacketReplyTimeout() / 10);
    } while (time < conn.getPacketReplyTimeout());
    throw new SmackException.NoResponseException();
}
 
Example #9
Source File: ChatService.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void sendMessage(String roomId, String content,ExtensionElement ext) {
	EntityBareJid jid = null;
	try {
		jid = JidCreate.entityBareFrom(roomId);
	} catch (XmppStringprepException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	Chat chat = ChatManager.getInstanceFor(Launcher.connection).chatWith(jid);

	org.jivesoftware.smack.packet.Message message = new org.jivesoftware.smack.packet.Message();
	message.setType(Type.chat);
	message.addExtension(ext);
	message.setBody(content);
	try {
		chat.send(message);
		DebugUtil.debug("chat.sendMessage::" + message.toString());
	} catch (NotConnectedException | InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
Example #10
Source File: ChatService.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
private static void createNewRoom(org.jivesoftware.smack.packet.Message message) {

		String barejid = message.getFrom().asBareJid().toString();
		String fromUsername = JID.usernameByJid(barejid);

		Room room = new Room();
		room.setLastMessage(message.getBody());
		room.setLastChatAt(System.currentTimeMillis());
		room.setMsgSum(1);
		room.setName(Launcher.contactsUserService.findByUsername(fromUsername).getName());
		room.setRoomId(message.getFrom().asBareJid().toString());
		room.setTotalReadCount(0);
		room.setUpdatedAt("2018-01-01T06:38:55.119Z");
		room.setType("s");
		room.setUnreadCount(1);
		Launcher.roomService.insertOrUpdate(room);

		updateLeftAllUI();
	}
 
Example #11
Source File: XSCHelper.java    From PracticeCode with Apache License 2.0 6 votes vote down vote up
/**
 * 加入信息聊天室
 *
 * @param password 登录密码
 * @param roomName 房间名称
 * @param maxMsg   接收离线消息数
 * @param handler  处理信息的Handler
 */
public void joinChatRoom(final String roomName, final String password, final int maxMsg, final Handler handler) {
    joinRoom(roomName, password, 1, maxMsg, new Handler(){
        @Override
        public void handleMessage(android.os.Message msg) {
            android.os.Message message = new android.os.Message();
            message.what = msg.what;
            message.obj = msg.obj;
            switch (msg.what) {
                case FAILURE:
                    handler.sendEmptyMessage(FAILURE);
                    break;
                case SUCCESS:
                    handler.sendMessage(message);
                    break;
                case MESSAGE:
                    Bundle args = new Bundle();
                    args.putString(MSGFROM, ((Message) msg.obj).getFrom());
                    args.putString(MSGBODY, ((Message) msg.obj).getBody());
                    message.setData(args);
                    handler.sendMessage(message);
                    break;
            }
        }
    });
}
 
Example #12
Source File: XHTMLExtensionProvider.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
public XHTMLExtension parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws IOException, XmlPullParserException {
    XHTMLExtension xhtmlExtension = new XHTMLExtension();

    while (true) {
        XmlPullParser.Event eventType = parser.getEventType();
        String name = parser.getName();
        if (eventType == XmlPullParser.Event.START_ELEMENT) {
            if (name.equals(Message.BODY)) {
                xhtmlExtension.addBody(PacketParserUtils.parseElement(parser));
            }
        } else if (eventType == XmlPullParser.Event.END_ELEMENT) {
            if (parser.getDepth() == initialDepth) {
                return xhtmlExtension;
            }
        }
        parser.next();
    }
}
 
Example #13
Source File: JivePropertiesExtensionTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Test
public void checkProvider() throws Exception {
    // @formatter:off
    String properties = "<message xmlns='jabber:client' from='[email protected]/orchard' to='[email protected]/balcony'>"
                    + "<body>Neither, fair saint, if either thee dislike.</body>"
                    + "<properties xmlns='http://www.jivesoftware.com/xmlns/xmpp/properties'>"
                    + "<property>"
                    + "<name>FooBar</name>"
                    + "<value type='integer'>42</value>"
                    + "</property>"
                    + "</properties>"
                    + "</message>";
    // @formatter:on

    Message message = PacketParserUtils.parseStanza(properties);
    JivePropertiesExtension jpe = JivePropertiesExtension.from(message);
    assertNotNull(jpe);

    Integer integer = (Integer) jpe.getProperty("FooBar");
    assertNotNull(integer);
    int fourtytwo = integer;
    assertEquals(42, fourtytwo);
}
 
Example #14
Source File: SparkMeetPlugin.java    From Spark with Apache License 2.0 6 votes vote down vote up
@Override
public void messageReceived(ChatRoom room, Message message) {

    try {
        Localpart roomId = room.getRoomJid().getLocalpart();
        String body = message.getBody();

        if ( body.startsWith("https://") && body.endsWith("/" + roomId) ) {
            showInvitationAlert(message.getBody(), room, roomId);
        }


    } catch (Exception e) {
        // i don't care
    }

}
 
Example #15
Source File: MsgListener.java    From yiim_v2 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean accept(Packet packet) {
	// TODO Auto-generated method stub
	if (Message.class.isInstance(packet)) {
		Message message = (Message) packet;
		if (Message.Type.chat.equals(message.getType())
				|| Message.Type.groupchat.equals(message.getType())) {
			return true;
		}
	}
	return false;
}
 
Example #16
Source File: OperationSetTypingNotificationsJabberImpl.java    From jitsi with Apache License 2.0 5 votes vote down vote up
@Override
public void processStanza(Stanza packet)
{
    Message msg = (Message) packet;
    ChatStateExtension ext = (ChatStateExtension) msg.getExtension(
        "http://jabber.org/protocol/chatstates");
    if(ext == null)
        return;
    stateChanged(ChatState.valueOf(ext.getElementName()), msg);
}
 
Example #17
Source File: XSCHelper.java    From PracticeCode with Apache License 2.0 5 votes vote down vote up
/**
 * 加入工程云同步室
 *
 * @param handler  处理信息的Handler
 */
public void joinProjChromRoom(final Handler handler) {
    joinRoom(UserInfoBasic.account, null, 0, 25, new Handler() {
        @Override
        public void handleMessage(android.os.Message msg) {
            android.os.Message message = new android.os.Message();
            message.what = msg.what;
            message.obj = msg.obj;
            switch (msg.what) {
                case FAILURE:
                    handler.sendEmptyMessage(FAILURE);
                    break;
                case SUCCESS:
                    handler.sendMessage(message);
                    break;
                case MESSAGE:
                    String body = ((Message) message.obj).getBody();
                    message.obj = ((Message) message.obj).getProperty(MSGCLOUD);
                    Bundle args = new Bundle();
                    args.putString(MSGCLOUD_KEY, body);
                    message.setData(args);
                    handler.sendMessage(message);
                    break;
            }
        }
    });
}
 
Example #18
Source File: ChatRoom.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new message to the transcript history.
 *
 * @param to   who the message is to.
 * @param from who the message was from.
 * @param body the body of the message.
 * @param date when the message was received.
 */
public void addToTranscript(String to, String from, String body, Date date) {
    final Message newMessage = new Message();
    newMessage.setTo(to);
    newMessage.setFrom(from);
    newMessage.setBody(body);
    final Map<String, Object> properties = new HashMap<>();
    properties.put( "date", new Date() );
    newMessage.addExtension( new JivePropertiesExtension( properties ) );
    transcript.add(newMessage);
}
 
Example #19
Source File: Workspace.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new room based on an anonymous user.
 *
 * @param bareJID the bareJID of the anonymous user.
 * @param message the message from the anonymous user.
 */
private void createOneToOneRoom(EntityBareJid bareJID, Message message) {
    ContactItem contact = contactList.getContactItemByJID(bareJID);
    Localpart localpart = bareJID.getLocalpartOrNull();
    String nickname = null;
    if (localpart != null) {
        nickname = localpart.toString();
    }
    if (contact != null) {
        nickname = contact.getDisplayName();
    }
    else {
        // Attempt to load VCard from users who we are not subscribed to.
        VCard vCard = SparkManager.getVCardManager().getVCard(bareJID);
        if (vCard != null && vCard.getError() == null) {
            String firstName = vCard.getFirstName();
            String lastName = vCard.getLastName();
            String userNickname = vCard.getNickName();
            if (ModelUtil.hasLength(userNickname)) {
                nickname = userNickname;
            }
            else if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
                nickname = firstName + " " + lastName;
            }
            else if (ModelUtil.hasLength(firstName)) {
                nickname = firstName;
            }
        }
    }

    SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
    try {
        insertMessage(bareJID, message);
    }
    catch (ChatRoomNotFoundException e) {
        Log.error("Could not find chat room.", e);
    }
}
 
Example #20
Source File: MucChatService.java    From xyTalk-pc with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void updateMembers(org.jivesoftware.smack.packet.Message message) {
	
	MucUpdateMembers mum = message.getExtension("x", MucUpdateMembers.NAMESPACE);
	String memberUsernames = mum.getMemberUsernames();
	String roomid = mum.getRoomid();
	Room room = Launcher.roomService.findById(roomid);
	room.setMember(memberUsernames);
	Launcher.roomService.update(room);//保存DB
	
}
 
Example #21
Source File: SendMessage.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void setGuiFieldsFromSampler(JMeterXMPPSampler sampler) {
    msgRecipient.setText(sampler.getPropertyAsString(RECIPIENT));
    msgBody.setText(sampler.getPropertyAsString(BODY));
    waitResponse.setSelected(sampler.getPropertyAsBoolean(WAIT_RESPONSE));
    msgType.setSelectedItem(Message.Type.fromString(sampler.getPropertyAsString(TYPE, Message.Type.normal.toString())));
}
 
Example #22
Source File: JabberWorkItemHandlerTest.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
@Test(expected = WorkItemHandlerRuntimeException.class)
public void testSendMessageInvalidParams() throws Exception {
    ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class);

    doNothing().when(xmppConnection).connect();
    doNothing().when(xmppConnection).login(anyString(),
                                           anyString());
    doNothing().when(xmppConnection).sendPacket(any(Presence.class));
    doNothing().when(xmppConnection).disconnect();
    when(xmppConnection.getChatManager()).thenReturn(chatManager);
    when(chatManager.createChat(anyString(),
                                anyObject())).thenReturn(chat);

    TestWorkItemManager manager = new TestWorkItemManager();
    WorkItemImpl workItem = new WorkItemImpl();

    JabberWorkItemHandler handler = new JabberWorkItemHandler("", "");
    handler.setConf(connectionConf);
    handler.setConnection(xmppConnection);

    handler.executeWorkItem(workItem,
                            manager);

    assertNotNull(manager.getResults());
    assertEquals(0,
                 manager.getResults().size());
}
 
Example #23
Source File: ChatStateManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the current state of the provided chat. This method will send an empty bodied Message
 * stanza with the state attached as a {@link org.jivesoftware.smack.packet.ExtensionElement}, if
 * and only if the new chat state is different than the last state.
 *
 * @param newState the new state of the chat
 * @param chat the chat.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void setCurrentState(ChatState newState, Chat chat) throws NotConnectedException, InterruptedException {
    if (chat == null || newState == null) {
        throw new IllegalArgumentException("Arguments cannot be null.");
    }
    if (!updateChatState(chat, newState)) {
        return;
    }
    Message message = StanzaBuilder.buildMessage().build();
    ChatStateExtension extension = new ChatStateExtension(newState);
    message.addExtension(extension);

    chat.send(message);
}
 
Example #24
Source File: Workspace.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new room if necessary and inserts an offline message.
 *
 * @param message The Offline message.
 * @throws InterruptedException 
 */
private void handleOfflineMessage(Message message) throws SmackException.NotConnectedException, InterruptedException
{
    if(!ModelUtil.hasLength(message.getBody())){
        return;
    }

    EntityBareJid bareJID = message.getFrom().asEntityBareJidIfPossible();
    if (bareJID == null) {
        return;
    }
    ContactItem contact = contactList.getContactItemByJID(bareJID);
    Localpart nickname = bareJID.getLocalpartOrNull();
    if (contact != null) {
        nickname = Localpart.fromOrThrowUnchecked(contact.getDisplayName());
    }

    // Create the room if it does not exist.
    ChatRoom room = SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
    if(!SparkManager.getChatManager().getChatContainer().getChatFrame().isVisible())
    {
        SparkManager.getChatManager().getChatContainer().getChatFrame().setVisible(true);
    }

    // Insert offline message
    room.getTranscriptWindow().insertMessage(nickname, message, ChatManager.FROM_COLOR);
    room.addToTranscript(message, true);

    // Send display and notified message back.
    SparkManager.getMessageEventManager().sendDeliveredNotification(message.getFrom(), message.getStanzaId());
    SparkManager.getMessageEventManager().sendDisplayedNotification(message.getFrom(), message.getStanzaId());
}
 
Example #25
Source File: ChatActivity.java    From mangosta-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessageSent(Message message) {
    super.onMessageSent(message);
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            refreshMessagesAndScrollToEnd();
        }
    });
}
 
Example #26
Source File: ChatController.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * @param body
 *            - any text
 * @param from
 *            must be a valid jid
 * @return
 */
private Message createInstantMessage(final String body, final String from) {
    final Message message = new Message();
    message.setBody(body);
    message.setFrom(from);
    message.setProperty("receiveTime", new Long(new Date().getTime()));
    return message;
}
 
Example #27
Source File: SystemNotification.java    From Spark with Apache License 2.0 5 votes vote down vote up
@Override
public void messageReceived(ChatRoom room, Message message, PropertyBundle bundle) {

    String nickname = RoarPopupHelper.getNickname(room, message);
    //if (Spark.isMac()) {
    //    MacNotificationCenter.sendNotification(nickname, message.getBody());
    //} else {
        WindowsNotification.sendNotification(nickname, message.getBody());
    //}
}
 
Example #28
Source File: DeliveryReceiptTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Test
public void receiptTest() throws Exception {
    XmlPullParser parser;
    String control;

    control = XMLBuilder.create("message")
        .a("from", "[email protected]")
        .e("request")
            .a("xmlns", "urn:xmpp:receipts")
        .asString(outputProperties);

    parser = PacketParserUtils.getParserFor(control);
    Message p = PacketParserUtils.parseMessage(parser);

    DeliveryReceiptRequest drr = p.getExtension(DeliveryReceiptRequest.class);
    assertNotNull(drr);

    assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(p));

    MessageBuilder messageBuilder = StanzaBuilder.buildMessage("request-id")
            .to("[email protected]")
            .ofType(Message.Type.normal)
            ;
    assertFalse(DeliveryReceiptManager.hasDeliveryReceiptRequest(messageBuilder.build()));
    DeliveryReceiptRequest.addTo(messageBuilder);
    assertTrue(DeliveryReceiptManager.hasDeliveryReceiptRequest(messageBuilder.build()));
}
 
Example #29
Source File: XMPPConsole.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void processMessage(Chat chat, Message msg) {
    logger.debug("Received XMPP message: {} of type {}", msg.getBody(), msg.getType());
    if (msg.getType() == Message.Type.error || msg.getBody() == null) {
        return;
    }
    String cmd = msg.getBody();
    String[] args = cmd.split(" ");
    ConsoleInterpreter.handleRequest(args, new ChatConsole(chat));
}
 
Example #30
Source File: Workspace.java    From Spark with Apache License 2.0 5 votes vote down vote up
private void insertMessage(final BareJid bareJID, final Message message) throws ChatRoomNotFoundException {
    ChatRoom chatRoom = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
    chatRoom.insertMessage(message);
    int chatLength = chatRoom.getTranscriptWindow().getDocument().getLength();
    chatRoom.getTranscriptWindow().setCaretPosition(chatLength);
    chatRoom.getChatInputEditor().requestFocusInWindow();
}