问题描述
我面临着开火和打sm的问题.我有一个使用smack和openfire开发的jabber机器人.当任何用户添加bot与他/她的联系人时,然后在整个过程结束时,ofRoster(openfire)表的订阅状态将设置为来自".此过程的预期结果是两者".
Hi I'm facing an issue with openfire and smack. I have a jabber bot developed using smack and openfire.When any user adds bot has his/her contact, then in the end of whole process, subscription status of ofRoster(openfire) table is set to 'from'.The desired result of this process is 'both'.
这是我处理新添加连接的代码,
here is my code of handling new adding connection,
xmppConnection.getConnection().getRoster().setSubscriptionMode(Roster.SubscriptionMode.manual);
xmppConnection.getConnection().addPacketListener(
new PacketListener() {
@Override
public void processPacket(Packet paramPacket) {
System.out.println("\n\n");
if(paramPacket instanceof Presence){
Presence presence = (Presence)paramPacket;
String email = getEmailIdFromJabberId(presence.getFrom());
System.out.println("chat invite status changed by user: : " + email + " calling listner");
//if(presence.getType().equals(Presence.Type.subscribed) || presence.getType().equals(Presence.Type.subscribe) ){
System.out.println("presence: " + presence.getFrom() + "; type: " + presence.getType() + "; to: " + presence.getTo() + "; " + presence.toXML());
Roster roster = xmppConnection.getConnection().getRoster();
for(RosterEntry rosterEntry : roster.getEntries()){
System.out.println("jid: " + rosterEntry.getUser() + "; type: " + rosterEntry.getType() + "; status: " + rosterEntry.getStatus());
}
System.out.println("\n\n\n");
if( presence.getType().equals(Presence.Type.subscribe) ){
//chatInviteAcceptanceListner.onChatInviteAccept(email);
Presence newp = new Presence(Presence.Type.subscribed);
newp.setMode(Presence.Mode.available);
newp.setPriority(24);
newp.setTo(presence.getFrom());
//presence.addExtension(new AvatarBroadcastExtension(imageHash));
xmppConnection.getConnection().sendPacket(newp);
} else if(presence.getType().equals(Presence.Type.unsubscribe)){
//chatInviteAcceptanceListner.onChatInviteReject(email);
Presence newp = new Presence(Presence.Type.unsubscribed);
newp.setMode(Presence.Mode.available);
newp.setPriority(24);
newp.setTo(presence.getFrom());
//presence.addExtension(new AvatarBroadcastExtension(imageHash));
xmppConnection.getConnection().sendPacket(newp);
}
}
}
},
new PacketFilter(){
public boolean accept(Packet packet) {
if(packet instanceof Presence){
Presence presence = (Presence)packet;
if(presence.getType().equals(Presence.Type.subscribed)
|| presence.getType().equals(Presence.Type.subscribe)
|| presence.getType().equals(Presence.Type.unsubscribed)
|| presence.getType().equals(Presence.Type.unsubscribe) ){
//System.out.println("packet: " + packet);
return true;
}
}
return false;
}
});
正在添加该约定的用户的日志.使用pidgin
log of users who is adding the conctact. using pidgin
(18:32:22) jabber: jabber_roster_add_buddy(): Adding [email protected]
(18:32:22) jabber: jabber_roster_update([email protected]): [Source: local blist]: groups: Buddies
(18:32:22) jabber: Sending (ssl) ([email protected]/pidgin): <iq type='set' id='purple8dde9bec'><query xmlns='jabber:iq:roster'><item jid='[email protected]' name=''><group>Buddies</group></item></query></iq>
(18:32:22) jabber: Sending (ssl) ([email protected]/pidgin): <presence to='[email protected]' type='subscribe'/>
(18:32:22) jabber: Recv (ssl)(231): <iq type="set" id="88-4977" to="[email protected]/pidgin"><query xmlns="jabber:iq:roster"><item jid="[email protected]" name="" subscription="none"><group>Buddies</group></item></query></iq>
(18:32:22) jabber: Sending (ssl) ([email protected]/pidgin): <iq type='result' id='88-4977'/>
(18:32:22) jabber: Recv (ssl)(89): <iq type="result" id="purple8dde9bec" to="[email protected]/pidgin"/>
(18:32:22) jabber: Unhandled IQ with id purple8dde9bec
(18:32:23) jabber: Recv (ssl)(248): <iq type="set" id="963-4978" to="[email protected]/pidgin"><query xmlns="jabber:iq:roster"><item jid="[email protected]" name="" ask="subscribe" subscription="none"><group>Buddies</group></item></query></iq>
(18:32:23) jabber: Sending (ssl) ([email protected]/pidgin): <iq type='result' id='963-4978'/>
(18:32:23) jabber: Recv (ssl)(247): <iq type="set" id="445-4981" to="[email protected]/pidgin"><query xmlns="jabber:iq:roster"><item jid="[email protected]" name=" Ask a Doctor Now" subscription="to"><group>Buddies</group></item></query></iq>
(18:32:23) jabber: Sending (ssl) ([email protected]/pidgin): <iq type='result' id='445-4981'/>
(18:32:23) jabber: Recv (ssl)(164): <presence id="ERM59-6" to="[email protected]" type="subscribed" from="[email protected]"><priority>24</priority></presence>
(18:32:23) jabber: Recv (ssl)(283): <presence id="ERM59-5" from="[email protected]/smoke" to="[email protected]/pidgin"><status>141 Doctors Online! Type your question & get an answer now. To find out more, type "Help" and hit ENTER</status><priority>24</priority></presence>
(18:32:23) blist: Updating buddy status for [email protected] (XMPP)
bot的日志(启用了错误调试)
log of bot (smack debug enabled)
已发送
<presence id="ERM59-6" to="[email protected]" type="subscribed"><priority>24</priority></presence>
收到
<presence to="[email protected]" type="subscribe" from="[email protected]"/>
<iq type="set" id="612-4980" to="[email protected]/smoke"><query xmlns="jabber:iq:roster"><item jid="[email protected]" subscription="from"/></query></iq>
已解释
<presence to="[email protected]" from="[email protected]" type="subscribe"></presence>
<iq id="612-4980" to="[email protected]/smoke" type="set"><query xmlns="jabber:iq:roster"><item jid="[email protected]" subscription="from"></item></query></iq>
推荐答案
您需要发送自己的<presence type="subscribe" to="[email protected]"/>
,然后该用户将需要像您一样使用<presence type="subscribed"/>
进行回复.
You need to send your own <presence type="subscribe" to="[email protected]"/>
, and then that user will need to reply, just as you do, with <presence type="subscribed"/>
.
这篇关于Openfire:将联系人订阅状态添加为“来自"而不是“两者"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!