-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
beautified the app and added online status field
- Loading branch information
Tejas Zambre
committed
May 27, 2020
1 parent
4590257
commit 50ba5dc
Showing
15 changed files
with
134 additions
and
15 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class OfflineUsersChannel < ApplicationCable::Channel | ||
def subscribed | ||
stream_from "offline_users_channel" | ||
end | ||
|
||
def unsubscribed | ||
# Any cleanup needed when channel is unsubscribed | ||
end | ||
end |
4 changes: 2 additions & 2 deletions
4
app/channels/online_channel.rb → app/channels/online_users_channel.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import consumer from "./consumer" | ||
|
||
consumer.subscriptions.create("OfflineUsersChannel", { | ||
connected() { | ||
// Called when the subscription is ready for use on the server | ||
}, | ||
|
||
disconnected() { | ||
// Called when the subscription has been terminated by the server | ||
}, | ||
|
||
received(data) { | ||
// Called when there's incoming data on the websocket for this channel | ||
$('#'+data.id).remove(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import consumer from "./consumer" | ||
|
||
consumer.subscriptions.create("OnlineUsersChannel", { | ||
connected() { | ||
// Called when the subscription is ready for use on the server | ||
}, | ||
|
||
disconnected() { | ||
// Called when the subscription has been terminated by the server | ||
}, | ||
|
||
received(data) { | ||
// Called when there's incoming data on the websocket for this channel | ||
$('#online-users-container').append("<div class='item' id='"+ data.id +"'><img class= 'ui avatar image' src= '/assets/avtar-for-message-me.png' id= 'profile-pic-online'><div class='content'><div class='header'>" + data.username + "</div></div></div>") | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class Message < ApplicationRecord | ||
validates :body, presence: true | ||
belongs_to :user | ||
scope :custom_display, -> { order(:created_at).last(50) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
<div class="content"> | ||
<div class="summary"> | ||
<% if session[:user_id] == message.user.id%> | ||
<p class= "ui right green aligned header" id="my-message-body"><big><em><%= message.user.username %></em>:</big> <%= message.body %></p> | ||
<p class= "ui right green aligned header"> | ||
<span class="ui label" id="my-message-body"> | ||
<%= message.body %> | ||
<br> | ||
<span class= "ui grey circular mini label" id="time-on-message"> | ||
<%= message.created_at.strftime("%I:%M %p") %> | ||
</span> | ||
</span> | ||
</p> | ||
<% else %> | ||
<p class= "ui left teal aligned header" id="my-message-body"><big><em><%= message.user.username %></em>:</big> <%= message.body %></p> | ||
<p class= "ui left teal aligned header"> | ||
<span class="ui label" id="frnd-message-body"> | ||
<span class= "" id="username-on-message"> | ||
<em><%= message.user.username %>:</em> | ||
</span> | ||
<br> | ||
<%= message.body %> | ||
<br> | ||
<span class= "ui grey circular mini label" id="time-on-message"> | ||
<%= message.created_at.strftime("%I:%M %p") %> | ||
</span> | ||
</span> | ||
</p> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "test_helper" | ||
|
||
class OfflineUsersChannelTest < ActionCable::Channel::TestCase | ||
# test "subscribes" do | ||
# subscribe | ||
# assert subscription.confirmed? | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "test_helper" | ||
|
||
class OnlineUsersChannelTest < ActionCable::Channel::TestCase | ||
# test "subscribes" do | ||
# subscribe | ||
# assert subscription.confirmed? | ||
# end | ||
end |