@Test public void validateMessageTypeWithDefaults1() { Message incomingChat = createChatPacket("134", true); incomingChat.setType(Type.chat); processServerMessage(incomingChat); assertNotNull(listener.getNewChat()); }
@Test public void validateMessageTypeWithDefaults2() { Message incomingChat = createChatPacket("134", true); incomingChat.setType(Type.normal); processServerMessage(incomingChat); assertNotNull(listener.getNewChat()); }
@Test public void validateMessageTypeWithDefaults3() { Message incomingChat = createChatPacket("134", true); incomingChat.setType(Type.groupchat); processServerMessage(incomingChat); assertNull(listener.getNewChat()); }
@Test public void validateMessageTypeWithNoNormal1() { cm.setNormalIncluded(false); Message incomingChat = createChatPacket("134", true); incomingChat.setType(Type.chat); processServerMessage(incomingChat); assertNotNull(listener.getNewChat()); }
@Test public void validateMessageTypeWithNoNormal2() { cm.setNormalIncluded(false); Message incomingChat = createChatPacket("134", true); incomingChat.setType(Type.normal); processServerMessage(incomingChat); assertNull(listener.getNewChat()); }
@Test public void chatNotMatchedWithTypeNormal() { cm.setNormalIncluded(false); Message incomingChat = createChatPacket(null, false); incomingChat.setType(Type.normal); processServerMessage(incomingChat); assertNull(listener.getNewChat()); }
private void initSysTemMsgManager() { initSoundPool(); XMPPConnection con = XmppConnectionManager.getInstance() .getConnection(); con.addPacketListener(pListener, new MessageTypeFilter( Message.Type.normal)); }
@Override public void processPacket(Packet packetz) { Message message = (Message) packetz; if (message.getType() == Type.normal) { NoticeManager noticeManager = NoticeManager .getInstance(context); Notice notice = new Notice(); // playSound(1, 0); //������Ч notice.setTitle("ϵͳ��Ϣ"); notice.setNoticeType(Notice.SYS_MSG); notice.setFrom(packetz.getFrom()); notice.setContent(message.getBody()); notice.setNoticeTime(DateUtil.date2Str(Calendar.getInstance(), Constant.MS_FORMART)); notice.setFrom(packetz.getFrom()); notice.setTo(packetz.getTo()); notice.setStatus(Notice.UNREAD); long noticeId = noticeManager.saveNotice(notice); if (noticeId != -1) { Intent intent = new Intent(); intent.setAction(Constant.ACTION_SYS_MSG); notice.setId(String.valueOf(noticeId)); intent.putExtra("notice", notice); sendBroadcast(intent); setNotiType(R.drawable.icon, Constant.SYS_MSG_DIS, message.getBody(), MyNoticeActivity.class); } } }
private void init() { //数据业务类 mIMMsgDao = new IMMsgDao(context); XMPPConnection con = XmppConnectionManager.getInstance() .getConnection(); con.addPacketListener(pListener, new MessageTypeFilter( Message.Type.normal)); }
public void processPacket(final Packet packet) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { final Message message = (Message)packet; // Do not handle errors or offline messages final DelayInformation offlineInformation = (DelayInformation)message.getExtension("x", "jabber:x:delay"); if (offlineInformation != null || message.getError() != null) { return; } boolean broadcast = message.getProperty("broadcast") != null; if ((broadcast || message.getType() == Message.Type.normal || message.getType() == Message.Type.headline) && message.getBody() != null) { showAlert((Message)packet); } else { String host = SparkManager.getSessionManager().getServerAddress(); String from = packet.getFrom() != null ? packet.getFrom() : ""; if (host.equalsIgnoreCase(from) || !ModelUtil.hasLength(from)) { showAlert((Message)packet); } } } catch (Exception e) { Log.error(e); } } }); }
@Test public void validateMessageTypeWithDefaults4() { Message incomingChat = createChatPacket("134", true); incomingChat.setType(Type.headline); assertNull(listener.getNewChat()); }
@Override protected void doStart() throws Exception { try { connection = endpoint.createConnection(); } catch (SmackException e) { if (endpoint.isTestConnectionOnStartup()) { throw new RuntimeException("Could not connect to XMPP server.", e); } else { LOG.warn(e.getMessage()); if (getExceptionHandler() != null) { getExceptionHandler().handleException(e.getMessage(), e); } scheduleDelayedStart(); return; } } chatManager = ChatManager.getInstanceFor(connection); chatManager.addChatListener(this); OrFilter pubsubPacketFilter = new OrFilter(); if (endpoint.isPubsub()) { //xep-0060: pubsub#notification_type can be 'headline' or 'normal' pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.headline)); pubsubPacketFilter.addFilter(new MessageTypeFilter(Type.normal)); connection.addPacketListener(this, pubsubPacketFilter); } if (endpoint.getRoom() == null) { privateChat = chatManager.getThreadChat(endpoint.getChatId()); if (privateChat != null) { if (LOG.isDebugEnabled()) { LOG.debug("Adding listener to existing chat opened to " + privateChat.getParticipant()); } privateChat.addMessageListener(this); } else { privateChat = ChatManager.getInstanceFor(connection).createChat(endpoint.getParticipant(), endpoint.getChatId(), this); if (LOG.isDebugEnabled()) { LOG.debug("Opening private chat to " + privateChat.getParticipant()); } } } else { // add the presence packet listener to the connection so we only get packets that concerns us // we must add the listener before creating the muc final AndFilter packetFilter = new AndFilter(new PacketTypeFilter(Presence.class)); connection.addPacketListener(this, packetFilter); muc = new MultiUserChat(connection, endpoint.resolveRoom(connection)); muc.addMessageListener(this); DiscussionHistory history = new DiscussionHistory(); history.setMaxChars(0); // we do not want any historical messages muc.join(endpoint.getNickname(), null, history, SmackConfiguration.getDefaultPacketReplyTimeout()); if (LOG.isInfoEnabled()) { LOG.info("Joined room: {} as: {}", muc.getRoom(), endpoint.getNickname()); } } this.startRobustConnectionMonitor(); super.doStart(); }
@Override public void processPacket(Packet packetz) { Message message = (Message) packetz; if (message != null && message.getBody() != null && !message.getBody().equals("null")) { if (message.getType() == Type.normal) { Log.i("TAG", "[服务]收到系统消息:"+message.getBody()); // 生成消息历史记录 IMMessage mIMMessage = new IMMessage(); mIMMessage.setTitle("系统信息"); mIMMessage.setContent(message.getBody()); if (Message.Type.error == message.getType()) { mIMMessage.setSendState(IMMessage.FAILED); } else { mIMMessage.setSendState(IMMessage.RECEIVED); } mIMMessage.setType(IMMessage.SYS_MSG); String from = message.getFrom().split("@")[0]; //发送方 mIMMessage.setUserName(from); //接收方 mIMMessage.setToUserName(message.getTo().split("@")[0]); mIMMessage.setReadState(IMMessage.UNREAD); String time = AbDateUtil.getCurrentDate(AbDateUtil.dateFormatYMDHMS); mIMMessage.setTime(time); //保存本地 mIMMsgDao.startWritableDatabase(false); long messageId = mIMMsgDao.insert(mIMMessage); mIMMsgDao.closeDatabase(); if (messageId != -1) { //发出接收到的系统消息 Intent intent = new Intent(); intent.setAction(IMConstant.ACTION_NEW_MESSAGE); intent.setAction(IMConstant.ACTION_SYS_MESSAGE); intent.putExtra("MESSAGE", mIMMessage); sendBroadcast(intent); } } } }
public void processPacket(Packet packet) { if (packet instanceof GoogleMailBoxPacket) { if (JiveGlobals.getBooleanProperty("plugin.gateway.gtalk.mailnotifications", true)) { GoogleMailBoxPacket mbp = (GoogleMailBoxPacket)packet; this.setLastGMailThreadDate(mbp.getResultTime()); Integer newMailCount = 0; String mailList = ""; for (GoogleMailThread mail : mbp.getMailThreads()) { newMailCount++; if (this.getLastGMailThreadId() == null || mail.getThreadId() > this.getLastGMailThreadId()) { this.setLastGMailThreadId(mail.getThreadId()); } String senderList = ""; for (GoogleMailSender sender : mail.getSenders()) { if (!senderList.equals("")) { senderList += ", "; } String name = sender.getName(); if (name != null) { senderList += name + " <"; } senderList += sender.getAddress(); if (name != null) { senderList += ">"; } } mailList += "\n "+senderList+" sent "+mail.getSubject(); } if (newMailCount > 0) { getSession().getTransport().sendMessage( getSession().getJID(), getSession().getTransport().getJID(), LocaleUtils.getLocalizedString("gateway.gtalk.mail", "kraken", Arrays.asList(newMailCount))+mailList, Message.Type.headline ); } } } else if (packet instanceof IQ) { Log.debug("XMPP: Got google mail notification"); GoogleNewMailExtension gnme = (GoogleNewMailExtension)packet.getExtension(GoogleNewMailExtension.ELEMENT_NAME, GoogleNewMailExtension.NAMESPACE); if (gnme != null) { Log.debug("XMPP: Sending google mail request"); getSession().conn.sendPacket(new IQWithPacketExtension(new GoogleMailNotifyExtension())); } } }
/** * 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(); StringBuffer buf = new StringBuffer(); if (subject != null) { buf.append(Res.getString("subject")).append(": ").append(subject); buf.append("\n\n"); } buf.append(body); String from = message.getFrom() != null ? message.getFrom() : ""; final TranscriptWindow window = new TranscriptWindow(); window.insertPrefixAndMessage(null, 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.contains("@")) { // 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); } }
/** * Creates a new message type filter using the specified message type. * * @param type the message type. */ private MessageTypeFilter(Message.Type type) { super(Message.class); this.type = type; }