Search in sources :

Example 11 with Message

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

the class HeadersProviderTest method headersInMessageTest.

@Test
public void headersInMessageTest() throws Exception {
    // @formatter:off
    final String messageStanza = "<message from='romeo@shakespeare.lit/orchard' to='juliet@capulet.com' type='chat'>" + "<body>Wherefore are thou?!?</body>" + "<headers xmlns='http://jabber.org/protocol/shim'>" + "<header name='Urgency'>high</header>" + "</headers>" + "</message>";
    // @formatter:on
    XmlPullParser parser = TestUtils.getMessageParser(messageStanza);
    Message message = PacketParserUtils.parseMessage(parser);
    HeadersExtension headers = HeadersExtension.from(message);
    Header header = headers.getHeaders().get(0);
    assertEquals("Urgency", header.getName());
    assertEquals("high", header.getValue());
}
Also used : HeadersExtension(org.jivesoftware.smackx.shim.packet.HeadersExtension) Message(org.jivesoftware.smack.packet.Message) Header(org.jivesoftware.smackx.shim.packet.Header) XmlPullParser(org.xmlpull.v1.XmlPullParser) Test(org.junit.Test)

Example 12 with Message

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

the class GeoLocationManager method sendGeoLocationToJid.

public void sendGeoLocationToJid(GeoLocation geoLocation, Jid jid) throws InterruptedException, NotConnectedException {
    final XMPPConnection connection = connection();
    Message geoLocationMessage = new Message(jid);
    geoLocationMessage.addExtension(geoLocation);
    connection.sendStanza(geoLocationMessage);
}
Also used : Message(org.jivesoftware.smack.packet.Message) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 13 with Message

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

the class MultiUserChat method requestVoice.

/**
     * Sends a voice request to the MUC. The room moderators usually need to approve this request.
     *
     * @throws NotConnectedException
     * @throws InterruptedException 
     * @see <a href="http://xmpp.org/extensions/xep-0045.html#requestvoice">XEP-45 ยง 7.13 Requesting
     *      Voice</a>
     * @since 4.1
     */
public void requestVoice() throws NotConnectedException, InterruptedException {
    DataForm form = new DataForm(DataForm.Type.submit);
    FormField formTypeField = new FormField(FormField.FORM_TYPE);
    formTypeField.addValue(MUCInitialPresence.NAMESPACE + "#request");
    form.addField(formTypeField);
    FormField requestVoiceField = new FormField("muc#role");
    requestVoiceField.setType(FormField.Type.text_single);
    requestVoiceField.setLabel("Requested role");
    requestVoiceField.addValue("participant");
    form.addField(requestVoiceField);
    Message message = new Message(room);
    message.addExtension(form);
    connection.sendStanza(message);
}
Also used : Message(org.jivesoftware.smack.packet.Message) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FormField(org.jivesoftware.smackx.xdata.FormField)

Example 14 with Message

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

the class ChatStateManager method setCurrentState.

/**
     * Sets the current state of the provided chat. This method will send an empty bodied Message
     * stanza(/packet) 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 
     * @throws InterruptedException 
     */
public void setCurrentState(ChatState newState, org.jivesoftware.smack.chat.Chat chat) throws NotConnectedException, InterruptedException {
    if (chat == null || newState == null) {
        throw new IllegalArgumentException("Arguments cannot be null.");
    }
    if (!updateChatState(chat, newState)) {
        return;
    }
    Message message = new Message();
    ChatStateExtension extension = new ChatStateExtension(newState);
    message.addExtension(extension);
    chat.sendMessage(message);
}
Also used : Message(org.jivesoftware.smack.packet.Message) ChatStateExtension(org.jivesoftware.smackx.chatstates.packet.ChatStateExtension)

Example 15 with Message

use of org.jivesoftware.smack.packet.Message in project Openfire by igniterealtime.

the class XMPPSession method sendChatState.

/**
     * @see net.sf.kraken.session.TransportSession#sendChatState(org.xmpp.packet.JID, net.sf.kraken.type.ChatStateType)
     */
@Override
public void sendChatState(JID jid, ChatStateType chatState) {
    final Presence presence = conn.getRoster().getPresence(jid.toString());
    if (presence == null || presence.getType().equals(Presence.Type.unavailable)) {
        // don't send chat state to contacts that are offline.
        return;
    }
    Chat chat = conn.getChatManager().createChat(getTransport().convertJIDToID(jid), listener);
    try {
        ChatState state = ChatState.active;
        switch(chatState) {
            case active:
                state = ChatState.active;
                break;
            case composing:
                state = ChatState.composing;
                break;
            case paused:
                state = ChatState.paused;
                break;
            case inactive:
                state = ChatState.inactive;
                break;
            case gone:
                state = ChatState.gone;
                break;
        }
        Message message = new Message();
        message.addExtension(new ChatStateExtension(state));
        chat.sendMessage(message);
    } catch (XMPPException e) {
    // Ignore
    }
}
Also used : ChatState(org.jivesoftware.smackx.ChatState) Message(org.jivesoftware.smack.packet.Message) ChatStateExtension(org.jivesoftware.smackx.packet.ChatStateExtension) Presence(org.jivesoftware.smack.packet.Presence)

Aggregations

Message (org.jivesoftware.smack.packet.Message)142 Test (org.junit.Test)57 Presence (org.jivesoftware.smack.packet.Presence)17 StanzaCollector (org.jivesoftware.smack.StanzaCollector)14 MessageTypeFilter (org.jivesoftware.smack.filter.MessageTypeFilter)12 Stanza (org.jivesoftware.smack.packet.Stanza)12 XMPPException (org.jivesoftware.smack.XMPPException)11 XMPPConnection (org.jivesoftware.smack.XMPPConnection)9 Date (java.util.Date)8 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)8 AccountItem (com.xabber.android.data.account.AccountItem)7 Chat (org.jivesoftware.smack.Chat)7 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)7 XmlPullParser (org.xmlpull.v1.XmlPullParser)7 ArrayList (java.util.ArrayList)6 Jid (org.jxmpp.jid.Jid)6 NetworkException (com.xabber.android.data.NetworkException)5 Forwarded (org.jivesoftware.smackx.forward.packet.Forwarded)5 GeoLocation (org.jivesoftware.smackx.geoloc.packet.GeoLocation)5 IOException (java.io.IOException)4