Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chat Window Pop-up Notification #4

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/messages_controller.rb
Expand Up @@ -8,11 +8,13 @@ def create
@message.save!

@path = conversation_path(@conversation)
rip = current_user == @conversation.recipient ? @conversation.sender : @conversation.recipient
PrivatePub.publish_to("/notifications" + rip.id.to_s, cid: @conversation.id, sid: current_user.id, rip: rip.id)
end

private

def message_params
params.require(:message).permit(:body)
end
end
end
20 changes: 19 additions & 1 deletion app/views/layouts/application.html.erb
Expand Up @@ -40,5 +40,23 @@
</div>
<audio id="chatAudio"><source src="/sounds/notification.mp3" type="audio/mpeg"></audio>
</body>
<% if current_user %>
<script type="text/javascript">
channel = <%= raw ('"' + '/notifications' + current_user.id.to_s + '"') %>
PrivatePub.subscribe(channel, function(data) {

var sender_id = data.sid;
var recipient_id = data.rip;
var conversation_id = data.cid;


$.post("/conversations", { sender_id: sender_id, recipient_id: recipient_id }, function (data) {
chatBox.chatWith(conversation_id);
});

});
</script>
<%= subscribe_to "/notifications" + current_user.id.to_s %>
<% end %>
</html>

</html>