Chat process in XMPP Openfire server using Android application - xmpp

I’m using Openfire XMPP server for a android chat application. I can connect and login to the server using my app.
Now I want to know how to send friend request and accept friend request in this chat application.
I can fetch all the user from server but I want to know the process of starting a chat.
Thanks in advance.

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.

Related

Deny messages from non-roster users in Openfire

How do I only allow contacts who are on my roster list to send me messages?
Is there any XEP responsible to do that? Or will I need to do this client-side?
Yes, OpenFire supports XEP-0016: Privacy Lists (see this question), which can be used to block stanzas according to various criteria.
You can't explicitly block stanzas for contacts not in your roster, but you can block by subscription status none, which can more or less accomplish the same goal. You could send something like this:
<iq from='romeo#example.net/orchard' type='set' id='msg3'>
<query xmlns='jabber:iq:privacy'>
<list name='message-sub-example'>
<item type='subscription'
value='none'
action='deny'
order='5'>
<message/>
</item>
</list>
</query>
</iq>
This creates a privacy list called message-sub-example, containing a rule to block any messages from contacts with subscription type none, including contacts not in the roster. For this list to take effect, you need to make it the active list:
<iq from='romeo#example.net/orchard' type='set' id='active1'>
<query xmlns='jabber:iq:privacy'>
<active name='message-sub-example'/>
</query>
</iq>

how to retrieve items from pep pubsub xmpp protocol

How can I retrieve items using PEP pubsub XMPP protocol? I don't know how to retrieve history of PEP events. I tried with this stanza, but I am getting an "item not found" error.
<iq type='get'
from='admin#domain.ddns.net'
to='pubsub.domain.ddns.net'
id='items1'>
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
<items node='http://jabber.org/protocol/tune'/>
</pubsub>
</iq>
You're sending the request to pubsub.domain.ddns.net, i.e. a Pubsub service, but when using PEP, you need to send the requests to the bare JID of the contact, e.g. user#domain.ddns.net. See XEP-0163 for more details.

Retrieving offline messages not working -XMPP wokkel

I have an XMPP chat client using wokkel and twisted and it works fine, but when a user comes online, I send this stanza to get the messages a user received while offline:
<iq type='get' id='fetch1'><offline xmlns='http://jabber.org/protocol/offline'><fetch/></offline></iq>
Other messages send and receive just fine but this stanza never returns anything. Any ideas how to debug or what the issue is? (These are google talk users)
Update: Google talk in theory supports XEP-0136 (archiving). When you get a list of support features you get:
<feature var='http://jabber.org/protocol/archive#otr'/>
<feature var='http://jabber.org/protocol/archive#save'/>
However, when I then follow this: http://xmpp.org/extensions/xep-0136.html#manage-retrieve
as to how to retrieve archived messages. I send the following stanza:
<iq type='get' id='page1'><retrieve xmlns='urn:xmpp:archive'/></iq>
[Whether or not I include the tag part of their example, I get a feature not support error back from Google's XMPP server]
<iq xmlns='jabber:client' to='x#gmail.com/7EBA7137' type='error' id='page1'>
<retrieve xmlns='urn:xmpp:archive'/><error code='501' type='cancel'>
<feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>

Facebook self vCard

Hi I want to get profile picture of my own. So After login, I am sending below IQ packet and getting the below mentioned response but it does not contain any Picture details.
Can anyone please help me what is the reason.
Reguest:
<iq to='-100002643606171#chat.facebook.com' from='' id='v1111' type='get' xmlns='jabber:client'>
<vCard xmlns='vcard-temp'/>
</iq>
Response:
<iq id="v1111" to="XXXXXX#chat.facebook.com/8hAKe3RdK1_51d153db_4AFBBB1DF508F" from="-100002643606171#chat.facebook.com" type="result">
<vCard xmlns='vcard-temp'>
<FN>Req Lee</FN>
</vCard>
</iq>
To get your own vCard, you should leave out the to attribute, or set it to your bare JID, like to="XXXXXX#chat.facebook.com".
<iq type="get" id="myvcardplz">
<vCard xmlns="vcard-temp"/>
</iq>

XMPP multi-user-chat get user list

get a list of all users and the status of XMPP multi-user-chat
I do so
<iq from='hag66#shakespeare.lit/pda'
id='kl2fax27'
to='coven#chat.shakespeare.lit'
type='get'>
<query xmlns='http://jabber.org/protocol/disco#items'/>
</iq>
getting a list but without status.
I need for all users on the statuses to know?
Please read XEP-0045, which describes the multi-user chat (MUC) protocol. You need to join the room:
<presence
from='hag66#shakespeare.lit/pda'
to='coven#chat.shakespeare.lit/thirdwitch'>
<x xmlns='http://jabber.org/protocol/muc'/>
</presence>
You'll then get a presence stanza from each occupant of the room with their current status:
<presence
from='coven#chat.shakespeare.lit/firstwitch'
to='hag66#shakespeare.lit/pda'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<item affiliation='owner' role='moderator'/>
</x>
</presence>
<presence
from='coven#chat.shakespeare.lit/secondwitch'
to='hag66#shakespeare.lit/pda'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<item affiliation='admin' role='moderator'/>
</x>
</presence>
And before you ask, no, there is no way to tell when you're "done" receiving these notifications, since users may come and go at any time. You are now subscribed to the presence changes of the occupants, and have to keep track of what is current on the receiving side.
Reading through the XMPP RFC, I see that statuses are conveyed by presence messages, and that you ask another entity to report its status now (rather than waiting for it to tell you in a broadcast) by sending a probe status request to which you'll get a directed response (§5.5 of the RFC gives some examples). It's up to you to interpret what they say back correctly, of course…