Package rocks.xmpp.core.stanza.model.client

Examples of rocks.xmpp.core.stanza.model.client.Message


                "         to='herbie@usrobots.lit/home'\n" +
                "         type='headline'>\n" +
                "  <attention xmlns='urn:xmpp:attention:0'/>\n" +
                "  <body>Why don't you answer, Herbie?</body>\n" +
                "</message>";
        Message message = unmarshal(xml, Message.class);
        Attention attention = message.getExtension(Attention.class);
        Assert.assertNotNull(attention);
    }
View Full Code Here


                "     <error type='cancel'>\n" +
                "       <remote-server-not-found\n" +
                "           xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>\n" +
                "     </error>\n" +
                "   </message>";
        Message message = unmarshal(xml, Message.class);
        Assert.assertNotNull(message.getError());
        Assert.assertEquals(message.getError().getType(), StanzaError.Type.CANCEL);
        Assert.assertTrue(message.getError().getCondition() instanceof RemoteServerNotFound);
    }
View Full Code Here

        xmppSession.addMessageListener(new MessageListener() {
            @Override
            public void handle(MessageEvent e) {
                if (e.isIncoming() && isEnabled()) {
                    Message message = e.getMessage();
                    Event event = message.getExtension(Event.class);
                    if (event != null) {
                        for (Item item : event.getItems()) {
                            Object payload = item.getPayload();
                            if (payload instanceof GeoLocation) {
                                // Notify the listeners about the reception.
                                for (GeoLocationListener geoLocationListener : geoLocationListeners) {
                                    try {
                                        geoLocationListener.geoLocationUpdated(new GeoLocationEvent(GeoLocationManager.this, (GeoLocation) payload, message.getFrom()));
                                    } catch (Exception ex) {
                                        logger.log(Level.WARNING, ex.getMessage(), ex);
                                    }
                                }
                            }
View Full Code Here

        this.xmppSession = xmppSession;

        xmppSession.addMessageListener(new MessageListener() {
            @Override
            public void handle(MessageEvent e) {
                Message message = e.getMessage();
                if (message.getType() == Message.Type.CHAT && message.getBody() != null && !message.getBody().isEmpty()) {
                    Jid chatPartner = e.isIncoming() ? message.getFrom() : message.getTo();
                    // If an entity receives such a message with a new or unknown ThreadID, it SHOULD treat the message as part of a new chat session.
                    // If an entity receives a message of type "chat" without a thread ID, then it SHOULD create a new session with a new thread ID (and include that thread ID in all the messages it sends within the new session).
                    String threadId = message.getThread() != null ? message.getThread() : UUID.randomUUID().toString();
                    if (chatPartner != null) {
                        Jid contact = chatPartner.asBareJid();
                        synchronized (chatSessions) {
                            // If there are no chat sessions with that contact yet, put the contact into the map.
                            if (!chatSessions.containsKey(contact)) {
                                chatSessions.put(contact, new HashMap<String, ChatSession>());
                            }
                            Map<String, ChatSession> chatSessionMap = chatSessions.get(contact);
                            if (!chatSessionMap.containsKey(threadId)) {
                                ChatSession chatSession = new ChatSession(chatPartner, threadId, xmppSession);
                                chatSessionMap.put(threadId, chatSession);
                                notifyChatSessionCreated(chatSession, e.isIncoming());
                            }
                            ChatSession chatSession = chatSessionMap.get(threadId);
                            if (e.isIncoming()) {
                                // Until and unless the user's client receives a reply from the contact, it SHOULD send any further messages to the contact's bare JID. The contact's client SHOULD address its replies to the user's full JID <user@domainpart/resourcepart> as provided in the 'from' address of the initial message.
                                chatSession.chatPartner = message.getFrom();
                            }
                            chatSession.notifyMessageListeners(message, e.isIncoming());
                        }
                    }
                }
View Full Code Here

        messageListener = new MessageListener() {
            @Override
            public void handle(MessageEvent e) {
                if (e.isIncoming()) {
                    Message message = e.getMessage();
                    if (message.getFrom().asBareJid().equals(roomJid)) {
                        if (message.getType() == AbstractMessage.Type.GROUPCHAT) {
                            // This is a <message/> stanza from the room JID (or from the occupant JID of the entity that set the subject), with a <subject/> element but no <body/> element
                            if (message.getSubject() != null && message.getBody() == null) {
                                Date date;
                                DelayedDelivery delayedDelivery = message.getExtension(DelayedDelivery.class);
                                if (delayedDelivery != null) {
                                    date = delayedDelivery.getTimeStamp();
                                } else {
                                    date = new Date();
                                }
                                notifySubjectChangeListeners(new SubjectChangeEvent(ChatRoom.this, message.getSubject(), message.getFrom().getResource(), delayedDelivery != null, date));
                            } else {
                                notifyMessageListeners(new MessageEvent(ChatRoom.this, message, true));
                            }
                        } else {
                            MucUser mucUser = message.getExtension(MucUser.class);
                            if (mucUser != null) {
                                Decline decline = mucUser.getDecline();
                                if (decline != null) {
                                    notifyInvitationDeclineListeners(new InvitationDeclineEvent(ChatRoom.this, roomJid, decline.getFrom(), decline.getReason()));
                                }
View Full Code Here

     * @param subject The subject.
     * @throws rocks.xmpp.core.stanza.model.StanzaException If the entity returned a stanza error.
     * @throws rocks.xmpp.core.session.NoResponseException  If the entity did not respond.
     */
    public void changeSubject(final String subject) throws XmppException {
        Message message = new Message(roomJid, Message.Type.GROUPCHAT);
        message.setSubject(subject);
        xmppSession.sendAndAwaitMessage(message, new StanzaFilter<Message>() {
            @Override
            public boolean accept(Message message) {
                return message.getSubject() != null && message.getSubject().equals(subject);
            }
        });
    }
View Full Code Here

     * Sends a message to the room.
     *
     * @param message The message text.
     */
    public void sendMessage(String message) {
        Message m = new Message(roomJid, Message.Type.GROUPCHAT);
        m.setBody(message);
        xmppSession.send(m);
    }
View Full Code Here

     * @param direct  True, if the message is sent directly to the invitee; false if it is mediated by the room.
     * @see <a href="http://xmpp.org/extensions/xep-0045.html#invite-direct">7.8.1 Direct Invitation</a>
     * @see <a href="http://xmpp.org/extensions/xep-0045.html#invite-mediated">7.8.2 Mediated Invitation</a>
     */
    public void invite(Jid invitee, String reason, boolean direct) {
        Message message;
        if (direct) {
            message = new Message(invitee, Message.Type.NORMAL);
            message.getExtensions().add(new DirectInvitation(roomJid, null, reason));
        } else {
            message = new Message(roomJid, Message.Type.NORMAL);
            message.getExtensions().add(MucUser.withInvites(new Invite(invitee, reason)));
        }
        xmppSession.send(message);
    }
View Full Code Here

     * Requests voice in a moderated room.
     *
     * @see <a href="http://xmpp.org/extensions/xep-0045.html#requestvoice">7.13 Requesting Voice</a>
     */
    public void requestVoice() {
        Message message = new Message(roomJid);
        DataForm dataForm = new DataForm(DataForm.Type.SUBMIT);
        RequestVoiceForm requestVoiceForm = new RequestVoiceForm(dataForm);
        requestVoiceForm.setRole(Role.PARTICIPANT);
        message.getExtensions().add(dataForm);
        xmppSession.send(message);
    }
View Full Code Here

                "      <item id='ae890ac52d0df67ed7cfdf51b644e901'>\n" +
                "      </item>\n" +
                "    </items>\n" +
                "  </event>\n" +
                "</message>\n";
        Message message = unmarshal(xml, Message.class);
        Assert.assertNotNull(message);
        Event pubSubEvent = message.getExtension(Event.class);
        Assert.assertNotNull(pubSubEvent);
        Assert.assertNotNull(pubSubEvent.getItems());
        Assert.assertEquals(pubSubEvent.getNode(), "princely_musings");
        Assert.assertEquals(pubSubEvent.getItems().size(), 1);
    }
View Full Code Here

TOP

Related Classes of rocks.xmpp.core.stanza.model.client.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.