Java Code Examples for org.jivesoftware.smack.packet.Message#setFrom()

The following examples show how to use org.jivesoftware.smack.packet.Message#setFrom() . 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: SendMessageTest.java    From jmeter-bzm-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void perform() throws Exception {
    SendMessage action = new SendMessage();
    XMPPConnectionMock connection = new XMPPConnectionMock();
    action.connected(connection);
    Message resp = new Message();
    resp.setFrom("[email protected]");
    resp.setBody(SendMessage.RESPONSE_MARKER);
    action.processPacket(resp);
    JMeterXMPPSampler sampler = new JMeterXMPPSamplerMock();
    sampler.getXMPPConnection().setFromMode(XMPPConnection.FromMode.USER);
    sampler.setProperty(SendMessage.RECIPIENT, "[email protected]");
    sampler.setProperty(SendMessage.WAIT_RESPONSE, true);
    SampleResult res = new SampleResult();
    action.perform(sampler, res);
    Assert.assertTrue(res.getResponseDataAsString().contains(SendMessage.RESPONSE_MARKER));
    Assert.assertTrue(res.getSamplerData().contains("from"));
}
 
Example 2
Source File: ChatManagerController.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * @param initialMessages
 * @return
 */
private Message extractMessages(final List<Message> initialMessages) {
    if (initialMessages == null) {
        return null;
    }
    if (initialMessages.size() > 1) {
        final Message msg = initialMessages.get(0);
        final StringBuilder sb = new StringBuilder();
        final String from = msg.getFrom();
        for (final Iterator<Message> iterator = initialMessages.iterator(); iterator.hasNext();) {
            final Message message = iterator.next();
            if (message.getFrom().equals(from)) {
                sb.append(message.getBody()).append("<br/>\n");
            }
        }
        final Message newMsg = new Message();
        newMsg.setBody(sb.toString());
        newMsg.setFrom(from);
        newMsg.setProperty("receiveTime", new Long(new Date().getTime()));
        return newMsg;
    } else {
        return initialMessages.get(0);
    }
}
 
Example 3
Source File: ChatManagerController.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * @param initialMessages
 * @return
 */
private Message extractMessages(final List<Message> initialMessages) {
    if (initialMessages == null) {
        return null;
    }
    if (initialMessages.size() > 1) {
        final Message msg = initialMessages.get(0);
        final StringBuilder sb = new StringBuilder();
        final String from = msg.getFrom();
        for (final Iterator<Message> iterator = initialMessages.iterator(); iterator.hasNext();) {
            final Message message = iterator.next();
            if (message.getFrom().equals(from)) {
                sb.append(message.getBody()).append("<br/>\n");
            }
        }
        final Message newMsg = new Message();
        newMsg.setBody(sb.toString());
        newMsg.setFrom(from);
        newMsg.setProperty("receiveTime", new Long(new Date().getTime()));
        return newMsg;
    } else {
        return initialMessages.get(0);
    }
}
 
Example 4
Source File: OperationSetTypingNotificationsJabberImpl.java    From jitsi with Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source File: ChatRoom.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * 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 6
Source File: OTREngineHost.java    From Spark with Apache License 2.0 6 votes vote down vote up
@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 7
Source File: InstantMessagingGroupChatController.java    From olat with Apache License 2.0 5 votes vote down vote up
private Message createMessage(final String from, final String msgBody) {
    final Message msg = new Message();
    msg.setBody(msgBody);
    msg.setFrom(from);
    msg.setProperty("receiveTime", new Long(new Date().getTime()));
    return msg;
}
 
Example 8
Source File: ChatController.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * @param body
 *            - any text
 * @param from
 *            must be a valid jid
 * @return
 */
private Message createInstantMessage(final String body, final String from) {
    final Message message = new Message();
    message.setBody(body);
    message.setFrom(from);
    message.setProperty("receiveTime", new Long(new Date().getTime()));
    return message;
}
 
Example 9
Source File: InstantMessagingGroupChatController.java    From olat with Apache License 2.0 5 votes vote down vote up
private Message createMessage(final String from, final String msgBody) {
    final Message msg = new Message();
    msg.setBody(msgBody);
    msg.setFrom(from);
    msg.setProperty("receiveTime", new Long(new Date().getTime()));
    return msg;
}
 
Example 10
Source File: ChatController.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * @param body
 *            - any text
 * @param from
 *            must be a valid jid
 * @return
 */
private Message createInstantMessage(final String body, final String from) {
    final Message message = new Message();
    message.setBody(body);
    message.setFrom(from);
    message.setProperty("receiveTime", new Long(new Date().getTime()));
    return message;
}
 
Example 11
Source File: XmppClient.java    From riotapi with Apache License 2.0 5 votes vote down vote up
public void sendToUser(String to, String message) throws Exception {
	Message packet = new Message(to);
	packet.setBody(message);
	packet.setType(Message.Type.chat);
	packet.setFrom(getUser().split("/")[0]);
	sendPacket(packet);
}
 
Example 12
Source File: SingleUserChat.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void sendMessage(Message message) throws XMPPException {
  Chat currentChat;

  synchronized (SingleUserChat.this) {
    currentChat = chat;

    chat.sendMessage(message);
    message.setFrom(userJID);
  }

  chatStateListener.processMessage(currentChat, message);
}
 
Example 13
Source File: ChatRoom.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}