Table name: activities
id :integer not null, primary key trackable_id :integer trackable_type :string(255) owner_id :integer owner_type :string(255) key :string(255) parameters :text recipient_id :integer recipient_type :string(255) created_at :datetime updated_at :datetime read :boolean default(FALSE) type :string(255) university_id :integer group_id :integer comments_count :integer default(0)
Returns all unresponded group events notifications.
# File app/models/notification.rb, line 56 def self.unapproved_event_notifications(user) group_notifications = [] user.unresponded_group_events.unapproved.each do |event| group_notifications << Notification.new(trackable_type: 'Event', trackable_id: event.id, owner_id: event.owner_id, owner_type: 'User', key: 'group_event.create', created_at: event.created_at) end group_notifications end
It sets the notification response to Accepted.
# File app/models/notification.rb, line 86 def accepted? accepted_at.present? end
Returns the date when it is accepted.
# File app/models/notification.rb, line 96 def accepted_at case trackable_type when 'Schedule' trackable.confirmations.accepted.where(user: recipient).first.try(:created_at) when 'ActsAsFriendable::Friendship' trackable.approved? ? trackable.updated_at : nil else false end end
To call super method to create activity.
# File app/models/notification.rb, line 51 def create_activity super end
To increment the user notification count.
# File app/models/notification.rb, line 30 def increase_user_notifications_count if recipient.is_a? User recipient.update_columns(cached_notification_count: recipient.cached_notification_count + 1) end end
It returns the owner of notification.
# File app/models/notification.rb, line 65 def owner unless super User.new(name: "anonymous") else super end end
It sets the notification response to nil if it is pending.
# File app/models/notification.rb, line 74 def pending? case trackable_type when 'Schedule' !trackable.confirmations.where(user: recipient).exists? when 'ActsAsFriendable::Friendship' trackable.try(:approved).nil? else true end end
It sets the notification response to Rejected.
# File app/models/notification.rb, line 91 def rejected? rejected_at.present? end
Returns the date when it is rejected.
# File app/models/notification.rb, line 108 def rejected_at case trackable_type when 'Schedule' trackable.confirmations.rejected.where(user: recipient).first.try(:created_at) when 'ActsAsFriendable::Friendship' trackable.approved.nil? ? nil : (!trackable.approved? ? trackable.updated_at : nil) else false end end
Trigger pusher event to send notification.
# File app/models/notification.rb, line 37 def trigger_pusher_event if Configurations::Pusher.enabled? client = ActsAsTenant.current_tenant.pusher_configuration.client data = {type: self.key} if self.trackable_type == 'TutoringSession' client["private-user-#{owner_id}"].trigger_async('new_notification', data.merge!(trackable.for_appointment_sidebar(User.current, owner))) client["private-user-#{recipient_id}"].trigger_async('new_notification', data.merge(trackable.for_appointment_sidebar(User.current, recipient)).merge(count: recipient.cached_notification_count)) else client["private-user-#{recipient_id}"].trigger_async('new_notification', data.merge(count: recipient.cached_notification_count)) end end end