XMPP Subscription

In my application, when I send a request to any friend using this code.

try { roster.createEntry(idExtension, nickname, null); roster.setSubscriptionMode(Roster.SubscriptionMode.manual); Presence subscribe = new Presence(Presence.Type.subscribe); subscribe.setTo(idExtension); connection.sendPacket(subscribe); return true; } catch (XMPPException e) { System.err.println("Error in adding friend"); return false; } 

then the subscription says β€œNONE” on both friends lists.

But it must be "TO" and "FROM".

But if for the same process I use this code -

 try { roster.createEntry(idExtension, nickname, null); roster.setSubscriptionMode(Roster.SubscriptionMode.manual); Presence subscribed = new Presence(Presence.Type.subscribed); subscribed.setTo(idExtension); connection.sendPacket(subscribed); return true; } catch (XMPPException e) { System.err.println("Error in adding friend"); return false; } 

Then it gives me the correct result, which I should get in the previous case.

Please tell me why I do not get the same in SUBSCRIBE mode.

thanks

+4
source share
1 answer

I assume that you are not getting type values ​​in the Presence.

subscribe - the sender wants to subscribe to the address of the recipient presence.

signed - the sender has allowed the recipient to receive their presence.

Therefore, when you send the first request, you ask the user to subscribe to his presence events and until he allows you to do this, the type of subscription is not.

In the second case, you allowed the user to subscribe to your presence, that is, give him permission to listen to your presence, and thus you will receive a type of subscription.

+3
source

Source: https://habr.com/ru/post/1440458/


All Articles