Package org.jivesoftware.smack

Examples of org.jivesoftware.smack.Chat


        }

        for(String toUser : toUsers){

            ChatManager chatmanager = connection.getChatManager();
            Chat chat = chatmanager.createChat(toUser, null);

            try {
                // google bounces back the default message types, you must use chat
                Message msg = new Message(toUser, Message.Type.chat);
                msg.setBody(text);
                chat.sendMessage(msg);
                System.out.println("Message Sended");
            } catch (XMPPException e) {
                System.out.println("Failed to send message");
                // handle this how?
            }
View Full Code Here


                return false;
            }
        }

        for (int i = 0; i < send.size(); i++) {
            Chat chat = null;

            if (buddy instanceof MUCBuddyStatus) {
                MultiUserChat muc = ((MUCBuddyStatus) buddy).getMUC();
                chat = muc.createPrivateChat(buddy.getUser());
            } else {
                chat = (Chat) chats.get((String) send.get(i));
            }

            if (chat == null) {
                chat = BuddyList.getInstance().getConnection().createChat(
                        (String) send.get(i));
                chats.put((String) send.get(i), chat);
            }

            Message message = chat.createMessage();
            if (secureExtension.getData() != null) {
                message.setBody("[This message is encrypted]");
                message.addExtension(secureExtension);
            } else {
                message.setBody(text);
            }
            if (signedExtension.getData() != null) {
                message.addExtension(signedExtension);
            }


            if (buddy.isAskForDelivered()) {
                BuddyList.getInstance().putEventMessage(message.getPacketID(), message.getTo(), getDate(null), 1);
            }
            if (buddy.isAskForDisplayed()) {
                BuddyList.getInstance().putEventMessage(message.getPacketID(), message.getTo(), getDate(null), 2);
            }
            if (buddy.isAskForOffline()) {
                BuddyList.getInstance().putEventMessage(message.getPacketID(), message.getTo(), getDate(null), 3);
            }

            MessageEventManager.addNotificationsRequests(message, buddy.isAskForOffline(), buddy.isAskForDelivered(), buddy.isAskForDisplayed(), true);
            MessageSendingEvent event = new MessageSendingEvent(this);
            event.setMessage(message);
            com.valhalla.pluginmanager.PluginChain.fireEvent(event);

            try {
                if (BuddyList.getInstance().checkConnection()) {
                    chat.sendMessage(message);
                } else {
                    BuddyList.getInstance().connectionError();
                }
            } catch (XMPPException e) {
                com.valhalla.Logger.debug("Could not send message: "
View Full Code Here

      String jabberId = event.getCommand();
      chats.remove(jabberId);
      Component c = container.getComponent(jabberId);
      container.remove(c);
      InstantMessagingModule.getAdapter().getClientManager().deregisterControllerListener(getIdentity().getName(), source);
      Chat chat = chatCtr.getChatManager();
      if (chat != null) {
        Collection<MessageListener> listeners = chat.getListeners();
        for (Iterator<MessageListener> iterator = listeners.iterator(); iterator.hasNext();) {
          chat.removeMessageListener(iterator.next());
        }
      }
      //forward event also to main controller
      fireEvent(ureq, event);
    }
View Full Code Here

      listeners.remove(username+controller.hashCode());
  }
 
  public Chat createChat(final String username, String chatPartnerJid, final Controller controller) {
    ChatManager chatmanager = getInstantMessagingClient(username).getConnection().getChatManager();
    Chat chat = chatmanager.createChat(chatPartnerJid, new MessageListener() {

      public void processMessage(Chat chat, Message message) {
        message.setProperty("receiveTime", new Long(new Date().getTime()));
        GenericEventListener listener = listeners.get(username+controller.hashCode());
        listener.event(new InstantMessagingEvent(message, "chatmessage"));
View Full Code Here

      if (chatroom) {
        groupchat.sendMessage(buf.toString());
      } else {
        Iterator iter = chats.iterator();
        while (iter.hasNext()) {
          Chat chat = (Chat) iter.next();
          chat.sendMessage(buf.toString());
        }
      }

    } catch (Exception e) {
      errorHandler.error("Could not send message in IMAppender [" + name
View Full Code Here

    public void process(Exchange exchange) {
        String threadId = exchange.getExchangeId();

        try {
            Chat chat = endpoint.getConnection().getChatManager().getThreadChat(threadId);

            if (chat == null) {
                chat = endpoint.getConnection().getChatManager().createChat(getParticipant(), threadId, new MessageListener() {
                    public void processMessage(Chat chat, Message message) {
                        // not here to do conversation
                    }
                });
            }

            // TODO it would be nice if we could reuse the message from the exchange
            Message message = new Message();
            message.setTo(participant);
            message.setFrom(endpoint.getUser());
            message.setThread(threadId);
            message.setType(Message.Type.normal);

            endpoint.getBinding().populateXmppMessage(message, exchange);
            if (LOG.isDebugEnabled()) {
                LOG.debug(">>>> message: " + message.getBody());
            }

            chat.sendMessage(message);
        } catch (XMPPException e) {
            throw new RuntimeXmppException(e);
        }
    }
View Full Code Here

    public void process(Exchange exchange) {
        String threadId = exchange.getExchangeId();

        try {
            ChatManager chatManager = endpoint.getConnection().getChatManager();
            Chat chat = chatManager.getThreadChat(threadId);

            if (chat == null) {
                chat = chatManager.createChat(getParticipant(), threadId, new MessageListener() {
                    public void processMessage(Chat chat, Message message) {
                        // not here to do conversation
                    }
                });
            }

            // TODO it would be nice if we could reuse the message from the exchange
            Message message = new Message();
            message.setTo(participant);
            message.setThread(threadId);
            message.setType(Message.Type.normal);

            endpoint.getBinding().populateXmppMessage(message, exchange);
            if (LOG.isDebugEnabled()) {
                LOG.debug(">>>> message: " + message.getBody());
            }

            chat.sendMessage(message);
        } catch (XMPPException e) {
            throw new RuntimeXmppException(e);
        }
    }
View Full Code Here

                public boolean accept(Packet packet) {
                    return packet instanceof Presence;
                }
            });

            Chat chat = null;
            if (to != null) {
                Presence presence = new Presence(Presence.Type.subscribe);
                presence.setFrom(connection.getUser());
                String toEntity = to + "@vysper.org";
                presence.setTo(toEntity);
View Full Code Here

        try {
            // SmackConfiguration.setPacketReplyTimeout(1000);
            // XMPPConnection con = new XMPPConnection(config);
            XMPPConnection con = new XMPPConnection("localhost", 61222);
            con.login("amq-user", "amq-pwd");
            Chat chat = con.createChat("test@localhost");
            for (int i = 0; i < 10; i++) {
                System.out.println("Sending message: " + i);
                chat.sendMessage("Hello from Message: " + i);
            }
            System.out.println("Sent all messages!");
        } catch (XMPPException e) {
            if (block) {
                System.out.println("Caught: " + e);
View Full Code Here

        }

        for(String toUser : toUsers){

            ChatManager chatmanager = connection.getChatManager();
            Chat chat = chatmanager.createChat(toUser, null);

            try {
                // google bounces back the default message types, you must use chat
                Message msg = new Message(toUser, Message.Type.chat);
                msg.setBody(text);
                chat.sendMessage(msg);
                System.out.println("Message Sended");
            } catch (XMPPException e) {
                System.out.println("Failed to send message");
                // handle this how?
            }
View Full Code Here

TOP

Related Classes of org.jivesoftware.smack.Chat

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.