我正在尝试使用Strophe从ejabberd服务器检索消息的集合。我使用查询:
$iq({type: 'get'}).c('retrieve', {xmlns: 'http://www.xmpp.org/extensions/xep-0136.html#ns', with:'pivo@localhost/local', start: '2012-10-28T17:38:00.000000Z'}).c('set', {xmlns: 'http://jabber.org/protocol/rsm'}).c('max').t('100');
这将为我生成以下XMPP数据包:
<iq type='get' xmlns='jabber:client'>
<retrieve xmlns='http://www.xmpp.org/extensions/xep-0136.html#ns' with='pivo@localhost/local' start='2012-10-28T17:38:00.000000Z'>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>100</max>
</set>
</retrieve>
</iq>
但问题是服务器无法成功回复,他返回内部服务器错误。
如果我查看Postgres日志,我会发现以下错误:
**ERROR: date/time field value out of range: "0000-01-01 00:00:00" at character 68**
我使用的是ejabberd 2.1.10,pgsql 9.1。
有人可以帮我这个吗?
答案 0 :(得分:2)
首先,您必须检查此集合是否存在。 你可以这样做:
<iq type='get' id='123456'>
<list xmlns='http://www.xmpp.org/extensions/xep-0136.html#ns'
with='jabbar@localhost'>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>30</max>/*max number of collection that you want to retrieve*/
</set>
</list>
</iq>
来自ejabberd的回应:
<iq xmlns='jabber:client'
from='root@localhost'
to='root@localhost/24975890851351278205927376'
id='123456'
type='result'>
<list xmlns='http://www.xmpp.org/extensions/xep-0136.html#ns'>
<chat with='jabbar@localhost/2021512663135182487476431'
start='2012-10-24T13:45:17.000000Z'/>
<chat with='jabbar@localhost/9286394041351135710472543'
start='2012-10-25T20:09:13.000000Z'/>
<chat with='jabbar@localhost/9286394041351135710472543'
start='2012-10-25T21:22:13.000000Z'/>/****** I will retrieve this *****/
<chat with='jabbar@localhost/9286394041351135710472543'
start='2012-10-25T22:05:13.000000Z'/>
<chat with='jabbar@localhost'
start='2012-10-25T23:03:14.000000Z'/>
<chat with='jabbar@localhost'
start='2012-10-25T23:35:37.000000Z'/>
<set xmlns='http://jabber.org/protocol/rsm'>
<first index='0'>
63518305517@1
</first>
<last>
63518427337@15
</last>
<changed>
2012-10-25T23:37:21.000000Z
</changed>
<count>
6
</count>
</set>
</list>
</iq>
现在要从集合中检索消息,您必须在请求节中输入“start”和“with”:
<iq type='get' id='433534536'>
<retrieve xmlns='http://www.xmpp.org/extensions/xep-0136.html#ns'
with='jabbar@localhost/9286394041351135710472543'
start='2012-10-25T21:22:13.000000Z'>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>100</max>
</set>
</retrieve>
</iq>
响应:
<iq xmlns='jabber:client'
from='root@localhost'
to='root@localhost/24975890851351278205927376'
id='433534536'
type='result'>
<chat with='jabbar@localhost/9286394041351135710472543'
start='2012-10-25T21:22:13.000000Z'>
<from secs='0'>
<body>
dddddddddd
</body>
</from>
<from secs='1'>
<body>
dddddddd
</body>
</from>
<set xmlns='http://jabber.org/protocol/rsm'>
<first index='0'>
63518419333@103
</first>
<last>
63518419334@105
</last>
<changed>
2012-10-25T21:22:14.000000Z
</changed>
<count>
2
</count>
</set>
</chat>
</iq>