The processes are a bit more complex than it looks to add/accept friend requests you need to do some juggling with presence
and and roster iq
stanzas.
I'll try to give you an indication about what stanzas are sent/received using contacts operations below.
1. Add contact
To add a contact you need to send a `subscribe` stanza.
<presence xmlns="jabber:client" to="you@app.com/123" id="9VO8j-1" type="subscribe" from="me@app.com/1234" />
1.1. Request accepted
When adding a contact and the other app "accepts the request" you receive two stanzas:
1. <presence xmlns="jabber:client" from="you@app.com/123" id="9VO8j-1" type="subscribed" to="me@app.com/1234" />
2. <presence xmlns="jabber:client" from="you@app.com/123" id="9VO8j-2" type="subscribe" to="me@app.com/1234" />
3. <presence xmlns="jabber:client" from="me@app.com/1234" id="9VO8j-3" type="subscribed" to="you@app.com/123" />
1.2. Request Denied
When the request is denied you receive an "UNSUBSCRIBED" stanza.
Example: <presence xmlns="jabber:client" from="you@app.com/123" id="9VO8j-1" type="unsubscribed" to="me@app.com/1234" />
2. Accept contact request
1. <presence xmlns="jabber:client" from="me@app.com/1234" id="9VO8j-1" type="subscribed" to="you@app.com/123" />
2. <presence xmlns="jabber:client" from="me@app.com/1234" id="9VO8j-2" type="subscribe" to="you@app.com/123" />
3. Deny contact request
<presence xmlns="jabber:client" from="me@app.com/1234" id="9VO8j-1" type="unsubscribed" to="you@app.com/123" />
4. Remove contact
When you "Delete" a contact you should be in fact be "deleting" it locally in your app and from the roster.
This is done by sending two stanzas:
1. <presence xmlns="jabber:client" from="me@app.com/1234" id="9VO8j-3" type="unsubscribe" to="you@app.com/123"/>
2. <iq from='me@app.com/1234' id='ah382g67' to='you@app.com/123' type='set'>
<query xmlns='jabber:iq:roster' ver='ver34'>
<item jid='you@app.com/123' subscription='remove'/>
</query>
</iq>
Note: The use-cases described above do not include all the iq:roster stanzas associated to the presence
stanzas. These are sent automatically by the server whenever a contact changes the subscription
and ask
types.
For a better understanding of how the these workflows work in details I suggest you read the latest RFC (implemented by your server). You can find it on the office site.
See section 3. Managing the roster.