情况2.A加B,B同意,B再加A,A拒绝
A请求加B
A1 , A->S A发送iq roster set
<iq id='setIQRoster_34619a68f6782' type='set' xmlns='jabber:client'>
<query xmlns='jabber:iq:roster'>
<item jid='lxy4@user-20160421db' name='lxy4'>
<group>家人</group>
</item>
</query>
</iq>
A2, S->A 服务器发来 iq roster set
<iq xmlns="jabber:client" type="set" id="642-562" to="lxy5@user-20160421db/6ws7h81i8t">
<query xmlns="jabber:iq:roster">
<item jid="lxy4@user-20160421db" name="lxy4" subscription="none">
<group>家人</group>
</item>
</query>
</iq>
A收到了服务器来的iq roster set后将B加到了自己的列表
A3, A->S 请求vcard
<iq id='vcard_34619a6925667' type='get' from='lxy5@user-20160421db' to='lxy4@user-20160421db' xmlns='jabber:client'><vCard xmlns='vcard-temp'/>
</iq>
A4, A->S 对A2的应答
<iq from='lxy5@user-20160421db/Spark' type='result' id='642-562' xmlns='jabber:client'/>
A5, S->A, 对A1的应答
<iq xmlns="jabber:client" type="result" id="setIQRoster_34619a68f6782" to="lxy5@user-20160421db/6ws7h81i8t"/>
A6, A->S, 发送 订阅节
<presence id='subscribe_34619a6972718' to='lxy4@user-20160421db' type='subscribe' from='lxy5@user-20160421db' xmlns='jabber:client'/>
A7, S->A 收到vcard
略去
B收到了请求
B1,S->B B收到了好友请求
<presence xmlns="jabber:client" id="subscribe_34619a6972718" to="lxy4@user-20160421db" type="subscribe" from="lxy5@user-20160421db"/>
此时点击了同意,但是没有先发送同意请求节
B2, B->S , B先发送 iq roster set节将A设置到自己的好友列表
<iq id='setIQRoster_3461a1b220446' type='set' xmlns='jabber:client'>
<query xmlns='jabber:iq:roster'>
<item jid='lxy5@user-20160421db' name='lxy5'>
<group>我的家人</group>
</item>
</query>
</iq>
B3, S->B 收到了服务器的对B2的确认
<iq xmlns="jabber:client" type="result" id="setIQRoster_3461a1b220446" to="lxy4@user-20160421db/and4ahzwoc"/>
B4, B->S 请求加A为好友
type = subscibe
<presence id='subscribe_3461a1b24f33' to='lxy5@user-20160421db' type='subscribe' from='lxy4@user-20160421db' xmlns='jabber:client'/>
B5, B->S 发送同意请求节,同意A对自己加好友的请求
type = subscribed
<presence id='subscribed_3461a1b253105' to='lxy5@user-20160421db' type='subscribed' from='lxy4@user-20160421db' xmlns='jabber:client'/>
B6, S->B 收到了服务器的iq roster set节,此时B渲染界面,将A加到自己的界面上
此时对B来说,是B(from)A,即对方(A)订阅了我,我还没订阅对方(A)
<iq xmlns="jabber:client" type="set" id="812-568" to="lxy4@user-20160421db/and4ahzwoc">
<query xmlns="jabber:iq:roster">
<item jid="lxy5@user-20160421db" name="lxy5" ask="subscribe" subscription="from">
<group>我的家人</group>
</item>
</query>
</iq>
B7, B->S 请求A的名片
<iq id='vcard_3461a1b29b609' type='get' from='lxy4@user-20160421db' to='lxy5@user-20160421db' xmlns='jabber:client'><vCard xmlns='vcard-temp'/></iq>
B8, B->S ,对B6的确认
<iq from='lxy4@user-20160421db/and4ahzwoc' type='result' id='812-568' xmlns='jabber:client'/>
B9, S->B 发来A的名片
略去
A8, S->A 收到了B对自己的订阅
type = subscribe
<presence xmlns="jabber:client" id="subscribe_3461a1b24f33" to="lxy5@user-20160421db" type="subscribe" from="lxy4@user-20160421db"/>
A9, S->A ,收到了iq roster set节
此时 A(to)B
<iq xmlns="jabber:client" type="set" id="476-570" to="lxy5@user-20160421db/6ws7h81i8t"><query xmlns="jabber:iq:roster"><item jid="lxy4@user-20160421db" name="lxy4" subscription="to"><group>家人</group></item></query></iq>
A10, A->S,对A8的确认
<iq from='lxy5@user-20160421db/Spark' type='result' id='476-570' xmlns='jabber:client'/>
A11,S->A 收到了B对自己的同意节
type = subscribed
<presence xmlns="jabber:client" id="subscribed_3461a1b253105" to="lxy5@user-20160421db" type="subscribed" from="lxy4@user-20160421db"/>
A12, S->A 收到了B的出席节
因为A(TO)B了,A已经订阅了B了,所以A可以获得B的出席节。
此时B的状态是在线
<presence xmlns="jabber:client" id="presOnline_34616a538b258" from="lxy4@user-20160421db/and4ahzwoc" to="lxy5@user-20160421db/6ws7h81i8t">
<status>在线</status>
<priority>1</priority>
</presence>
此图3个红框,从上到下,从左到右依次是:
A收到了B同意添加其为好友
A方收到了B的好友申请,
A因为订阅了B,收到了B的出席节。
A点击不同意B加自己为好友
A13, A->S 发送
prensence type = unsubscibe
<presence id='unsubscribe_3461aeeee4726' to='lxy4@user-20160421db' type='unsubscribe' from='lxy5@user-20160421db' xmlns='jabber:client'/>
B10, S->B 收到了设置好友subscription为none的节
<iq xmlns="jabber:client" type="set" id="92-572" to="lxy4@user-20160421db/and4ahzwoc">
<query xmlns="jabber:iq:roster">
<item jid="lxy5@user-20160421db" name="lxy5" ask="subscribe" subscription="none">
<group>我的家人</group>
</item>
</query>
</iq>
B11 , B->S 对B10的确认
<iq from='lxy4@user-20160421db/and4ahzwoc' type='result' id='92-572' xmlns='jabber:client'/>
B12, S->B B收到了不同意加为好友的节
type=unsubscribe。收到这个节就发送remove
<presence xmlns="jabber:client" id="unsubscribe_3461aeeee4726" to="lxy4@user-20160421db" type="unsubscribe" from="lxy5@user-20160421db"/>
B13, B->S 发送remove
<iq id='setIQRosterRemove_3461aeef1b678' type='set' xmlns='jabber:client'>
<query xmlns='jabber:iq:roster'>
<item jid='lxy5@user-20160421db' subscription='remove'>
<group>我的家人</group>
</item>
</query>
</iq>
B14,S->B 收到服务器发送来的remove
此时将A从自己的界面中除去
<iq xmlns="jabber:client" type="set" id="521-575" to="lxy4@user-20160421db/and4ahzwoc">
<query xmlns="jabber:iq:roster">
<item jid="lxy5@user-20160421db" subscription="remove"/>
</query>
</iq>
B15, B->S 对B14的确认
<iq from='lxy4@user-20160421db/and4ahzwoc' type='result' id='521-575' xmlns='jabber:client'/>
B16, S->B 对B13的确认
<iq xmlns="jabber:client" type="result" id="setIQRosterRemove_3461aeef1b678" to="lxy4@user-20160421db/and4ahzwoc"/>
A拒绝后,收到了remove节。联系人列表中的B就被移除了。
A14, S->A收到服务器的remove节
将B从界面移除。
<iq xmlns="jabber:client" type="set" id="207-577" to="lxy5@user-20160421db/6ws7h81i8t">
<query xmlns="jabber:iq:roster">
<item jid="lxy4@user-20160421db" subscription="remove"/>
</query>
</iq>
A15, A->S 对A14的确认
<iq from='lxy5@user-20160421db/Spark' type='result' id='207-577' xmlns='jabber:client'/>
流程图