0

こんにちは、オープンファイアとスマックの問題に直面しています。smack と openfire を使用して開発された jabber ボットがあります。ユーザーがボットに連絡先を追加すると、プロセス全体の最後に、ofRoster(openfire) テーブルのサブスクリプション ステータスが「from」に設定されます。このプロセスの望ましい結果は「両方」です。

これが、新しい追加接続を処理する私のコードです。

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;
        }
    });

連絡先を追加しているユーザーのログ。ピジンを使って

(18:32:22) jabber: jabber_roster_add_buddy(): Adding testdoctor@answers.exampledomain.com
(18:32:22) jabber: jabber_roster_update(testdoctor@answers.exampledomain.com): [Source: local blist]: groups: Buddies
(18:32:22) jabber: Sending (ssl) (testuser2@answers.exampledomain.com/pidgin): <iq type='set' id='purple8dde9bec'><query xmlns='jabber:iq:roster'><item jid='testdoctor@answers.exampledomain.com' name=''><group>Buddies</group></item></query></iq>
(18:32:22) jabber: Sending (ssl) (testuser2@answers.exampledomain.com/pidgin): <presence to='testdoctor@answers.exampledomain.com' type='subscribe'/>
(18:32:22) jabber: Recv (ssl)(231): <iq type="set" id="88-4977" to="testuser2@answers.exampledomain.com/pidgin"><query xmlns="jabber:iq:roster"><item jid="testdoctor@answers.exampledomain.com" name="" subscription="none"><group>Buddies</group></item></query></iq>
(18:32:22) jabber: Sending (ssl) (testuser2@answers.exampledomain.com/pidgin): <iq type='result' id='88-4977'/>
(18:32:22) jabber: Recv (ssl)(89): <iq type="result" id="purple8dde9bec" to="testuser2@answers.exampledomain.com/pidgin"/>
(18:32:22) jabber: Unhandled IQ with id purple8dde9bec
(18:32:23) jabber: Recv (ssl)(248): <iq type="set" id="963-4978" to="testuser2@answers.exampledomain.com/pidgin"><query xmlns="jabber:iq:roster"><item jid="testdoctor@answers.exampledomain.com" name="" ask="subscribe" subscription="none"><group>Buddies</group></item></query></iq>
(18:32:23) jabber: Sending (ssl) (testuser2@answers.exampledomain.com/pidgin): <iq type='result' id='963-4978'/>
(18:32:23) jabber: Recv (ssl)(247): <iq type="set" id="445-4981" to="testuser2@answers.exampledomain.com/pidgin"><query xmlns="jabber:iq:roster"><item jid="testdoctor@answers.exampledomain.com" name=" Ask a Doctor Now" subscription="to"><group>Buddies</group></item></query></iq>
(18:32:23) jabber: Sending (ssl) (testuser2@answers.exampledomain.com/pidgin): <iq type='result' id='445-4981'/>
(18:32:23) jabber: Recv (ssl)(164): <presence id="ERM59-6" to="testuser2@answers.exampledomain.com" type="subscribed" from="testdoctor@answers.exampledomain.com"><priority>24</priority></presence>
(18:32:23) jabber: Recv (ssl)(283): <presence id="ERM59-5" from="testdoctor@answers.exampledomain.com/smoke" to="testuser2@answers.exampledomain.com/pidgin"><status>141 Doctors Online! Type your question &amp; 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 testdoctor@answers.exampledomain.com (XMPP) 

ボットのログ (スマック デバッグが有効)

送信済

    <presence id="ERM59-6" to="testuser2@answers.exampledomain.com" type="subscribed"><priority>24</priority></presence>

受け取った

    <presence to="testdoctor@answers.exampledomain.com" type="subscribe" from="testuser2@answers.exampledomain.com"/>
<iq type="set" id="612-4980" to="testdoctor@answers.exampledomain.com/smoke"><query xmlns="jabber:iq:roster"><item jid="testuser2@answers.exampledomain.com" subscription="from"/></query></iq>

解釈された

    <presence to="testdoctor@answers.exampledomain.com" from="testuser2@answers.exampledomain.com" type="subscribe"></presence>
<iq id="612-4980" to="testdoctor@answers.exampledomain.com/smoke" type="set"><query xmlns="jabber:iq:roster"><item jid="testuser2@answers.exampledomain.com" subscription="from"></item></query></iq>
4

1 に答える 1

0

自分の を送信する必要が<presence type="subscribe" to="testusrer@answers.exampledomain.com"/>あり、そのユーザーはあなたと同じように で返信する必要があります<presence type="subscribed"/>

これは XMPP6121 で説明されています

于 2012-05-27T08:28:49.797 に答える