mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 02:04:33 +08:00
347f208480
SCI-4140
19 lines
618 B
Ruby
19 lines
618 B
Ruby
class Notification < ApplicationRecord
|
|
has_many :user_notifications, inverse_of: :notification, dependent: :destroy
|
|
has_many :users, through: :user_notifications
|
|
belongs_to :generator_user, class_name: 'User', optional: true
|
|
|
|
enum type_of: Extends::NOTIFICATIONS_TYPES
|
|
|
|
def already_seen(user)
|
|
UserNotification.where(notification: self, user: user)
|
|
.pluck(:checked)
|
|
.first
|
|
end
|
|
|
|
def create_user_notification(user)
|
|
return if user == generator_user
|
|
|
|
user_notifications.create!(user: user) if user.enabled_notifications_for?(type_of.to_sym, :web)
|
|
end
|
|
end
|