Class: Activity

Inherits:
ApplicationRecord show all
Defined in:
app/models/activity.rb

Overview

The object which represents the user's activity. This is meant to be called by the Notifications Framework

Constant Summary collapse

USER_NOTIFICATION_TYPES =
[:email, :popup].freeze
COURSE_NOTIFICATION_TYPES =
[:email, :feed].freeze

Instance Method Summary collapse

Instance Method Details

#from_course?(course) ⇒ Boolean

Checks if activity is from the given course. Ensure that object has #course defined on it for the current activity to be displayed as an in-course popup user notification.


35
36
37
38
# File 'app/models/activity.rb', line 35

def from_course?(course)
  object_course = object&.course
  object_course.present? && (object_course.id == course.id)
end

#notify(recipient, type) ⇒ Object

Send notifications according to input type and recipient


19
20
21
22
23
24
25
26
27
28
# File 'app/models/activity.rb', line 19

def notify(recipient, type)
  case recipient
  when Course
    notify_course(recipient, type)
  when User
    notify_user(recipient, type)
  else
    raise ArgumentError, 'Invalid recipient type'
  end
end