mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-09 08:10:08 +09:00
Create messages, search entries and unread state atomically
Apply the Laravel implementation’s MessageWriter architecture to Rails creation: save native Action Text and attachment metadata, insert the search entry and update unread memberships in the message transaction. Keep notification jobs after commit and preserve Room#receive and existing serialized jobs. Cover native HTML/mentions, attachment-only search, derived-write failures, outer rollback and SQL commit ordering. Updates and destruction retain their current indexing behavior.
This commit is contained in:
@@ -9,7 +9,9 @@ class Message < ApplicationRecord
|
||||
has_rich_text :body
|
||||
|
||||
before_create -> { self.client_message_id ||= Random.uuid } # Bots don't care
|
||||
after_create_commit -> { room.receive(self) }
|
||||
# Run after Action Text and Active Storage autosave, while creation is still atomic.
|
||||
after_save :record_creation, if: :previously_new_record?
|
||||
after_create_commit -> { room.push_later(self) }
|
||||
|
||||
scope :ordered, -> { order(:created_at) }
|
||||
scope :with_creator, -> { preload(creator: :avatar_attachment) }
|
||||
@@ -45,4 +47,10 @@ class Message < ApplicationRecord
|
||||
Sound.find_by_name match[:name]
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def record_creation
|
||||
create_in_index
|
||||
room.unread_memberships(self)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user