Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
Derek #1
Member since Jun 2006 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: Automatically subscribe
I'm trying to figure out how to make a user automatically subscribe to a user who subscribes to them. ie. User 1 subscribes to User 2, so User 2 automatically subscribes to User 1.

Putting the subscribe command in the presence event of type subscribe or subscribed obviously makes an infinite loop. Putting it in the rosteritem event works, but it seems this event is called multiple times for one subscription (I'm not sure why this is), causing undue traffic.

If there was some way to see if I was already subscribed to someone, it would be pretty easy...but I don't see how to do that either. Does anyone have any ideas?
Avatar
Jabberer #2
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
Hello Derek,

Normally when you get a subscription request you show a form to your user with "Accept" or "Deny" request. When the user accepts the subscription then it's a good idea to add the reqesting contact also to the roster and subscribe to him (If the user is not already on your roster). PSI has 3 buttons on this form which i think is a good idea, "Accept", "Deny", "Accept and Add".

Some clients have an option like "automatically accept all subscriptions", and i think this is what you are doing here. This is exactly the same, you have to check if this user is already in your roster, and if you are subscribed to him to avoid unnecessary traffic and ping pong effects. If your client manages and shows the roster then you must have a control or some collection which keeps the roster. And this is where you should lookup this information. We store the complete RosterItem object with our Roster, then we have access to everything we need. When the subscription state or smth else changes then you have to update your collection. But the server will send you the new RosterItem and you will get a OnRosterItem event from XmppClientConnection. The RosterItem object contains jid, nickname, subscription, ask and groups.
Software Developer
AG-Software
Avatar
Derek #3
Member since Jun 2006 · 6 posts
Group memberships: Members
Show profile · Link to this post
Thanks for the quick response!

Yes, that is exactly what I'm doing. I have it automatically accepting subscriptions. I think I get what you're saying. In the miniclient, is the collection that keeps the roster just that control in the main form? Or is there an actual collection somewhere else? Obviously this is what I was missing though, I need to keep track of the roster on the client. Thanks!
Avatar
Jabberer #4
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
it's the control which holds the data. It's possible that you have to modify it for your case. The most people use this GUI controls only as a start and modify them, other wise all clients would look the same and this is not what the programmers want. This is also the reason why there will not be many updates or changes to the UI controls.
Software Developer
AG-Software
Avatar
[gja] #5
Member since Jul 2009 · 19 posts
Group memberships: Members
Show profile · Link to this post
Subject: same problem
i had problem also on how to handle this.

i have a form2 aside from my main form..now, the function of form 2 is to accept address(email add. like..)and button "Inquire" to check if that address is online/offline..in button "Inquire" i placed code to ask subscription to that address.and add to my rosteritem if the user is not on my buddy list..adding new contact in rosteritem would trigger the OnRosterItem event right?..

my current progress now,if i clicked the button "Inquire" so,it will check if the user is already on my roster and if not i send subscription request..and add that contact to my roster..the problem is,the inquire_click() event would finish first before that contact added to my roster..if i clicked twice the inquire button i am now able to see the contact online..

to get whos online i made an arraylist storing users whoever is online..and removed user if it is unavailable..this is where i looked up to get status of a user..but this working only if the subscription is mutual.or if i have subscription to that user..how about if i am not subscribed?..i placed the code in Onpresence event..

thank you in advace
glen
Avatar
Alex #6
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by [gja:
]
i have a form2 aside from my main form..now, the function of form 2 is to accept address(email add. like..)and button "Inquire" to check if that address is online/offline..in button "Inquire" i placed code to ask subscription to that address.and add to my rosteritem if the user is not on my buddy list..adding new contact in rosteritem would trigger the OnRosterItem event right?..

in both cases it will trigger an OnRosterItem event. When the contact is already on your roster and subscribed you should not add it and subscribe again. If you do so the AddRosterItem does a roster update and triggers the event. Normally updates are used to change the Nickname.

Quote by [gja:
]
my current progress now,if i clicked the button "Inquire" so,it will check if the user is already on my roster and if not i send subscription request..and add that contact to my roster..the problem is,the inquire_click() event would finish first before that contact added to my roster..if i clicked twice the inquire button i am now able to see the contact online..

thats normal, becuase agsXMPP handles everything async. You can use AutoResetEvents or similar technologies to mimic synchronous behaviour.

Quote by [gja:
]
to get whos online i made an arraylist storing users whoever is online..and removed user if it is unavailable..this is where i looked up to get status of a user..but this working only if the subscription is mutual.or if i have subscription to that user..how about if i am not subscribed?..i placed the code in Onpresence event..

you only get presence of a user when you are subscribed to them. Unlike other protocols XMPP is secure and you can control who gets your presence and who doesn't.

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS