rpaschoal / ng-chat

💬 A simple facebook/linkedin lookalike chat module for Angular applications.
MIT License
155 stars 92 forks source link

How to get unread messages amount on chat initialization #66

Closed rmussabayev closed 5 years ago

rmussabayev commented 6 years ago

Hi, Rafael! The chat is really great, thank you! I'd like to use it within my application, but I have a couple of questions.

  1. We have listFriends() and getMessageHistory(userId) methods. First one will be invoked on chat initialization giving us an array of users available to talk with and the second is invoked when the chat window is opened. What if user has received a message while being offline, how should I notify him about unread message on next login? My idea is to receive users and unread messages amount within listFriends() method, and explicitly call getMessageHistory() for every user, who has unreadMessages > 0. Is this a good way to go or am I missing something?
  2. The Message class has seenOn property, which is being set when the chat window gets a focus. Is there a way to send a message to the server on this event? In order to update corresponding message record in DB as read. Sorry for my english. Feel free to edit this question if you find mistakes.
rpaschoal commented 6 years ago

Hey @rmussabayev ,

I am glad you like the chat! Comments like yours give me a confidence boost to keep on adding features to this component 😸

  1. This is a very interesting question, makes me think if we need to update the adapter workflow. For this scenario, what if you do the heavy lifting on your back-end and just push the notifications to your socket/hub (I am assuming you are using socket.io, signalR or something similar) when the user connects to your hub? For example, if a user logs in to your application, you get a connection event from that user and on your database you know he has unread messages, right? So at that point, you can push those messages to him as if he had just received it. The only issue I see with this approach is that you would get tons of message notifications popping up at the same time for every message the user has received while being offline (which kind of sucks).
  2. Not for the time being, but this could be a great addition to the Events list. We could create an event such as onMessageSeen.

What do you think of my alternative for question 1? Would it be enough to just have the unread messages total count at the left when I log in, or should the windows pop up too with the offline messages? Regardless of which approach we decide to go, we might have to make changes on core adapter methods which will lead us to a new major release 1.1.0, which I believe to be about time.

Let me know what you think, I am compiling all suggestion and issues I am getting here on GitHub for the past weeks for a new roadmap development and possibly a major release. I've been wanting to do some cool animation work with the component too (Just a sneak peek, I wanna add an option to pop the windows from the side bar to a draggable window).

Looking forward to hear your thoughts on the above. By the way, your English is just fine, and who am I to judge it? English is not my first language either 😸

Cheers!

rmussabayev commented 6 years ago

Hi Raphael! Thanks for the fast reply. Seems like your suggestion to move the notification logic to the back-end is more accurate than mine and I will try to implement this workaround your way. Well, I also think that it will be annoying for the user to have a lot of windows popping up after login, but I just can't see how this issue can be bypassed with the current implementation. No matter how a client will be notified on new unseen message, chat window is going to popup, isn't it?

Would it be enough to just have the unread messages total count at the left when I log in, or should the windows pop up too with the offline messages?

Unread messages count will be totally enough for me, but I think there should be a lot of changes done to achieve that. Because currently this count is being calculated on-the-fly and to find it after login either all of the chats histories should be retrieved( what I think is too much for this kind of problem), either listFriends method should return not only a list of friends but also a count of unread messages for every record.

Is it possible to add onMessageSeen before 1.1.0 release? I can implement a temporary solution for the first question and wait for the major release, but it can't be done while I am not able to track unseen messages. It looks like a more critical feature at the moment.

Actually I am new to Angular and this is the first time I am working with websocket also, so I decided to go to with angular's Websocket interface. It just meets all of my demands for now, and I don't want to add any new library without an apparent need, so I do not use socket.io or signalR right now.

Have a good day!

rpaschoal commented 6 years ago

Hi @rmussabayev ,

listFriends method should return not only a list of friends but also a count of unread messages for every record.

^ This is exactly what I was thinking for 1.1.0 (Or possibly 2.0.0 depending on how these changes break existing applications). I want to add some metadata on this too, but this would require a major change on the adapter interface, therefore the reason why I can't release it straight away.

I can implement onMessageSeen before that and release it on 1.0.15 which is a win-win situation anyway as this will be carried over to the major release as I am not planning on a major revamp of the library.

Regarding implementation time, I can't promise it will be as fast as my replies here, but I can try to release 1.0.15 including onMessageSeen within 2 weeks max. How does it sound to you?

Cheers!

rpaschoal commented 5 years ago

Hi @rmussabayev ,

Just letting you know that this has been released with 2.0.0-rc.1.

I haven't merged the changes on the master branch yet as this is an RC release so please refer to the README on this link for instructions on the new features: https://github.com/rpaschoal/ng-chat/tree/2.0.0-rc.1

I am planning on building a .net core application with a full demo of ng-chat and all its features, and only after that I'll be moving it to 2.0.0 as it will be a good opportunity for better testing and fine tuning of this release.

Cheers!