Created
February 8, 2025 19:42
-
-
Save stephaneliu/232116e5064d250577c06d1c1b40f74f to your computer and use it in GitHub Desktop.
Notice extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module EventExtensions | |
extend ActiveSupport::Concern | |
included do | |
scope :by_category, ->(category) { where.any(categories: category) } | |
end | |
end | |
module NotificationExtensions | |
extend ActiveSupport::Concern | |
included do | |
counter_culture :recipient, | |
column_name: proc { |model| model.unread? ? "unread_notices_count" : nil }, | |
column_names: {["noticed_notifications.read_at IS NULL"] => "unread_notifications_count"} | |
scope :by_category, ->(category) { joins(:event).merge(::Noticed::Event.by_category(category)) } | |
# Used by: GQL Types::Noticed::NotificationType | |
def title = "" | |
# Used by: GQL Types::Noticed::NotificationType | |
def message = "" | |
# Used by: GQL Types::Noticed::NotificationType | |
def formatted_message = "" | |
# Used by: GQL Types::Noticed::NotificationType | |
def image = nil | |
# Used by: GQL Types::Noticed::NotificationType | |
def action_url = "" | |
# Used by: GQL Types::Noticed::NotificationType | |
def categories = event.categories | |
# Used by: GQL Types::Noticed::NotificationType | |
def project = nil | |
# Used by: GQL Types::Noticed::NotificationType | |
def project_title = project&.display_name.to_s | |
# Used by: GQL Types::Noticed::NotificationType | |
# Returning the same value as the previous implementation of metadata method | |
def metadata = nil | |
end | |
end | |
Rails.application.config.to_prepare do | |
Noticed::Event.include EventExtensions | |
Noticed::Notification.include NotificationExtensions | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment