Java Code Examples for org.jivesoftware.smack.packet.Message#setBody()
The following examples show how to use
org.jivesoftware.smack.packet.Message#setBody() .
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: KonMessageSender.java From desktopclient-java with GNU General Public License v3.0 | 6 votes |
private static Message rawMessage(MessageContent content, Chat chat, boolean encrypted) { Message smackMessage = new Message(); // text body String text = content.getPlainText(); OutAttachment att = content.getOutAttachment().orElse(null); if (text.isEmpty() && att != null) { // use attachment URL as body text = att.getURL().toString(); } if (!text.isEmpty()) smackMessage.setBody(text); extensionsForContent(content, chat, encrypted) .forEach(smackMessage::addExtension); return smackMessage; }
Example 2
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 3
Source File: CoBrowser.java From Spark with Apache License 2.0 | 6 votes |
private void navigateUser(String href) { if (followMeButton.isSelected() && hasLoaded) { final Message mes = new Message(); final Map<String, Object> properties = new HashMap<>(); properties.put( "PUSH_URL", href ); mes.addExtension( new JivePropertiesExtension( properties ) ); mes.setBody(""); send(mes); updateLinkLabel(href); hasLoaded = false; } else { updateLinkLabel(href); } hasLoaded = true; }
Example 4
Source File: XHTMLExtensionTest.java From Smack with Apache License 2.0 | 6 votes |
/** * Low level API test. * This is a simple test to use with an XMPP client and check if the client receives the message * 1. User_1 will send a message with formatted text (XHTML) to user_2 */ public void testSendSimpleXHTMLMessage() { // User1 creates a chat with user2 Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null); // User1 creates a message to send to user2 Message msg = new Message(); msg.setSubject("Any subject you want"); msg.setBody("Hey John, this is my new green!!!!"); // Create a XHTMLExtension Package and add it to the message XHTMLExtension xhtmlExtension = new XHTMLExtension(); xhtmlExtension.addBody( "<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>"); msg.addExtension(xhtmlExtension); // User1 sends the message that contains the XHTML to user2 try { chat1.sendMessage(msg); Thread.sleep(200); } catch (Exception e) { fail("An error occurred sending the message with XHTML"); } }
Example 5
Source File: Workpane.java From Spark with Apache License 2.0 | 6 votes |
public void decorateRoom(ChatRoom room, Map metadata) { EntityBareJid roomName = room.getRoomJid(); Localpart sessionID =roomName.getLocalpart(); RequestUtils utils = new RequestUtils(metadata); addRoomInfo(sessionID, utils, room); addButtons(sessionID.toString(), utils, room); // Specify to use Typing notifications. GroupChatRoom groupChat = (GroupChatRoom)room; groupChat.setChatStatEnabled(true); Properties props = FastpathPlugin.getLitWorkspace().getWorkgroupProperties(); String initialResponse = props.getProperty(INITIAL_RESPONSE_PROPERTY); if (ModelUtil.hasLength(initialResponse)) { Message message = new Message(); message.setBody(initialResponse); GroupChatRoom groupChatRoom = (GroupChatRoom)room; groupChatRoom.sendMessage(message); } }
Example 6
Source File: CoBrowser.java From Spark with Apache License 2.0 | 6 votes |
private void pushPage(String link) { updateLinkLabel(link); // If the disable box is not selected, update customer with // page push. final Message mes = new Message(); final Map<String, Object> properties = new HashMap<>(); properties.put( "PUSH_URL", link ); mes.addExtension( new JivePropertiesExtension( properties ) ); mes.setBody(FpRes.getString("message.start.cobrowsing", link)); chatRoom.getTranscriptWindow().insertNotificationMessage(FpRes.getString("message.send.cobrowsing.message", link), ChatManager.NOTIFICATION_COLOR); send(mes); pushField.setText(""); load(link); }
Example 7
Source File: ChatManagerController.java From olat with Apache License 2.0 | 6 votes |
/** * @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 8
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 9
Source File: ChatManagerController.java From olat with Apache License 2.0 | 6 votes |
/** * @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 10
Source File: InstantMessagingGroupChatController.java From olat with Apache License 2.0 | 5 votes |
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 11
Source File: ChatController.java From olat with Apache License 2.0 | 5 votes |
/** * @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 12
Source File: XmppClient.java From riotapi with Apache License 2.0 | 5 votes |
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 13
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 14
Source File: InstantMessagingGroupChatController.java From olat with Apache License 2.0 | 5 votes |
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 15
Source File: MultiUserChat.java From saros with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void sendMessage(String body) throws XMPPException { Message message = muc.createMessage(); message.setBody(body); sendMessage(message); }
Example 16
Source File: SingleUserChat.java From saros with GNU General Public License v2.0 | 5 votes |
@Override public void sendMessage(String text) throws XMPPException { String participant; String threadId; synchronized (SingleUserChat.this) { threadId = chat.getThreadID(); participant = chat.getParticipant(); } Message message = new Message(participant, Message.Type.chat); message.setThread(threadId); message.setBody(text); sendMessage(message); }
Example 17
Source File: UriManager.java From Spark with Apache License 2.0 | 5 votes |
/** * handles the ?message URI * * @param uri * the decoded uri */ public void handleMessage(URI uri) { String query = uri.getQuery(); int bodyIndex = query.indexOf("body="); Jid jid = retrieveJID(uri); String body = null; // Find body if (bodyIndex != -1) { body = query.substring(bodyIndex + 5); } body = org.jivesoftware.spark.util.StringUtils.unescapeFromXML(body); UserManager userManager = SparkManager.getUserManager(); String nickname = userManager.getUserNicknameFromJID(jid.asBareJid()); if (nickname == null) { nickname = jid.toString(); } ChatManager chatManager = SparkManager.getChatManager(); ChatRoom chatRoom = chatManager.createChatRoom(jid.asEntityJidOrThrow(), nickname, nickname); if (body != null) { Message message = new Message(); message.setBody(body); chatRoom.sendMessage(message); } chatManager.getChatContainer().activateChatRoom(chatRoom); }
Example 18
Source File: GroupChatRoom.java From Spark with Apache License 2.0 | 5 votes |
@Override public void sendMessage( String text ) { // IF there is no body, just return and do nothing if ( !ModelUtil.hasLength( text ) ) { return; } // Set the body of the message using typedMessage and remove control characters final Message message = new Message(); message.setBody( text.replaceAll( "[\\u0001-\\u0008\\u000B-\\u001F]", "" ) ); sendMessage( message ); }
Example 19
Source File: XSCHelper.java From PracticeCode with Apache License 2.0 | 5 votes |
/** * 发送信息到云同步室 * * @param room 云同步室 * @param msg 将要发送的信息 */ public void sendProjChromMsg(MultiUserChat room, Object msg) { if (!room.isJoined()) return; try { Message message = new Message(room.getRoom(), Message.Type.groupchat); message.setBody(SysUtil.getInstance().getDateAndTimeFormated()); message.setProperty(MSGCLOUD, msg); room.sendMessage(message); } catch (XMPPException e) { e.printStackTrace(); } }
Example 20
Source File: XMPPPeerInterface.java From hypergraphdb with Apache License 2.0 | 4 votes |
public PeerRelatedActivityFactory newSendActivityFactory() { return new PeerRelatedActivityFactory() { public PeerRelatedActivity createActivity() { return new PeerRelatedActivity() { public Boolean call() throws Exception { Json msg = getMessage(); if (!msg.has(Messages.REPLY_TO)) { msg.set(Messages.REPLY_TO, connection.getUser()); } String msgAsString = msg.toString(); if (msgAsString.length() > fileTransferThreshold) { OutgoingFileTransfer outFile = fileTransfer.createOutgoingFileTransfer((String)getTarget()); byte [] B = msgAsString.getBytes(); outFile.sendStream(new ByteArrayInputStream(B), "", B.length, ""); return true; } else { try { Message xmpp = new Message((String)getTarget()); xmpp.setBody(msgAsString); xmpp.setProperty("hypergraphdb", Boolean.TRUE); connection.sendPacket(xmpp); return true; } catch (Throwable t) { t.printStackTrace(System.err); return false; } } } }; } }; }