Skip to content

Commit 2bfa2ff

Browse files
author
Nicholas Newberry
committed
update convo title live
1 parent a048265 commit 2bfa2ff

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

app/models/application_record.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ class ApplicationRecord < ActiveRecord::Base
44
def user_dom_id(suffix)
55
"#{user.id}_#{suffix}"
66
end
7+
8+
def dom_id
9+
"#{self.class.name.underscore}_#{id}"
10+
end
711
end

app/models/conversation.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,15 @@ class Conversation < ApplicationRecord
44
has_many :messages, dependent: :destroy
55
has_many :conversation_collections, dependent: :destroy
66
has_many :collections, through: :conversation_collections, dependent: :destroy
7+
8+
include Turbo::Broadcastable
9+
10+
after_update_commit -> {
11+
broadcast_replace_to(
12+
user_dom_id("conversations"),
13+
target: dom_id,
14+
partial: "conversations/conversation_list_item",
15+
locals: { selected: self}
16+
)
17+
}
718
end

app/models/message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ class Message < ApplicationRecord
1919
partial: "messages/message"
2020
)
2121
}
22-
end
22+
end

0 commit comments

Comments
 (0)