Schwack is a clone of the business communication platform, Slack. Schwack gives users the ability to create their very own channel, or already join a pre-existing one. In these channels, users can chat through live messaging.
Editing and Deleting both happen in real time updating other users chats after completing the action
I used Action Cable in order to accomplish these real time update features
const createConnection = (currentUserId, channelId, dispatch) => {
return App.cable.subscriptions.create(
{ channel: "ChatChannel", id: channelId },
{
received: data => {
if (data.type === "REMOVE_MESSAGE") {
dispatch(removeMessage(data.messageId))
}
else if (data.message.userId !== currentUserId) {
dispatch(receiveMessage(data.message));
}
},
speak: function (data) {
return this.perform("speak", data);
}
}
);
}
class ChatChannel < ApplicationCable::Channel
def subscribed
@channel = Channel.find_by(id: params[:id])
stream_for @channel if @channel
end
def speak(data)
socket = data
@channel = Channel.find_by(id: data["message"]["channelId"])
ChatChannel.broadcast_to(@channel, socket)
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end