mirror of
https://github.com/beatriceo/polyglot.git
synced 2025-10-22 09:42:11 +00:00
created channel for action cable and friendship relationship in database
This commit is contained in:
11
app/channels/video_session_channel.rb
Normal file
11
app/channels/video_session_channel.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class VideoSessionChannel < ApplicationCable::Channel
|
||||
def subscribed
|
||||
# video session
|
||||
# stream_from "chat_room_#{params[:chat_room_id]}"
|
||||
end
|
||||
|
||||
|
||||
def unsubscribed
|
||||
# Any cleanup needed when channel is unsubscribed
|
||||
end
|
||||
end
|
14
app/models/connection.rb
Normal file
14
app/models/connection.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class Connection < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :contact, class_name: 'User', foreign_key: 'contact_id'
|
||||
|
||||
after_create :create_inverted_connection
|
||||
|
||||
private
|
||||
|
||||
def create_inverted_connection
|
||||
unless Connection.where('user_id = ? and contact_id = ?', self.contact.id, self.user.id).length > 0
|
||||
Connection.create!(user: self.contact, contact: self.user)
|
||||
end
|
||||
end
|
||||
end
|
@@ -3,4 +3,12 @@ class User < ApplicationRecord
|
||||
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :validatable
|
||||
|
||||
has_many :connections
|
||||
|
||||
def contacts
|
||||
self.connections.map do |connection|
|
||||
connection.contact
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user