mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 13:33:44 +08:00
FIX: Properly localize badge notification on batch grant
This commit is contained in:
parent
9859bfb072
commit
9a502c73c9
|
@ -274,7 +274,7 @@ class BadgeGranter
|
||||||
/*where*/
|
/*where*/
|
||||||
RETURNING id, user_id, granted_at
|
RETURNING id, user_id, granted_at
|
||||||
)
|
)
|
||||||
select w.*, username FROM w
|
select w.*, username, locale FROM w
|
||||||
JOIN users u on u.id = w.user_id
|
JOIN users u on u.id = w.user_id
|
||||||
"
|
"
|
||||||
|
|
||||||
|
@ -305,15 +305,24 @@ class BadgeGranter
|
||||||
# old bronze badges do not matter
|
# old bronze badges do not matter
|
||||||
next if badge.badge_type_id == BadgeType::Bronze and row.granted_at < 2.days.ago
|
next if badge.badge_type_id == BadgeType::Bronze and row.granted_at < 2.days.ago
|
||||||
|
|
||||||
|
# Try to use user locale in the badge notification if possible without too much resources
|
||||||
|
notification_locale = if SiteSetting.allow_user_locale && row.locale.present?
|
||||||
|
row.locale
|
||||||
|
else
|
||||||
|
SiteSetting.default_locale
|
||||||
|
end
|
||||||
|
|
||||||
|
I18n.with_locale(notification_locale) do
|
||||||
notification = Notification.create!(
|
notification = Notification.create!(
|
||||||
user_id: row.user_id,
|
user_id: row.user_id,
|
||||||
notification_type: Notification.types[:granted_badge],
|
notification_type: Notification.types[:granted_badge],
|
||||||
data: {
|
data: {
|
||||||
badge_id: badge.id,
|
badge_id: badge.id,
|
||||||
badge_name: badge.name,
|
badge_name: badge.display_name,
|
||||||
badge_slug: badge.slug,
|
badge_slug: badge.slug,
|
||||||
username: row.username
|
username: row.username
|
||||||
}.to_json )
|
}.to_json )
|
||||||
|
end
|
||||||
|
|
||||||
Badge.exec_sql("UPDATE user_badges SET notification_id = :notification_id WHERE id = :id",
|
Badge.exec_sql("UPDATE user_badges SET notification_id = :notification_id WHERE id = :id",
|
||||||
notification_id: notification.id,
|
notification_id: notification.id,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user