Class: CloudObject::Subscriber
- Inherits:
-
ApplicationLesliRecord
- Object
- ApplicationLesliRecord
- CloudObject::Subscriber
- Defined in:
- app/models/lesli/cloud_object/subscriber.rb
Instance Attribute Summary collapse
- #action ⇒ :discussion_created, ... readonly
- #notification_type ⇒ :web, :email readonly
Class Method Summary collapse
- .add_subscriber(cloud_object, user, action = nil, notification_type = :web) ⇒ void
-
.cloud_object_model ⇒ Class
The class of the association ‘belongs_to’.
- .notify_subscribers(current_user, cloud_object, action, subject: nil, body: nil, url: nil) ⇒ void
-
.subscription_actions(cloud_object, user) ⇒ Array
Array of subscriptions.
Instance Method Summary collapse
-
#user_main ⇒ User
This method will always return nil.
Instance Attribute Details
#action ⇒ :discussion_created, ... (readonly)
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/lesli/cloud_object/subscriber.rb', line 49 enum action: { object_created: "object_created", object_updated: "object_updated", object_destroyed: "object_destroyed", object_status_updated: "object_status_updated", action_created: "action_created", action_updated: "action_updated", action_destroyed: "action_destroyed", discussion_created: "discussion_created", discussion_updated: "discussion_updated", discussion_destroyed: "discussion_destroyed", file_created: "file_created", file_updated: "file_updated", file_destroyed: "file_destroyed" } |
#notification_type ⇒ :web, :email (readonly)
72 73 74 75 76 77 78 |
# File 'app/models/lesli/cloud_object/subscriber.rb', line 72 enum notification_type: { email: "email", # notification sent by email only webpush: "webpush", # notification for web interface only mobilepush: "mobilepush", # notification for mobile only mobiledialog: "mobiledialog", # open a dialog in the main app screen push: "push", # webpush & mobilepush } |
Class Method Details
.add_subscriber(cloud_object, user, action = nil, notification_type = :web) ⇒ void
This method returns an undefined value.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/models/lesli/cloud_object/subscriber.rb', line 94 def self.add_subscriber(cloud_object, user, action=nil, notification_type= :web) if action return cloud_object.subscribers.create( user_creator: user, action: action, notification_type: self.notification_types[notification_type] ) end self.actions.values.each do |action| cloud_object.subscribers.create( user_creator: user, action: action, notification_type: self.notification_types[notification_type] ) end end |
.cloud_object_model ⇒ Class
Returns The class of the association ‘belongs_to’.
182 183 184 |
# File 'app/models/lesli/cloud_object/subscriber.rb', line 182 def self.cloud_object_model self.reflect_on_association(:cloud_object).klass end |
.notify_subscribers(current_user, cloud_object, action, subject: nil, body: nil, url: nil) ⇒ void
This method returns an undefined value.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'app/models/lesli/cloud_object/subscriber.rb', line 128 def self.notify_subscribers(current_user, cloud_object, action, subject: nil, body: nil, url: nil) unless cloud_object.subscribers.blank? subscribers = cloud_object.subscribers.where(action: action) subscribers = subscribers.where("users_id != ?", current_user.id) if current_user subscribers.each do |subscriber| Courier::Bell::Notification.new( subscriber.user_main || subscriber.user_creator, subject || action, body: body, url: url, category: "info", channel: subscriber.notification_type ) end end end |
.subscription_actions(cloud_object, user) ⇒ Array
Returns Array of subscriptions. There is one subscription per action.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'app/models/lesli/cloud_object/subscriber.rb', line 159 def self.subscription_actions(cloud_object, user) data = { } actions = self.actions.keys actions.each do |action| data[action] = { action: action, subscribed: false, notification_type: :email } end cloud_object.subscribers.where(users_id: user.id).each do |subscriber| data[subscriber.action][:id] = subscriber.id data[subscriber.action][:subscribed] = true data[subscriber.action][:notification_type] = subscriber.notification_type end data.values end |
Instance Method Details
#user_main ⇒ User
Returns This method will always return nil.
42 43 44 |
# File 'app/models/lesli/cloud_object/subscriber.rb', line 42 def user_main return nil end |