Skip to content

Instantly share code, notes, and snippets.

@stephaneliu
Created February 8, 2025 19:42
Show Gist options
  • Save stephaneliu/232116e5064d250577c06d1c1b40f74f to your computer and use it in GitHub Desktop.
Save stephaneliu/232116e5064d250577c06d1c1b40f74f to your computer and use it in GitHub Desktop.
Notice extensions
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