Java Code Examples for org.jivesoftware.smack.packet.Message#getType()
The following examples show how to use
org.jivesoftware.smack.packet.Message#getType() .
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: MessageListener.java From Yahala-Messenger with MIT License | 6 votes |
@Override public void processPacket(Stanza packet) throws SmackException.NotConnectedException { Message m = (Message) packet; if (m.getType() == Message.Type.chat || m.getType() == Message.Type.normal) { // somebody has news for us FileLog.e(LOGGER.getName(), "got message: " + m); MessagesController.getInstance().processChatMessage(m); } // error message else if (m.getType() == Message.Type.error) { FileLog.e(LOGGER.getName(), "got error message: " + m); } else { FileLog.e(LOGGER.getName(), "unknown message type: " + m.getType()); } }
Example 2
Source File: GroupChatJoinTask.java From olat with Apache License 2.0 | 6 votes |
/** * listens to new messages for this chatroom */ void addMessageListener() { messageListener = new PacketListener() { @Override public void processPacket(final Packet packet) { final Message jabbmessage = (Message) packet; if (log.isDebugEnabled()) { log.debug("processPacket Msg: to=" + jabbmessage.getTo()); } jabbmessage.setProperty("receiveTime", new Long(new Date().getTime())); if ((jabbmessage.getType() == Message.Type.groupchat) && jabbmessage.getBody() != null) { listeningController.event(new InstantMessagingEvent(jabbmessage, "groupchat")); } } }; muc.addMessageListener(messageListener); }
Example 3
Source File: GroupChatJoinTask.java From olat with Apache License 2.0 | 6 votes |
/** * listens to new messages for this chatroom */ void addMessageListener() { messageListener = new PacketListener() { @Override public void processPacket(final Packet packet) { final Message jabbmessage = (Message) packet; if (log.isDebugEnabled()) { log.debug("processPacket Msg: to=" + jabbmessage.getTo()); } jabbmessage.setProperty("receiveTime", new Long(new Date().getTime())); if ((jabbmessage.getType() == Message.Type.groupchat) && jabbmessage.getBody() != null) { listeningController.event(new InstantMessagingEvent(jabbmessage, "groupchat")); } } }; muc.addMessageListener(messageListener); }
Example 4
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 5
Source File: RoarPopupHelper.java From Spark with Apache License 2.0 | 6 votes |
/** * Returns the Nickname of the person sending the message * * @param room * the ChatRoom the message was sent in * @param message * the actual message * @return nickname */ public static String getNickname(ChatRoom room, Message message) { String nickname = SparkManager.getUserManager().getUserNicknameFromJID(message.getFrom()); if (room.getChatType() == Message.Type.groupchat) { nickname = XmppStringUtils.parseResource(nickname); } final JivePropertiesExtension extension = ((JivePropertiesExtension) message.getExtension( JivePropertiesExtension.NAMESPACE )); final boolean broadcast = extension != null && extension.getProperty( "broadcast" ) != null; if ((broadcast || message.getType() == Message.Type.normal || message.getType() == Message.Type.headline) && message.getBody() != null) { nickname = Res.getString("broadcast") + " - " + nickname; } return nickname; }
Example 6
Source File: XMPPConsole.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
@Override public void processMessage(Chat chat, Message msg) { logger.debug("Received XMPP message: {} of type {}", msg.getBody(), msg.getType()); if (msg.getType() == Message.Type.error || msg.getBody() == null) { return; } String cmd = msg.getBody(); String[] args = cmd.split(" "); ConsoleInterpreter.handleRequest(args, new ChatConsole(chat)); }
Example 7
Source File: MessageTypeFilter.java From Smack with Apache License 2.0 | 4 votes |
@Override protected boolean acceptSpecific(Message message) { return message.getType() == type; }
Example 8
Source File: Workspace.java From Spark with Apache License 2.0 | 4 votes |
private void handleIncomingPacket(Stanza stanza) throws SmackException.NotConnectedException, InterruptedException { // We only handle message packets here. if (stanza instanceof Message) { final Message message = (Message)stanza; boolean isGroupChat = message.getType() == Message.Type.groupchat; // Check if Conference invite. If so, do not handle here. if (message.getExtension("x", "jabber:x:conference") != null) { return; } final String body = message.getBody(); final JivePropertiesExtension extension = ((JivePropertiesExtension) message.getExtension( JivePropertiesExtension.NAMESPACE )); final boolean broadcast = extension != null && extension.getProperty( "broadcast" ) != null; // Handle offline message. DelayInformation offlineInformation = message.getExtension("delay", "urn:xmpp:delay"); if (offlineInformation != null && (Message.Type.chat == message.getType() || Message.Type.normal == message.getType())) { handleOfflineMessage(message); } if (body == null || isGroupChat || broadcast || message.getType() == Message.Type.normal || message.getType() == Message.Type.headline || message.getType() == Message.Type.error) { return; } // Create new chat room for Agent Invite. final Jid from = stanza.getFrom(); final String host = SparkManager.getSessionManager().getServerAddress(); // Don't allow workgroup notifications to come through here. final BareJid bareJID = from.asBareJid(); if (host.equalsIgnoreCase(from.toString()) || from == null) { return; } ChatRoom room = null; try { room = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID); } catch (ChatRoomNotFoundException e) { // Ignore } // Check for non-existent rooms. if (room == null) { EntityBareJid entityBareJid = bareJID.asEntityBareJidIfPossible(); if (entityBareJid != null) { createOneToOneRoom(entityBareJid, message); } } } }
Example 9
Source File: BroadcastPlugin.java From Spark with Apache License 2.0 | 4 votes |
/** * Show Server Alert. * * @param message the message to show. * @param type */ private void showAlert(Message message) { Type type = message.getType(); // Do not show alert if the message is an error. if (message.getError() != null) { return; } final String body = message.getBody(); String subject = message.getSubject(); StringBuilder buf = new StringBuilder(); if (subject != null) { buf.append(Res.getString("subject")).append(": ").append(subject); buf.append("\n\n"); } buf.append(body); Jid from = message.getFrom(); final TranscriptWindow window = new TranscriptWindow(); window.insertNotificationMessage(buf.toString(), ChatManager.TO_COLOR); JPanel p = new JPanel(); p.setLayout(new BorderLayout()); p.add(window, BorderLayout.CENTER); p.setBorder(BorderFactory.createLineBorder(Color.lightGray)); // Count the number of linebreaks <br> and \n String s = message.getBody(); s = s.replace("<br/>", "\n"); s = s.replace("<br>", "\n"); int linebreaks = org.jivesoftware.spark.util.StringUtils. countNumberOfOccurences(s,'\n'); // Currently Serverbroadcasts dont contain Subjects, so this might be a MOTD message boolean mightbeMOTD = message.getSubject()!=null; if (!from.hasLocalpart()) { // if theres no "@" it means the message came from the server if (Default.getBoolean(Default.BROADCAST_IN_CHATWINDOW) || linebreaks > 20 || message.getBody().length() > 1000 || mightbeMOTD) { // if we have more than 20 linebreaks or the message is longer // than 1000characters we should broadcast // in a normal chatwindow broadcastInChat(message); } else { broadcastWithPanel(message); } } else if (message.getFrom() != null) { userToUserBroadcast(message, type, from); } }