Smack-create registry entry

I know this question has been asked before, but only a partial answer was given by mschonaker here . On my site, the user can add people to his list, then the friend must accept and finally connect. The first person (user a) uses the famous

roster.createEntry(jid, name, groups);

which works and adds an entry to my list, but then I'm a little confused about what to do:

  • How do I get a request at the other end? I tried implementing PacketListener, overriding processPacket () and checking for a package whose type is Presence.Type.subscribe or Presence.Type.subscribed, but it seems to run only for user a, but not the one that should listen to subscriptions - user b .

  • then I have another function that can search for all requests at the login, so if I log in again, I will see the request, but how to accept it? firstly, I thought user b should also add the user to his roster.createEntry(jid, name, groups); list roster.createEntry(jid, name, groups);

but it did not work, and nothing happened. I also tried to do

 Presence subscribed = new Presence(Presence.Type.subscribed); subscribed.setTo(jid); xMPPConnection.sendPacket(subscribed); 

but does not work. I'm sure there should be a good and easy way to do this, but I haven’t found it anywhere, and having tried one thing at a time, I had too many headaches. Does anyone know the correct thread for this? thanks in advance!

+6
source share
1 answer

From the Smack documentation: The registries and presence use a permission-based model in which users must give permission before they are added to the list of other users. This protects user privacy by ensuring that only approved users can view their presence information. Therefore, when you add a new registry entry, it will be in a waiting state until another user accepts your request. If another user requests a subscription to attend, so they can add you to their list, you must accept or decline this request. Smack processes presence subscription requests in one of three ways:

 Automatically accept all presence subscription requests. Automatically reject all presence subscription requests. Process presence subscription requests manually. 

The mode can be set using the Roster.setSubscriptionMode (Roster.SubscriptionMode) method. Simple clients typically use one of the auto-subscription modes, and full-featured clients must manually process subscription requests and allow end users to accept or decline each request. If you use manual mode, you must register a PacketListener that will listen for presence packets of type Presence.Type.subscribe.

So, try setting the Roster subscription mode to manual, and then implement PacketListener to listen to Presence.Type.subscribe. After receiving the package, create a new package with presence. Enter your subscription and send it to the sender.

+4
source

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


All Articles