Search code examples
javascriptlistenervelocorvid

What the best way to refresh a wix repeater when a new message receive


I created a chat messenger between my website users based on wix repeater when a new msg launch a new row insert into chat collection (my chat collection including the following fields User A, User B, MSG ) and the messenger repeater should refresh for both users.

So if user A send a message to User B

I should do the following :

  1. a new row inserts into DB.
  2. User A repeater is refresh.

3. Refresh user B repeater

What is the best way to Refresh user B repeater?

I used afterInsert() to know which user received a message and when but now I need to send this user a trigger for a refresh.

I thought about sendMessage function after insert to this specific user and then refresh User B repeater when a new msg received (use onMessage ). the main problem is that I don't use wix chat so I can't generate channelId, If there was an option to send a message from a business to a specific user without channelId or alternatively get channelId without using wix chat app, it will solve this problem.

What should I use ?


Solution

  • You can use the Realtime API to create a subscriber for the collection on the client. In your backend code in the afterInsert function, publish a message to the specific client which execute the refresh function for the list in the repeater in the callback function. You could store the channel information for the client and backend to know each other alongside your message in your chat collection.