消息历史记录请求返回空结果

时间:2015-01-19 11:16:34

标签: xml xmpp monitoring openfire

我使用以下节来获取历史消息:

<iq type='get' id='user1'>
  <list xmlns='urn:xmpp:archive'
        with='admin@localhost'>
    <set xmlns='http://jabber.org/protocol/rsm'>
      <max>30</max>
    </set>
  </list>
</iq>

答案是:

<iq id="user1" to="user1@localhost/Smack" type="result"></iq>

虽然我可以在Openfire管理控制台上看到两个用户之间的消息..我使用监控服务..

感谢。

1 个答案:

答案 0 :(得分:0)

解决方案是创建自己的提供者..就像那样:

public class HistoryIQProvider implements IQProvider {
public static final String NAMESPACE = "urn:xmpp:archive";
public static final String ELEMENT_NAME = "list";
public static final String CHAT = "chat";
public static final String START_TIME = "start";

private ArrayList<String> startTimes = new ArrayList<String>();

@Override
public IQ parseIQ(XmlPullParser parser) throws Exception {
    boolean stop = false;
    String name = parser.getName();
    Log.d("Parse", "Name: " + name);

    while(false == stop)
    {
        switch (parser.getEventType())
        {
            case XmlPullParser.START_TAG:
            {
                if(ELEMENT_NAME.equals(name)) {

                    /*** START_TAG = 2
                     ***  END_TAG = 3
                     ***/

                    while (parser.nextTag() == XmlPullParser.START_TAG) {
                        /*** Stop when chats is finished.. ***/
                        if(parser.getName().equals("set")) {
                            break;
                        }
                        String startTime = parser.getAttributeValue(1);
                        startTimes.add(startTime);
                        parser.nextTag();
                    }
                }
            }
            case XmlPullParser.END_TAG:
            {
                stop = ELEMENT_NAME.equals(name);
                break;
            }
        }
    }

    name = null;
    HistoryIQ historyIQ = new HistoryIQ(startTimes);
    return historyIQ;
}
}

HistoryIQ:

public class HistoryIQ extends IQ {
private ArrayList<String> startTimes = new ArrayList<String>();

public HistoryIQ(ArrayList<String> l) {
    startTimes = l;
}

@Override
public String getChildElementXML() {
    return null;
}

public ArrayList<String> getHistory_Chats() {
    Log.d("Parse", "Lists : " + startTimes.size());
    return startTimes;
}
}