Java 类org.jivesoftware.smackx.OfflineMessageManager 实例源码

项目:EIM    文件:XmppConnectionManager.java   
/**
 * ��ȡ������Ϣ
 * 
 * @return
 */
public List<Message> getOffLineMessages() {
    List<Message> msgs = new ArrayList<Message>();
    OfflineMessageManager offLineMessageManager = new OfflineMessageManager(
            connection);
    try {
        Iterator<Message> it = offLineMessageManager.getMessages();
        while (it.hasNext()) {
            Message msg = it.next();
            SLog.i(tag, msg.toXML());
            msgs.add(msg);
        }
        offLineMessageManager.deleteMessages();
    } catch (XMPPException e) {
        e.printStackTrace();
    }
    return msgs;
}
项目:NewCommunication-Android    文件:XmppManager.java   
public List<Message> getOfflineMsg() throws XMPPException{

    List<Message> msgList = null;

    OfflineMessageManager omm = new OfflineMessageManager(this.getConnection());
    Iterator<Message> messages = omm.getMessages();
    while(messages.hasNext()){

        if(msgList == null){
            msgList = new ArrayList<Message>();
        }

        msgList.add(messages.next());
    }

    return msgList;
}
项目:SmackStudy    文件:XMPPUtil.java   
/**
 * 获取用户的所有离线消息
 * @param xmppConnection
 * @return
 */
public static Map<String, List<HashMap<String, String>>> getOfflnMessage(XMPPConnection xmppConnection) {
    Map<String, List<HashMap<String, String>>> offlineMsgs = null;
    try {
        OfflineMessageManager offlineManager = new OfflineMessageManager(xmppConnection);
        Iterator<Message> it = offlineManager.getMessages();
        offlineMsgs = new HashMap<String, List<HashMap<String, String>>>();
        while (it.hasNext()) {
            Message message = it.next();
            String fromUser = StringUtils.parseName(message.getFrom());
            HashMap<String, String> histrory = new HashMap<String, String>();
            histrory.put("useraccount",StringUtils.parseName(xmppConnection.getUser()));
            histrory.put("friendaccount", fromUser);
            histrory.put("info", message.getBody());
            histrory.put("type", "left");
            if (offlineMsgs.containsKey(fromUser)) {
                offlineMsgs.get(fromUser).add(histrory);
            } else {
                List<HashMap<String, String>> temp = new ArrayList<HashMap<String, String>>();
                temp.add(histrory);
                offlineMsgs.put(fromUser, temp);
            }
        }
        offlineManager.deleteMessages();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return offlineMsgs;
}
项目:SmackStudy    文件:XMPPUtil.java   
/**
 * 获取用户的所有离线消息
 * @param xmppConnection
 * @return
 */
public  static  Map<String, List<HashMap<String, String>>> getOfflnMessage(XMPPConnection xmppConnection) {
    Map<String, List<HashMap<String, String>>> offlineMsgs = null;
    try {
        OfflineMessageManager offlineManager = new OfflineMessageManager(xmppConnection);
        Iterator<Message> it = offlineManager.getMessages();
        offlineMsgs = new HashMap<String, List<HashMap<String, String>>>();
        while (it.hasNext()) {
            Message message = it.next();
            String fromUser = StringUtils.parseName(message.getFrom());
            HashMap<String, String> histrory = new HashMap<String, String>();
            histrory.put("useraccount",StringUtils.parseName(xmppConnection.getUser()));
            histrory.put("friendaccount", fromUser);
            histrory.put("info", message.getBody());
            histrory.put("type", "left");
            if (offlineMsgs.containsKey(fromUser)) {
                offlineMsgs.get(fromUser).add(histrory);
            } else {
                List<HashMap<String, String>> temp = new ArrayList<HashMap<String, String>>();
                temp.add(histrory);
                offlineMsgs.put(fromUser, temp);
            }
        }
        offlineManager.deleteMessages();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return offlineMsgs;
}
项目:xmpp    文件:XmppTool.java   
/**
     * 获取离线消息
     */
    private void getMessage() {
        OfflineMessageManager offlineManager = new OfflineMessageManager(getCon());
        try {
            Iterator<org.jivesoftware.smack.packet.Message> it = offlineManager
                    .getMessages();
            Log.i("service", offlineManager.supportsFlexibleRetrieval() + "");
            Log.i("service", "离线消息数量: " + offlineManager.getMessageCount());
            Map<String, ArrayList<Message>> offlineMsgs = new HashMap<String, ArrayList<Message>>();
            while (it.hasNext()) {
                org.jivesoftware.smack.packet.Message message = it.next();
                Log.i("service", "收到离线消息, Received from 【" + message.getFrom()
                        + "】 message: " + message.getBody());
                String fromUser = message.getFrom().split("/")[0];
                if (offlineMsgs.containsKey(fromUser)) {
                    offlineMsgs.get(fromUser).add(message);
                } else {
                    ArrayList<Message> temp = new ArrayList<Message>();
                    temp.add(message);
                    offlineMsgs.put(fromUser, temp);
                }
            }
//在这里进行处理离线消息集合......
            Set<String> keys = offlineMsgs.keySet();
            Iterator<String> offIt = keys.iterator();
            while (offIt.hasNext()) {
                String key = offIt.next();
                ArrayList<Message> ms = offlineMsgs.get(key);

                for (int i = 0; i < ms.size(); i++) {
                    Log.i("serviceeeeeeeeeeeee", "收到离线消息, Received from 【" + ms.get(i).getFrom()
                            + "】 message: " + ms.get(i).getBody());
                }
            }
            offlineManager.deleteMessages();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }
项目:EIM    文件:OfflineMsgManager.java   
/**
 * 
 * ����������Ϣ.
 * 
 * @param connection
 * @author shimiso
 * @update 2012-7-9 ����5:45:32
 */
public void dealOfflineMsg(XMPPConnection connection) {
    OfflineMessageManager offlineManager = new OfflineMessageManager(
            connection);
    try {
        Iterator<org.jivesoftware.smack.packet.Message> it = offlineManager
                .getMessages();
        Log.i("������Ϣ����: ", "" + offlineManager.getMessageCount());
        while (it.hasNext()) {
            org.jivesoftware.smack.packet.Message message = it.next();
            Log.i("�յ�������Ϣ", "Received from ��" + message.getFrom()
                    + "�� message: " + message.getBody());
            if (message != null && message.getBody() != null
                    && !message.getBody().equals("null")) {
                IMMessage msg = new IMMessage();
                String time = (String) message
                        .getProperty(IMMessage.KEY_TIME);
                msg.setTime(time == null ? DateUtil.getCurDateStr() : time);
                msg.setContent(message.getBody());
                if (Message.Type.error == message.getType()) {
                    msg.setType(IMMessage.ERROR);
                } else {
                    msg.setType(IMMessage.SUCCESS);
                }
                String from = message.getFrom().split("/")[0];
                msg.setFromSubJid(from);

                // ����֪ͨ
                NoticeManager noticeManager = NoticeManager
                        .getInstance(context);
                Notice notice = new Notice();
                notice.setTitle("�Ự��Ϣ");
                notice.setNoticeType(Notice.CHAT_MSG);
                notice.setContent(message.getBody());
                notice.setFrom(from);
                notice.setStatus(Notice.UNREAD);
                notice.setNoticeTime(time == null ? DateUtil
                        .getCurDateStr() : time);

                // ��ʷ��¼
                IMMessage newMessage = new IMMessage();
                newMessage.setMsgType(0);
                newMessage.setFromSubJid(from);
                newMessage.setContent(message.getBody());
                newMessage.setTime(time == null ? DateUtil.getCurDateStr()
                        : time);
                MessageManager.getInstance(context).saveIMMessage(
                        newMessage);

                long noticeId = noticeManager.saveNotice(notice);
                if (noticeId != -1) {
                    Intent intent = new Intent(Constant.NEW_MESSAGE_ACTION);
                    intent.putExtra(IMMessage.IMMESSAGE_KEY, msg);
                    intent.putExtra("noticeId", noticeId);
                    context.sendBroadcast(intent);
                    activitySupport.setNotiType(
                            R.drawable.icon,
                            context.getResources().getString(
                                    R.string.new_message),
                            notice.getContent(), ChatActivity.class, from);
                }
            }
        }

        offlineManager.deleteMessages();
    } catch (Exception e) {
        e.printStackTrace();
    }

}