created channel for action cable and friendship relationship in database

This commit is contained in:
Beatrice Olivera
2018-08-27 16:55:44 +01:00
parent 7d67f04c63
commit f9cbb7c680
7 changed files with 59 additions and 2 deletions

View 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
View 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

View File

@@ -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