Search in sources :

Example 6 with MessageBuilder

use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.

the class StableUniqueStanzaIdTest method fromMessageTest.

@Test
public void fromMessageTest() {
    MessageBuilder messageBuilder = StanzaBuilder.buildMessage();
    Message message = messageBuilder.build();
    assertFalse(OriginIdElement.hasOriginId(message));
    assertFalse(StanzaIdElement.hasStanzaId(message));
    OriginIdElement.addTo(messageBuilder);
    message = messageBuilder.build();
    assertTrue(OriginIdElement.hasOriginId(message));
    StanzaIdElement stanzaId = new StanzaIdElement("alice@wonderland.lit");
    message.addExtension(stanzaId);
    assertTrue(StanzaIdElement.hasStanzaId(message));
    assertEquals(stanzaId, StanzaIdElement.getStanzaId(message));
}
Also used : MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) Message(org.jivesoftware.smack.packet.Message) StanzaIdElement(org.jivesoftware.smackx.sid.element.StanzaIdElement) Test(org.junit.jupiter.api.Test)

Example 7 with MessageBuilder

use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.

the class MultiUserChatManager method decline.

/**
 * Informs the sender of an invitation that the invitee declines the invitation. The rejection will be sent to the
 * room which in turn will forward the rejection to the inviter.
 *
 * @param room the room that sent the original invitation.
 * @param inviter the inviter of the declined invitation.
 * @param reason the reason why the invitee is declining the invitation.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void decline(EntityBareJid room, EntityBareJid inviter, String reason) throws NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();
    MessageBuilder messageBuilder = connection.getStanzaFactory().buildMessageStanza().to(room);
    // Create the MUCUser packet that will include the rejection
    MUCUser mucUser = new MUCUser();
    MUCUser.Decline decline = new MUCUser.Decline(reason, inviter);
    mucUser.setDecline(decline);
    // Add the MUCUser packet that includes the rejection
    messageBuilder.addExtension(mucUser);
    connection.sendStanza(messageBuilder.build());
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 8 with MessageBuilder

use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.

the class Chat method sendMessage.

/**
 * Sends the specified text as a message to the other chat participant.
 * This is a convenience method for:
 *
 * <pre>
 *     Message message = chat.createMessage();
 *     message.setBody(messageText);
 *     chat.sendMessage(message);
 * </pre>
 *
 * @param text the text to send.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void sendMessage(String text) throws NotConnectedException, InterruptedException {
    MessageBuilder message = StanzaBuilder.buildMessage().setBody(text);
    sendMessage(message);
}
Also used : MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder)

Example 9 with MessageBuilder

use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.

the class ChatConnectionTest method validateMessageTypeWithDefaults1.

@Test
public void validateMessageTypeWithDefaults1() {
    MessageBuilder incomingChat = createChatPacket("134", true);
    incomingChat.ofType(Message.Type.chat);
    processServerMessage(incomingChat.build());
    assertNotNull(listener.getNewChat());
}
Also used : MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) Test(org.junit.Test)

Example 10 with MessageBuilder

use of org.jivesoftware.smack.packet.MessageBuilder in project Smack by igniterealtime.

the class ChatConnectionTest method chatNotMatchedWithTypeNormal.

@Test
public void chatNotMatchedWithTypeNormal() {
    cm.setNormalIncluded(false);
    MessageBuilder incomingChat = createChatPacket(null, false);
    incomingChat.ofType(Message.Type.normal);
    processServerMessage(incomingChat.build());
    assertNull(listener.getNewChat());
}
Also used : MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) Test(org.junit.Test)

Aggregations

MessageBuilder (org.jivesoftware.smack.packet.MessageBuilder)34 Message (org.jivesoftware.smack.packet.Message)10 XMPPConnection (org.jivesoftware.smack.XMPPConnection)9 Test (org.junit.jupiter.api.Test)8 Test (org.junit.Test)7 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)5 Stanza (org.jivesoftware.smack.packet.Stanza)3 RosterExchange (org.jivesoftware.smackx.xroster.packet.RosterExchange)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Date (java.util.Date)2 DummyConnection (org.jivesoftware.smack.DummyConnection)2 AndFilter (org.jivesoftware.smack.filter.AndFilter)2 XmlElement (org.jivesoftware.smack.packet.XmlElement)2 OpenPgpMessage (org.jivesoftware.smackx.ox.OpenPgpMessage)2 EntityBareJid (org.jxmpp.jid.EntityBareJid)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1