Add creator initials and avatar color to push notification payload
Move avatar_background_color logic from helper to User::Avatar concern so it can be accessed from models. Include creator_id, creator_initials, and creator_avatar_color in native push notifications for local avatar rendering on iOS. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Rosa Gutierrez
parent
113e61d418
commit
b1cdb72381
@@ -1,13 +1,6 @@
|
||||
require "zlib"
|
||||
|
||||
module AvatarsHelper
|
||||
AVATAR_COLORS = %w[
|
||||
#AF2E1B #CC6324 #3B4B59 #BFA07A #ED8008 #ED3F1C #BF1B1B #736B1E #D07B53
|
||||
#736356 #AD1D1D #BF7C2A #C09C6F #698F9C #7C956B #5D618F #3B3633 #67695E
|
||||
]
|
||||
|
||||
def avatar_background_color(user)
|
||||
AVATAR_COLORS[Zlib.crc32(user.to_param) % AVATAR_COLORS.size]
|
||||
user.avatar_background_color
|
||||
end
|
||||
|
||||
def avatar_tag(user, hidden_for_screen_reader: false, **options)
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
require "zlib"
|
||||
|
||||
module User::Avatar
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
ALLOWED_AVATAR_CONTENT_TYPES = %w[ image/jpeg image/png image/gif image/webp ].freeze
|
||||
MAX_AVATAR_DIMENSIONS = { width: 4096, height: 4096 }.freeze
|
||||
AVATAR_COLORS = %w[
|
||||
#AF2E1B #CC6324 #3B4B59 #BFA07A #ED8008 #ED3F1C #BF1B1B #736B1E #D07B53
|
||||
#736356 #AD1D1D #BF7C2A #C09C6F #698F9C #7C956B #5D618F #3B3633 #67695E
|
||||
].freeze
|
||||
|
||||
included do
|
||||
has_one_attached :avatar do |attachable|
|
||||
@@ -22,6 +28,10 @@ module User::Avatar
|
||||
avatar.variable? ? avatar.variant(:thumb) : avatar
|
||||
end
|
||||
|
||||
def avatar_background_color
|
||||
AVATAR_COLORS[Zlib.crc32(to_param) % AVATAR_COLORS.size]
|
||||
end
|
||||
|
||||
# Avatars are always publicly accessible
|
||||
def publicly_accessible?
|
||||
true
|
||||
|
||||
@@ -34,7 +34,10 @@ class Notification::PushTarget::Native < Notification::PushTarget
|
||||
avatar_url: payload.avatar_url,
|
||||
card_id: card&.id,
|
||||
card_title: card&.title,
|
||||
creator_id: notification.creator.id,
|
||||
creator_name: notification.creator.name,
|
||||
creator_initials: notification.creator.initials,
|
||||
creator_avatar_color: notification.creator.avatar_background_color,
|
||||
category: payload.category
|
||||
)
|
||||
.new(
|
||||
|
||||
Reference in New Issue
Block a user