XMPP: count of unread messages - xmpp

I'm trying to implement chat for my webapp with following features:
When user logs in he should see a number of unread messages (which is both offline messages and "unseen", I will explain "unseen" in next step).
When user is anywhere in the app but on chat window he should be notified that he has a new message. Message should be marked "unseen" and must be added to the count of unread messages.
The first point is quite easily achieved using XEP-0013: Flexible Offline Message Retrieval. So I can retrieve offline messages and when I'm sure user has seen them - I remove them from unread list. But the problem is: how do I achieve same thing for "unseen" messages?
In short what I need is: any message should be marked as offline, unless user sees it and it's removed from the list by explicit request.
Can I achieve that with XMPP and how do I do that?
Thanks in advance.

What you are trying to do is to basically store a counter of unseen stuff in your account. I think you do not need flexible offline retrieval as when you connect the messages would simply become unseen. You thus only have to deal with one case: Unseen.
I will reply from the perspective of ejabberd, that I know better as one of the developer: I would use private storage to store your current state of unseen count and conversation.

Related

check weather the user readed data or not in flutter using firestore

I was developing the chat app in flutter using firestore, the users successfully chat one-to-one. but I also want to send the notification to the user that someone sends him/her a message. For that I decided to use the cloud messaging service of firebase, but how can I check that the user read the message or not.
There is nothing built into Cloud Firestore to track which user has read a specific document already.
The two most common approaches that I know of are:
To track for each individual message and each individual user whether they have read it, so by keeping a list of the user IDs in each message document. While this potentially stores a lot of extra data, it is the most direct mapping of your use-case.
In most chat apps though, tracking of what messages each user has read is done as an "up to here". So if the user has read all messages up until a certain one or a certain time, the assumption is that they've also read all the messages before that one/moment.
For this model you can instead just keep a single document ID or timestamp for each user (i.e. readUpTo), instead of having to mark each message for each user that has read it. In your UI, you then determine whether to show each message as unread based on the message ID/timestamp compared to the timestamp of readUpTo.

MAM XEP-0313 - Query conversation list for a particular user

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.

Count total XMPP session in multiple tabs/window

I also have a same problem as mentioned here. But, I went ahead with the approach of randomizing my resource so as to maintain the session in multiple tabs/windows. Also, I get carbon message (LINK) in all tabs/windows.
My only concern is, I'm saving chat history using (store.js) in my browser. And if 5 tabs are opened, then message gets saved 5 times. Which is a repeat.
How can I determine to how many tabs/windows the message was sent?
Based on the count I want to apply my logic to save the message only once.
You can count the number of tabs from Javascript because, you are sandbox to your own tab for security reason.
However, what you can do is ensure your client have unique id on the message tag and you can check on write if your message has already been written in your store or not.

RabbitMQ Structure For Private Messaging

I am currently looking to buildout a messaging service where users can send and receive messages privately between each other. I may have a need for multi-user chat, but for the most part, I only want single recipients to be able to read messages sent to them.
With looking at RabbitMQ, does it make sense to use one exchange, and create a queue for each user when they login and destroy each queue on logout? Are there major performance issues with creating a queue for each user or are there better alternatives?
I am building a REST API and plan on having users send messages to others through an endpoint (/send) and subscribe to their own message streams via websockets or something similar. I will probably store messages in MongoDB as well, so users can access all of their previous messages. Any suggestions on structure are appreciated.
I think your approach is correct. You event don't need an exchange if you will use the default exchange (AMQP Default). And during login create a new queue and keep queue name same as user name. (Just need to make sure user names are unique) And if you publish message to the default exchange with username (ie: queue name) as routing key, RbbitMQ will route that message to that queue only. And on logout if you delete the queue then user is going to miss the messages when he is not online. If it is OK then create queue after login and use the configuration exclusive which says queue gets deleted when there is no consumer. But if you want to keep offline messages then you need to create queue permanently during user signup.

Facebook Graph - What is the limit to send private messages from page to users?

I am developing a chat robot that works with private messages on facebook. The person sends a private message to a page that I own, and then I will send an answer for each message.
Everything is working, but I need to be sure facebook won't complain about the amount of messages I will send. This application will receive a lot of interactions at the same time, but in some early tests one of my messages were received like that:
http://cl.ly/image/1C1n0Z2L0R05
I am now using Batch Requests to send all messages, on an interval of 15s.
Do someone know some way to test it with multiple users and multiple messages at the same time? How the process of identification of spam messages work on facebook? How many messages can I send at the same time and in what time range to prevent that kind of behaviour?
Thanks.
There is no set limit or guideline on volume.
But really volume should not be the issue. There's a huge number of factors that is taken into account to determine if a message is spam... too many to discuss here. But you can assume basics: the content of the messages, the volume per user in a given time period, the content variation per user, has this app been flagged as spammy before, by how many users, etc. I would say its reasonable to assume your test user is probably going to be triggered as spammy because you're likely using it far far more than the average user would.
So, in short: it depends entirely on what exactly you're doing every 15 seconds.
Tip (although I cannot verify it): if you are trying to batch send a message to a number of users at once, without them very recently contacting you, you're probably gonna be flagged as spammy.