0
votes

I am developing an internal chat system using OpenFire and JsJAC. I wanted everyone logged in to automatically be friends with one another, but since there is no good way to automatically make everyone friends I decided to use the subscription plugin and send along a subscription request to anyone not on your roster. The subscription plugin automatically accepts the request.

This is working now, however I'm unable to set the nickname for the new roster entry.

Here is the code I'm using:

    //Send friend request
    var subscribe_packet = "<presence to='"+this.sender+"@"+chatManager.args()['domain']+"' from='"+chatManager.args()['username']+"@"+chatManager.args()['domain']+"' type='subscribe'>";
    subscribe_packet += "<nick xmlns='http://jabber.org/protocol/nick'>TestTest</nick>";
    subscribe_packet += "</presence>";

    console.log("Subscribe packet: "+subscribe_packet);
    con._sendRaw(subscribe_packet);

This gives the following XML output as an example:

<presence to='[email protected]' from='[email protected]'><nick xmlns='http://jabber.org/protocol/nick'>TestTest</nick></presence>

This sends the subscription request, but the nickname is either not sent or not properly interpreted by OpenFire.

Any thoughts?

2
Turns out this isn't an issue with JsJac. Openfire appears to not follow XEP-0172, specifically the "including nickname with subscription request". Anyone have a workaround for this? - Jason Palmer

2 Answers

1
votes

This took me forever to find! I was using xmpphp, but got the solution from using jquery Strophe.

First do:

<iq type='set' xmlns='jabber:client' id='9155:sendIQ'>
        <query xmlns='jabber:iq:roster'>
                <item jid='user@localhost' name='usernickname'/>
        </query>
</iq>

Followed by:

<presence to='user@localhost' type='subscribe' xmlns='jabber:client'/>

Then to rename again:

<iq type='set' xmlns='jabber:client' id='9155:sendIQ'><query xmlns='jabber:iq:roster'><item jid='kafkav2@localhost' name='kafkav2RENAME'/></query></iq>

Hope this helps, because I was using the same XML you were using above and that did not work.

0
votes

Jason, XEP 0172 doesn't involve any actions taken by the server. You need to make your client deal with the nickname. To do so check for a given nickname when receiving a subscription request and then use this nickname when adding the newly subscribed user to your roster.

Btw: It is not a good idea to use _sendRaw (it's a private method, thus the _). A more cleanly solution would be to extend the JSJaCPresence prototype with methods getNickname and setNickname.