Enabling PEP on ejabberd server - xmpp

I'm creating a chat app using the Electron Framework and node-xmpp module for XMPP communication.
I have managed to do almost everything except making Personal Eventing Protocol to work. Specifically sending a new nickname to the roster.
When I send the PEP stanza
<iq from='test#localhost' type='set' id='pub1'>
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
<publish node='http://jabber.org/protocol/nick'>
<item>
<nick xmlns='http://jabber.org/protocol/nick'>I am a test user</nick>
</item>
</publish>
</pubsub>
</iq>
I get a response IQ stanza:
<iq from="test#localhost" type="result" to="test#localhost/testapp" id="pub1">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<publish node="http://jabber.org/protocol/nick">
<item id="5D4E0BB8EB3C6"/>
</publish>
</pubsub>
</iq>
Now, according to XEP-172 example 6 I should get a Message with the nickname that is also sent to all my contacts. It should look like this:
<message from='test#localhost' to='otheruser#localhost' type='headline' id='foo'>
<event xmlns='http://jabber.org/protocol/pubsub#event'>
<items node='http://jabber.org/protocol/nick'>
<item>
<nick xmlns='http://jabber.org/protocol/nick'>I am a test user</nick>
</item>
</items>
</event>
<addresses xmlns='http://jabber.org/protocol/address'>
<address type='replyto' jid='test#localhost/chatapp'/>
</addresses>
</message>
The thing is I'm not getting any message to other contacts in the user's roster. Not even to myself.
Is there any step I'm missing to enable PEP on a ejabberd server? Any extra stanza or information I should include?
Thanks!

If you want to receive other users' nickname events you should include http://jabber.org/protocol/nick+notify string into your Entity Capabilities list.
See Filtered notifications for detailed description.

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>

Get last message of each conversation with XEP-0313?

I'm using an XMPP server that implements XEP-0313 for retrieving conversation history. I would like to fetch only the last message of each conversation, so that I can build a list of your most recent conversations previewing the last message.
I've managed to fetch all messages of all conversations and based on that I could build the list, but it's a big waste of data and not an option. I'm not sure this is the right extension for accomplishing this, so if there is another extension I should be looking at, please guide me in the right direction.
One thing you can do easily is first retrieve the user's roster and then for each contact retrieve the latest message.
<iq from='juliet#example.com/balcony'
id='bv1bs71f'
type='get'>
<query xmlns='jabber:iq:roster'/>
</iq>
Result:
<iq id='bv1bs71f'
to='juliet#example.com/chamber'
type='result'>
<query xmlns='jabber:iq:roster' ver='ver7'>
<item jid='nurse#example.com'/>
<item jid='romeo#example.net'/>
</query>
</iq>
Retrieve the last message from or to nurse#example.com:
<iq type='set' id='juliet1'>
<query xmlns='urn:xmpp:mam:1'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE' type='hidden'>
<value>urn:xmpp:mam:1</value>
</field>
<field var='with'>
<value>nurse#example.com</value>
</field>
</x>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>1</max>
<before/>
</set>
</query>
</iq>
Of course users can have conversations with people not on their roster, but in practice this is quite rare on XMPP.

Chat process in XMPP Openfire server using Android application

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.

XMPP PubSub retrieve node's subscribers

I have a PubSub node with two subscribers: Joe and Mike.
I want to retrieve them as a list of subscribers and when I do
<iq type='get'
from='francisco#denmark.lit/barracks'
to='pubsub.shakespeare.lit'
id='subscriptions2'>
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
<subscriptions node='my_node'/>
</pubsub>
</iq>
the result is
<iq type='result'
from='pubsub.shakespeare.lit'
to='joe#denmark.lit'
id='subscriptions2'>
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
<subscriptions node='my_node'>
<subscription node='my_node' jid='joe#denmark.lit' subscription='subscribed' subid='123-abc'/>
</subscriptions>
</pubsub>
</iq>
It doesn't show that Mike is also subscribed to the same node.
And if I make the same query from Mike's account it shows that Mike is the only subscriber and does not include Joe.
Only the node owner can retrieve the list of subscribers.
And the namespace should be "http://jabber.org/protocol/pubsub#owner" for such request.

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>