I've a problem with roster mechanism and I'm using JSJaC javascript library.
My case:
The user A has a simple roster that contains another user B with subscription "both". The user B has the same configuration.
When the user A is logged to openfire, I call my "getRoster()" function that returns the user's list of friends (in my case, only the user B), but how I can check if user B is currently available to chat?
I see that there are some presence mechanisms, but I don't understand how I can use these.
Sorry for my poor english. Thanks.
When you send your own presence to the server then server starts sending all the presences of your subscribed contacts to you. You have to consider all contacts as offline by default.
I am not familiar with JSJaC, but there is probably a callback where the presence comes in.
You should register a presence handler. Assuming you have roster as array of user data you can do it like this:
xmpp.registerHandler 'presence', (response) ->
user = _.find #roster, jid: (response.getFrom().split '/').shift()
if user
if response.getType() is 'unavailable'
user.online = no
else
user.online = yes
Related
We are building a chat app using latest ejabberd and there is a use case where user A blocks user B. the requirement is to hide last seen or user's presence from each other. if A blocks B then its easy to hide these information from user A but how can user B be informed that user A has blocked them ? whats the best approach to tell user B the someone has blocked them on realtime while both are in a conversation , like whatsapp does now.
For presence, you do not have to use block, you can simply remove contacts from roster. That way, the other user is notified and can also stop sharing his presence.
There is XEP-0191: Simple Communications Blocking:
https://xmpp.org/extensions/xep-0191.html
https://xmpp.org/extensions/attic/xep-0191-0.2.html
I think it will give you the answers you need. Now it depends how will you implement this functionality using chosen client library like Smack.
I am developing a mobile messaging app (ios) and I support the logout feature. I want to keep the latest conversation list when the users logs in back again. Because the local storage of the app gets cleaned once logout.
I am using MAM XEP-0313 sucessfully but I have not found an IQ to query the conversation list of a particular user.
For example:
chat
user_a -> user_b
user_c
user_d
user_f
user_a has had conversations with 4 users and he wants to logout of the app, when he comes back in he needs to get those last 4 conversation threads on his list.
What I do when a user messages another user is that I add them to my roster and have the logic of automatic subscription. So I was thinking to use the roster history logic to query this collection but I was also expecting the MAM module to have a more direct way..
I am using MongooseIM server
I understand your problem, the solution you have is probably the best one you can have with standard XEPs and their implementations.
The conversation list is actually sth missing in MAM spec or in general in XMPP. There are some works to define an extension to get you all the conversations where you have some unread messages (so called "unread sync"). Will this be enough for you or you would rather want to get some kind of "inbox". By "inbox" I mean a list of all recent conversations with unread messages count where there are some unread messages.
I am using smack 4.1 now. All i want to reload/refresh roster after sending a presence and get the changes in new roster.
For example
I have an entry of user 'A' with type none and status null in Roster
then i have sent an subscribe presence for above entry of user 'A'
now i want to fire a reload and wait till roster not get refreshed(its different from Roster.reloadAndWait() method provided in smack)
After roster refresh i would get entry of user 'A' as type=none and status=subscribe.
So my question here
Is there a simple blocking call to reload fresh roster? According to my study roster.reload() would send an IQ to reload but it won't block the call till reload. reloadAndWait() method also does the same thing from 2nd and onward calls with the help of boolean isLoaded. reloadAndWait method would only block the call for first time if its not loaded(correct me if wrong).
Is there any way to get a callback when roster reload operation completes(sync or async) in smack?
Is it possible to make a request for reload of a single RosterEntry?
Is it good practice to verify the impact of presence change through roster refresh?
Thanks for your valuable suggestion and answer
The general approach is not to require the roster from server more than once during a session.
The expected workflow in XMPP is as follow:
Request the roster at the start of the session. This is not mandatory but commonly done. See for reference RFC 6121 Retrieving Roster on Login
Update your in memory roster state based on the roster change you perform. Not that you will receive roster changes confirmation no matter if this is your current session performing the change or another client logged in with same JID (Roster Set result or Roster Push).
Doing that, you will always have an in-memory representation of your roster which is up to date during your whole session. This is the workflow XMPP was designed for.
I want my users to invite their friends by sending them Facebook private massage. I am thinking of using send button, but the problem is that each invitation url is different and unique, so if I use send button to do it, I might need to create many send buttons each of which carries an unique href. I think this should work? But ideally, I want users to just select their friends in a multi friend selector and everything's done by just clicking the sending button. Any ideas?
Thanks for any help!
You can generate a unique URL for the message that includes the IDs for all the users the user wants to send the message to. Then, when the recipient accesses the URL and authenticates themselves, you can cross reference the URL and their User ID to what you have in your database.
Without knowing what the message contains, its purpose and what you want to achieve, this is the best approach I can think of.
You won't be able to tell who the message is actually sent to, as Facebook doesn't return the User IDs in the callback, but if you have read_inbox permissions, you should be able to look the User IDs up that way.
i think an better way to approach this is set up an invite system, have an invitation code field in your register.php that you sign into, store that info in user account database and set an number of times it can be used
I'm learning XMPP and I repeatedly see the word "Roster" but I have no idea what it is.
contact list (in XMPP this is called a "roster")
Source: XMPP-IM - RFC 6121 ยง 1.3: Requirements
In XMPP, one's contact list is called a roster, which consists of any number of specific roster items, each roster item being identified by a unique JID (usually of the form contact#domain). A user's roster is stored by the user's server on the user's behalf so that the user may access roster information from any resource.
Note: There are important interactions between rosters and subscriptions; these are defined under Integration of Roster Items and Presence Subscriptions, and the reader must refer to that section for a complete understanding of roster management.
See http://xmpp.org/rfcs/rfc6121.html#intro-requirements
Let me know if anybody have any queries regarding xmpp/chat app in Android.
Roster is the name given to the list of contacts which appears in one's chat client
http://www.adarshr.com/fun-with-xmpp-and-google-talk-part-2