fix: prevent NoMethodError in mute helpers when contact is nil (#13277)
## Linear Ticket https://linear.app/chatwoot/issue/CW-4569/nomethoderror-undefined-method-blocked-for-nil-nomethoderror ## Description Fixes NoMethodError in ConversationMuteHelpers that occurs during contact deletion race condition. When a contact is deleted, there's a brief window (~50-150ms) where contact_id becomes nil but conversations still exist. If ResolutionJob runs during this window, the muted? method crashes trying to call blocked? on nil.Fixes # (issue) ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? - Created orphaned conversations (contact_id = nil) - Called muted?, mute!, unmute! - all return gracefully - Verified async deletion still works correctly ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
committed by
GitHub
parent
7d68c25c97
commit
d451615811
@@ -16,10 +16,12 @@ class Conversations::ResolutionJob < ApplicationJob
|
||||
private
|
||||
|
||||
def conversation_scope(account)
|
||||
if account.auto_resolve_ignore_waiting
|
||||
account.conversations.resolvable_not_waiting(account.auto_resolve_after)
|
||||
else
|
||||
account.conversations.resolvable_all(account.auto_resolve_after)
|
||||
end
|
||||
base_scope = if account.auto_resolve_ignore_waiting
|
||||
account.conversations.resolvable_not_waiting(account.auto_resolve_after)
|
||||
else
|
||||
account.conversations.resolvable_all(account.auto_resolve_after)
|
||||
end
|
||||
# Exclude orphan conversations where contact was deleted but conversation cleanup is pending
|
||||
base_scope.where.not(contact_id: nil)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,17 +2,21 @@ module ConversationMuteHelpers
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def mute!
|
||||
return unless contact
|
||||
|
||||
resolved!
|
||||
contact.update(blocked: true)
|
||||
create_muted_message
|
||||
end
|
||||
|
||||
def unmute!
|
||||
return unless contact
|
||||
|
||||
contact.update(blocked: false)
|
||||
create_unmuted_message
|
||||
end
|
||||
|
||||
def muted?
|
||||
contact.blocked?
|
||||
contact&.blocked? || false
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user