Java Code Examples for org.jivesoftware.smack.packet.Message#setTo()
The following examples show how to use
org.jivesoftware.smack.packet.Message#setTo() .
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: Chat.java From Smack with Apache License 2.0 | 6 votes |
public void send(Message message) throws NotConnectedException, InterruptedException { switch (message.getType()) { case normal: case chat: break; default: throw new IllegalArgumentException("Message must be of type 'normal' or 'chat'"); } Jid to = lockedResource; if (to == null) { to = jid; } message.setTo(to); connection().sendStanza(message); }
Example 2
Source File: OperationSetTypingNotificationsJabberImpl.java From jitsi with Apache License 2.0 | 6 votes |
/** * Creates and sends a packet for the new chat state. * @param chatState the new chat state. * @param jid the JID of the receiver. */ private void setCurrentState(ChatState chatState, Jid jid) throws NotConnectedException, InterruptedException { String threadID = opSetBasicIM.getThreadIDForAddress(jid.asBareJid()); if(threadID == null) return; Message message = new Message(); ChatStateExtension extension = new ChatStateExtension(chatState); message.addExtension(extension); message.setTo(jid); message.setType(Message.Type.chat); message.setThread(threadID); message.setFrom(parentProvider.getConnection().getUser()); parentProvider.getConnection().sendStanza(message); }
Example 3
Source File: ChatRoom.java From Spark with Apache License 2.0 | 6 votes |
/** * 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: OTREngineHost.java From Spark with Apache License 2.0 | 6 votes |
@Override public void injectMessage(SessionID arg0, String arg1) { Message injection = new Message(); injection.setType(Message.Type.chat); injection.setTo(_chatRoom.getParticipantJID()); injection.setFrom(SparkManager.getSessionManager().getJID()); String threadID = StringUtils.randomString(6); injection.setThread(threadID); injection.setBody(arg1); try { SparkManager.getConnection().sendStanza(injection); } catch ( SmackException.NotConnectedException e ) { Log.warning( "Unable to send injection to " + injection.getTo(), e ); } }
Example 5
Source File: Chat.java From Smack with Apache License 2.0 | 5 votes |
/** * Sends a message to the other chat participant. The thread ID, recipient, * and message type of the message will automatically set to those of this chat. * * @param message the message to send. * @throws NotConnectedException if the XMPP connection is not connected. * @throws InterruptedException if the calling thread was interrupted. */ public void sendMessage(Message message) throws NotConnectedException, InterruptedException { // Force the recipient, message type, and thread ID since the user elected // to send the message through this chat object. message.setTo(participant); message.setType(Message.Type.chat); message.setThread(threadID); chatManager.sendMessage(this, message); }
Example 6
Source File: FakePacketTransmitter.java From saros with GNU General Public License v2.0 | 5 votes |
@Override public void sendPacketExtension(JID jid, PacketExtension extension) { Message message = new Message(); message.addExtension(extension); message.setTo(jid.toString()); try { sendPacket(message); } catch (IOException e) { throw new RuntimeException(e); } }
Example 7
Source File: GroupChatRoom.java From Spark with Apache License 2.0 | 5 votes |
/** * Sends a message. * * @param message - the message to send. */ @Override public void sendMessage( Message message ) { try { message.setTo( chat.getRoom() ); message.setType( Message.Type.groupchat ); MessageEventManager.addNotificationsRequests( message, true, true, true, true ); addPacketID( message.getStanzaId() ); SparkManager.getChatManager().filterOutgoingMessage( this, message ); SparkManager.getChatManager().fireGlobalMessageSentListeners( this, message ); chat.sendMessage( message ); } catch ( SmackException | InterruptedException ex ) { Log.error( "Unable to send message in conference chat.", ex ); } // Notify users that message has been sent. fireMessageSent( message ); addToTranscript( message, false ); getChatInputEditor().clear(); getTranscriptWindow().validate(); getTranscriptWindow().repaint(); getChatInputEditor().setCaretPosition( 0 ); getChatInputEditor().requestFocusInWindow(); scrollToBottom(); lastActivity = System.currentTimeMillis(); }
Example 8
Source File: ChatRoom.java From Spark with Apache License 2.0 | 5 votes |
/** * 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 9
Source File: BuzzRoomDecorator.java From Spark with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent e) { Jid jid; try { jid = JidCreate.from(((ChatRoomImpl)chatRoom).getParticipantJID()); } catch (XmppStringprepException exception) { throw new IllegalStateException(exception); } Message message = new Message(); message.setTo(jid); message.addExtension(new BuzzPacket()); try { SparkManager.getConnection().sendStanza(message); } catch ( SmackException.NotConnectedException | InterruptedException e1 ) { Log.warning( "Unable to send stanza to " + jid, e1 ); } chatRoom.getTranscriptWindow().insertNotificationMessage(Res.getString("message.buzz.sent"), ChatManager.NOTIFICATION_COLOR); buzzButton.setEnabled(false); // Enable the button after 30 seconds to prevent abuse. final TimerTask enableTask = new SwingTimerTask() { @Override public void doRun() { buzzButton.setEnabled(true); } }; TaskEngine.getInstance().schedule(enableTask, 30000); }
Example 10
Source File: ReversiPanel.java From Spark with Apache License 2.0 | 5 votes |
/** * Sends a forfeit message to the other player. */ public void sendForfeit() throws SmackException.NotConnectedException { DefaultExtensionElement forfeit = new DefaultExtensionElement(GameForfeit.ELEMENT_NAME, GameForfeit.NAMESPACE); forfeit.setValue("gameID", Integer.toString(gameID)); Message message = new Message(); message.setTo(opponentJID); message.addExtension(forfeit); try { connection.sendStanza(message); } catch (InterruptedException e) { throw new IllegalStateException(e); } connection.removeAsyncStanzaListener(gameMoveListener); }
Example 11
Source File: GUI.java From Spark with Apache License 2.0 | 5 votes |
private Message createAnswer(MovePacket incoming, String from) { Message answer = new Message(); answer.setTo(from); MoveAnswerPacket map = new MoveAnswerPacket(); map.setGameID(incoming.getGameID()); map.setPositionX(incoming.getPositionX()); map.setPositionY(incoming.getPositionY()); return answer; }
Example 12
Source File: CoBrowser.java From Spark with Apache License 2.0 | 5 votes |
private void send(Message message) { GroupChatRoom groupChatRoom = (GroupChatRoom)chatRoom; try { message.setTo(groupChatRoom.getRoomname()); message.setType(Message.Type.groupchat); MessageEventManager.addNotificationsRequests(message, true, true, true, true); groupChatRoom.getMultiUserChat().sendMessage(message); } catch (SmackException | InterruptedException ex) { Log.error("Unable to send message in conference chat.", ex); } }