Message notifications

Kevin B Posted in Component Development 3 years ago

Hi guys
Just looking for advice from anyone that might be able to help?

I've created a chat component but feel I need to change how I perform some of the functions.

My component is making use of the API.

Checking for new messages: I have an Ajax function running every 3 seconds that checks the notifications API for a Messages count above 0. If there are new message notifications, it uses the messages API to mark all messages in that thread as read, and then refreshes the messages on screen. This gives the desired result, but if I receive a message from somebody who I'm not chatting with, it refreshes the current message thread anyway. It would be useful if the message thread could include an ID, and if the notifications API could include the message thread id in the notifications array?

That way I only need to refresh the currently displayed thread if it receives a new message.

It would also be useful if I could mark just the messages in the current thread as "read" instead of all messages.

Is this functionality already available somewhere? Or can anybody suggest a better way of implementing this?

I also play a notification sound when a new message is received, but if it's for a thread I'm not currently viewing, it pings every time it checks, until I load that thread and mark the messages as read.

Any advice greatly appreciated.

Replies
gb Kevin B Replied 3 years ago

Excellent! Thank you.

That will also allow me to ensure I only play the new notification sound if that figure increases :)

Indonesian Arsalan Shah Replied 3 years ago

You should see this just created example : https://github.com/opensource-socialnetwork/UnreadMessagesCountAPI

Custom Unread Messages API

gb Kevin B Replied 3 years ago

Yes I think that's nailed it. If there was a user id associated with the notification that would probably resolve most of the hurdles I have.

Indonesian Arsalan Shah Replied 3 years ago

Ok what I understand is you can able to read messages in one thread example only between user a and user b. But the problem is:

  1. You are using https://www.opensource-socialnetwork.org/webservices/view/3611/notifications-count endpoint.
  2. This just gives total unread messages.
  3. You wanted to see from who you received message that is still unread?