Chat with rooms

Created live chat with sockets as to Teodors tutorial, this works, except sometimes the message is emitted twice.

Any ideas why?

My application requires the ability for members who are part of separate ‘partnerships’ to communicate only with members with the same partnership_id.
This would require separate rooms to be created which could be named using the partner_id

I have added the parameter ‘partner_id’ to the chat_message socket but don’t know how the client joins the room associated with his associated partner_id.

Can anyone help?
Thanks for reading

To look at why messages are sent twice we would need to see some code.

As for the partnerships, are they separate chat rooms where everyone talks to everyone else in the partnership (like WhatsApp groups) or is it for direct chats but only to other members of the same partnership?

And are you trying to find the best way for a member to add themselves to a partnership or would this be done by an admin?

1 Like

Hi Paul
The partnerships would each have a dedicated room for their members, entry to that room should be automated.

Ok, so I assume you have recorded somewhere else in your database which users are in which partnerships?

In that case in Teodors tutorial (I am assuming it is this one), where the chat originator selects a user on the client side, restrict that list to just users who are in the same partnership by using the partnership_id in the source query.
If it is a message to multiple users and you have a list of partnerships the chat originator is a member of then use the selected partnership_id to restrict the message to only other members of that partnership.

If not the automated logic to enrol a user in a partnership is separate to the chat process.

Hi Paul thanks for your reply:

that is the crux of my problem, I don't know how to filter the contents of the local storage which contains the partnership_id, I have tried using dataview with the filter 'partnership_id==x' but referencing the dataview from the repeat doesn't seem to work??

Hi Paul
Created the the expression, below, for the repeat displaying chat data from the datastore:

<div class="row border-bottom rounded-0 border-1" is="dmx-repeat" id="repeat2" dmx-bind:repeat="chat_messages.data.where(`partner_id`, sc_current_user.data.account_type.partner_id, '==')">

but got this error
image

Doing this from my mobile so not testing or checking so apologies if it is completely wrong but do you need a .value after partner_id

repeat=“chat_messages.data.where(partner_id, sc_current_user.data.account_type.partner_id.value, ‘==’)”

1 Like

You have back ticks rather than straight quotes around the first parameter, try:

<div class="row border-bottom rounded-0 border-1" is="dmx-repeat" id="repeat2" dmx-bind:repeat="chat_messages.data.where('partner_id', sc_current_user.data.account_type.partner_id, '==')">
1 Like

Thankyou @paulBS @bpj
the code was good but I had to create a new repeat (with the expression I showed above) and it now works.

I have noticed before there seems to be some corruption in the code sometimes when the query/expression is edited and the only solution seems to be deleting and starting again.

Thanks for your help guys…

1 Like