Class: Notifly::NotificationChannel

Inherits:
Object
  • Object
show all
Defined in:
lib/services/notification_channel.rb

Instance Method Summary collapse

Constructor Details

#initialize(user_id) ⇒ NotificationChannel

Returns a new instance of NotificationChannel.



3
4
5
6
7
# File 'lib/services/notification_channel.rb', line 3

def initialize(user_id)
  @user_id = user_id
  @channel = WebsocketRails.users[@user_id.to_s]
  @action_view = ActionViewHelper.new
end

Instance Method Details

#render(notification) ⇒ Object



14
15
16
17
# File 'lib/services/notification_channel.rb', line 14

def render(notification)
  @action_view.render partial: 'layouts/notification',
    locals: { notification: notification }
end

#trigger(notification) ⇒ Object



9
10
11
12
# File 'lib/services/notification_channel.rb', line 9

def trigger(notification)
  @channel.send_message 'notifly.notifications.new',
    { message: render(notification), id: notification.id }
end