You’re not receiving notifications from this thread.
Direct Messages in Realtime with ActionCable Discussion
Shouldn't be better to create a model lets say conversations with both users "sender and receiver" and maybe make messages a polymorphic association between rooms and conversations?
A bit counterintuitively, that actually makes things more complex if you treat direct messages that way. By doing that you complicate the database significantly because now you can't simply join tables since you're using polymorphic assocations. Plus your direct messages no longer have a Chatroom object meaning all your messaging code on the frontend and backend need to account for the different types and treat them differently.
Hey Chris, thank you for this tutorial. I asked about it a few weeks ago and I got to a solution with your feedback but it was not as technically sound when I did it on my own and it didn't work as well tbh. Have you considered doing something with WebRTC for video/voice conferencing or using something like Twilio, Pusher etc, I think that would be a kickass project and could complement this one pretty well. :) Looking forward to all the new screencasts!
Hi Chris. I have a question for you. I was playing with the code and wanted to color the username depending on if you are or if you are not the speaker.
I was able to color code the user (mine or others) depending on the speaker name on the view side but the channel seem to be quite different as it streaming to both. I simply compared User.find(message.user_id) to current_user.
On the channel side (used for updating the messages after you have reached the page), I am not sure how to introduce that test?
I would say either do client side or server side generation of colors. Server side, you could save a "color" attribute on the user that's an RGB version of their username so you only have to generate it when they sign up. You can pass that value over the websocket and use it for rendering of messages
If you went with the client side, you could have it generate the colors on all the existing messages on the page (might need to add a data attribute for the username) and then apply the colors to the existing messages on page load, and then add it to the new messages afterwards. You can just simply store those on the
style="" attribute on the span around the username so that it's added directly to the record.
Either approach would work fine. The client side one is more likely to be simpler and less data intensive because it can generate colors on the fly without storing them. I would probably go with this approach personally.
Has someone seen support for file attachment using actionable?
You'll actually want to combine websockets with direct uploads (see: https://gorails.com/episode... ) in order to accomplish this. You don't want to upload files via websockets because they're not a good medium for this. Instead, you can upload files like you normally would and then you can use the response JSON from the upload to include the file in your application.
For example, Slack file uploads submit an AJAX file upload, you send over the message via ajax so you can upload the file and then once that's complete, it broadcasts it over websockets.
Here is a question. I am developing a feature where users can direct message other users directly, without the whole chatroom.
Is it possible to use actioncable the same way to have it set up this way:
A user clicks on a "chat" button on another user's profile.
It opens a little chat box in the same window (facebook chat for example)
Ability to message other users directly through that.
Hi there. If wanted to build a 1-to-1 direct message system for my application, would you suggest I build the prototype from "Group Chat with ActionCable" series first to get started? It's hard to know how I should approach this since you are starting off this video by using code already built in a previous series. Any help is greatly appreciated. Thanks!