mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-09 16:20:09 +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:
+13
-13
@@ -78,6 +78,19 @@ class Room < ApplicationRecord
|
||||
push_later(message)
|
||||
end
|
||||
|
||||
# Rewriting every member on every message is most of what posting to a large room writes,
|
||||
# so members who are unread already stay as they are. Directs keep touching them all: a
|
||||
# direct's sidebar row is cached by membership and shows the room's recency.
|
||||
def unread_memberships(message)
|
||||
recipients = memberships.visible.disconnected.where.not(user: message.creator)
|
||||
recipients = recipients.where(unread_at: nil) unless direct?
|
||||
recipients.update_all(unread_at: message.created_at, updated_at: Time.current)
|
||||
end
|
||||
|
||||
def push_later(message)
|
||||
Room::PushMessageJob.perform_later(self, message)
|
||||
end
|
||||
|
||||
def open?
|
||||
is_a?(Rooms::Open)
|
||||
end
|
||||
@@ -103,17 +116,4 @@ class Room < ApplicationRecord
|
||||
errors.add :type, "can't be changed for a direct room"
|
||||
end
|
||||
end
|
||||
|
||||
# Rewriting every member on every message is most of what posting to a large room writes,
|
||||
# so members who are unread already stay as they are. Directs keep touching them all: a
|
||||
# direct's sidebar row is cached by membership and shows the room's recency.
|
||||
def unread_memberships(message)
|
||||
recipients = memberships.visible.disconnected.where.not(user: message.creator)
|
||||
recipients = recipients.where(unread_at: nil) unless direct?
|
||||
recipients.update_all(unread_at: message.created_at, updated_at: Time.current)
|
||||
end
|
||||
|
||||
def push_later(message)
|
||||
Room::PushMessageJob.perform_later(self, message)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user