mirror of
https://github.com/discourse/discourse.git
synced 2026-08-03 09:53:24 -05:00
FIX: Rebake chat messages when GitHub PR status changes (#36561)
Fix GitHub PR onebox updates not working for chat messages. When a GitHub webhook triggered the `RebakeGithubPrPosts` job, chat messages containing PR links were not being rebaked. The issue was twofold: 1. `defined?(Chat::MessageLink)` doesn't trigger Rails autoloading - it only checks if a constant is already loaded, so it would return `nil` before the class was ever accessed 2. Inside `module Jobs`, Ruby's constant resolution would look for `Jobs::Chat::MessageLink` before the global `::Chat::MessageLink` - Replace `defined?(Chat)` check with `SiteSetting.chat_enabled` which is the idiomatic Discourse pattern for checking plugin availability - Remove the redundant `defined?(Chat::MessageLink)` guard since the site setting check already handles this - Add `::` prefix to `Chat::MessageLink` and `Chat::Message` references to ensure they resolve to the global namespace Internal ref - t/169442
This commit is contained in:
@@ -9,7 +9,7 @@ module Jobs
|
||||
return if pr_url.blank?
|
||||
|
||||
rebake_posts(pr_url)
|
||||
rebake_chat_messages(pr_url) if defined?(Chat)
|
||||
rebake_chat_messages(pr_url) if SiteSetting.chat_enabled
|
||||
end
|
||||
|
||||
private
|
||||
@@ -30,15 +30,13 @@ module Jobs
|
||||
end
|
||||
|
||||
def rebake_chat_messages(pr_url)
|
||||
return unless defined?(Chat::MessageLink)
|
||||
|
||||
message_ids =
|
||||
Chat::MessageLink
|
||||
::Chat::MessageLink
|
||||
.where(url: pr_url)
|
||||
.or(Chat::MessageLink.where("url LIKE ?", "#{pr_url}%"))
|
||||
.or(::Chat::MessageLink.where("url LIKE ?", "#{pr_url}%"))
|
||||
.select(:chat_message_id)
|
||||
|
||||
Chat::Message
|
||||
::Chat::Message
|
||||
.where(id: message_ids)
|
||||
.find_each do |message|
|
||||
next unless has_github_pr_onebox?(message.cooked, pr_url)
|
||||
|
||||
Reference in New Issue
Block a user