threadables -> messageables

This commit is contained in:
Jose Farias
2024-10-25 15:03:31 -06:00
parent 3cd1d34f9d
commit 85d47a35ab
33 changed files with 150 additions and 202 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
class Bubble < ApplicationRecord
include Assignable, Boostable, Colored, Commentable, Eventable, Poppable, Searchable, Staged, Taggable, Threaded
include Assignable, Boostable, Colored, Commentable, Eventable, Messages, Poppable, Searchable, Staged, Taggable
belongs_to :bucket
belongs_to :creator, class_name: "User", default: -> { Current.user }
+1 -1
View File
@@ -9,6 +9,6 @@ module Bubble::Eventable
private
def track_event(action, creator: Current.user, **particulars)
events.create! action: action, creator: creator, rollup: thread.latest_rollup, particulars: particulars
events.create! action: action, creator: creator, summary: latest_event_summary, particulars: particulars
end
end
+11
View File
@@ -0,0 +1,11 @@
module Bubble::Messages
extend ActiveSupport::Concern
included do
has_many :messages, -> { chronologically }, dependent: :destroy
end
def latest_event_summary
messages.last&.event_summary || EventSummary.new(bubble: self)
end
end
-13
View File
@@ -1,13 +0,0 @@
class Bubble::Thread < ApplicationRecord
belongs_to :bubble, touch: true
has_many :entries, -> { chronologically }, dependent: :destroy
def latest_rollup
entries.last&.event_rollup || Event::Rollup.new(thread: self)
end
def to_partial_path
"bubbles/threads/thread"
end
end
-13
View File
@@ -1,13 +0,0 @@
class Bubble::Thread::Entry < ApplicationRecord
belongs_to :thread, touch: true
delegated_type :threadable, types: Threadable::TYPES, inverse_of: :thread_entry, dependent: :destroy
after_touch -> { thread.touch }
scope :chronologically, -> { order created_at: :asc, id: :desc }
def to_partial_path
"bubbles/threads/entries/entry"
end
end
-9
View File
@@ -1,9 +0,0 @@
module Bubble::Threaded
extend ActiveSupport::Concern
included do
has_one :thread, dependent: :destroy
after_create -> { create_thread! }
end
end
+1 -5
View File
@@ -1,12 +1,8 @@
class Comment < ApplicationRecord
include Searchable, Threadable
include Searchable, Messageable
belongs_to :bubble, touch: true
belongs_to :creator, class_name: "User", default: -> { Current.user }
searchable_by :body, using: :comments_search_index
def thread
bubble.thread
end
end
+13
View File
@@ -0,0 +1,13 @@
module Messageable
extend ActiveSupport::Concern
TYPES = %w[ Comment EventSummary ]
included do
has_one :message, as: :messageable
after_create -> { create_message! bubble: bubble }
after_update -> { message.touch }
after_touch -> { message.touch }
end
end
-13
View File
@@ -1,13 +0,0 @@
module Threadable
extend ActiveSupport::Concern
TYPES = %w[ Comment Event::Rollup ]
included do
has_one :thread_entry, as: :threadable, class_name: "Bubble::Thread::Entry"
after_create -> { create_thread_entry! thread: thread }
after_update -> { thread_entry.touch }
after_touch -> { thread_entry.touch }
end
end
+1 -1
View File
@@ -3,7 +3,7 @@ class Event < ApplicationRecord
belongs_to :creator, class_name: "User"
belongs_to :bubble, touch: true
belongs_to :rollup, touch: true
belongs_to :summary, touch: true, class_name: "EventSummary"
has_one :account, through: :creator
-11
View File
@@ -1,11 +0,0 @@
class Event::Rollup < ApplicationRecord
include Threadable
attr_accessor :thread
has_many :events, -> { chronologically }, dependent: :delete_all
def to_partial_path
"events/rollups/rollup"
end
end
+7
View File
@@ -0,0 +1,7 @@
class EventSummary < ApplicationRecord
include Messageable
attr_accessor :bubble
has_many :events, -> { chronologically }, dependent: :delete_all, inverse_of: :summary
end
+9
View File
@@ -0,0 +1,9 @@
class Message < ApplicationRecord
belongs_to :bubble, touch: true
delegated_type :messageable, types: Messageable::TYPES, inverse_of: :message, dependent: :destroy
after_touch -> { bubble.touch }
scope :chronologically, -> { order created_at: :asc, id: :desc }
end
+2 -2
View File
@@ -2,6 +2,6 @@
<%= render "boosts/boosts", bubble: @bubble %>
<% end %>
<%= turbo_stream.replace dom_id(@bubble.thread) do %>
<%= render @bubble.thread %>
<%= turbo_stream.replace dom_id(@bubble, :thread) do %>
<%= render "bubbles/thread", bubble: @bubble %>
<% end %>
+11
View File
@@ -0,0 +1,11 @@
<section id="<%= dom_id(bubble, :thread) %>"
class="comments align-center center borderless margin flex flex-column gap-half"
style="--bubble-color: <%= bubble.color %>"
data-controller="created-by-current-user"
data-created-by-current-user-selector-value=".comment"
data-created-by-current-user-differentiator-class="comment--mine">
<%# Template Dependency: comments/comment %>
<%# Template Dependency: event_summaries/event_summary %>
<%= render bubble.messages, cache: true %>
<%= render "comments/new", bubble: bubble %>
</section>
+2 -1
View File
@@ -18,4 +18,5 @@
<%= render "bubbles/bubble", bubble: @bubble %>
</div>
<%= render @bubble.thread %>
<%= render "bubbles/thread", bubble: @bubble %>
@@ -1,13 +0,0 @@
<%= cache thread do %>
<section id="<%= dom_id(thread) %>"
class="comments align-center center borderless margin flex flex-column gap-half"
style="--bubble-color: <%= thread.bubble.color %>"
data-controller="created-by-current-user"
data-created-by-current-user-selector-value=".comment"
data-created-by-current-user-differentiator-class="comment--mine">
<%# Template Dependency: comments/comment %>
<%# Template Dependency: rollups/rollup %>
<%= render thread.entries, cache: true %>
<%= render "comments/new", bubble: thread.bubble %>
</section>
<% end %>
@@ -1 +0,0 @@
<%= render entry.threadable %>
@@ -1,4 +1,4 @@
<div class="rollup flex-inline flex-wrap align-start fill-white border-radius center position-relative" data-controller="rollup">
<%# Template Dependency: events/actions/* %>
<%= render rollup.events, cache: true %>
<%= render event_summary.events, cache: true %>
</div>
+1
View File
@@ -0,0 +1 @@
<%= render message.messageable %>
@@ -1,9 +0,0 @@
class CreateBubbleThread < ActiveRecord::Migration[8.0]
def change
create_table :bubble_threads do |t|
t.references :bubble, null: false, foreign_key: true
t.timestamps
end
end
end
@@ -0,0 +1,10 @@
class CreateMessages < ActiveRecord::Migration[8.0]
def change
create_table :messages do |t|
t.references :bubble, null: false, foreign_key: true
t.references :messageable, polymorphic: true, null: false, index: { unique: true }
t.timestamps
end
end
end
@@ -1,10 +0,0 @@
class CreateThreadEntries < ActiveRecord::Migration[8.0]
def change
create_table :bubble_thread_entries do |t|
t.references :thread, null: false, foreign_key: { to_table: :bubble_threads }
t.references :threadable, polymorphic: true, null: false, index: { unique: true }
t.timestamps
end
end
end
@@ -1,7 +0,0 @@
class CreateEventRollups < ActiveRecord::Migration[8.0]
def change
create_table :event_rollups do |t|
t.timestamps
end
end
end
@@ -0,0 +1,7 @@
class CreateEventSummaries < ActiveRecord::Migration[8.0]
def change
create_table :event_summaries do |t|
t.timestamps
end
end
end
@@ -1,5 +0,0 @@
class AddRollupReferenceToEvents < ActiveRecord::Migration[8.0]
def change
add_reference :events, :rollup, foreign_key: { to_table: :event_rollups }
end
end
@@ -0,0 +1,5 @@
class AddSummaryReferenceToEvents < ActiveRecord::Migration[8.0]
def change
add_reference :events, :summary, foreign_key: { to_table: :event_summaries }
end
end
Generated
+15 -23
View File
@@ -68,23 +68,6 @@ ActiveRecord::Schema[8.0].define(version: 2024_10_22_180133) do
t.index ["bubble_id"], name: "index_assignments_on_bubble_id"
end
create_table "bubble_thread_entries", force: :cascade do |t|
t.integer "thread_id", null: false
t.string "threadable_type", null: false
t.integer "threadable_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["thread_id"], name: "index_bubble_thread_entries_on_thread_id"
t.index ["threadable_type", "threadable_id"], name: "index_bubble_thread_entries_on_threadable", unique: true
end
create_table "bubble_threads", force: :cascade do |t|
t.integer "bubble_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["bubble_id"], name: "index_bubble_threads_on_bubble_id"
end
create_table "bubbles", force: :cascade do |t|
t.string "title"
t.string "color"
@@ -127,7 +110,7 @@ ActiveRecord::Schema[8.0].define(version: 2024_10_22_180133) do
t.datetime "updated_at", null: false
end
create_table "event_rollups", force: :cascade do |t|
create_table "event_summaries", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
@@ -139,10 +122,20 @@ ActiveRecord::Schema[8.0].define(version: 2024_10_22_180133) do
t.string "action", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "rollup_id"
t.integer "summary_id"
t.index ["bubble_id", "action"], name: "index_events_on_bubble_id_and_action"
t.index ["creator_id"], name: "index_events_on_creator_id"
t.index ["rollup_id"], name: "index_events_on_rollup_id"
t.index ["summary_id"], name: "index_events_on_summary_id"
end
create_table "messages", force: :cascade do |t|
t.integer "bubble_id", null: false
t.string "messageable_type", null: false
t.integer "messageable_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["bubble_id"], name: "index_messages_on_bubble_id"
t.index ["messageable_type", "messageable_id"], name: "index_messages_on_messageable", unique: true
end
create_table "pops", force: :cascade do |t|
@@ -210,10 +203,9 @@ ActiveRecord::Schema[8.0].define(version: 2024_10_22_180133) do
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "bubble_thread_entries", "bubble_threads", column: "thread_id"
add_foreign_key "bubble_threads", "bubbles"
add_foreign_key "bubbles", "workflow_stages", column: "stage_id"
add_foreign_key "events", "event_rollups", column: "rollup_id"
add_foreign_key "events", "event_summaries", column: "summary_id"
add_foreign_key "messages", "bubbles"
add_foreign_key "pops", "bubbles"
add_foreign_key "pops", "users"
add_foreign_key "sessions", "users"
-40
View File
@@ -1,40 +0,0 @@
logo_1:
thread: logo
threadable: logo_initial_activity (Event::Rollup)
created_at: <%= 1.week.ago %>
logo_2:
thread: logo
threadable: logo_agreement_jz (Comment)
created_at: <%= 2.days.ago %>
logo_3:
thread: logo
threadable: logo_second_activity (Event::Rollup)
created_at: <%= 1.day.ago %>
logo_4:
thread: logo
threadable: logo_agreement_kevin (Comment)
created_at: <%= 2.hours.ago %>
logo_5:
thread: logo
threadable: logo_third_activity (Event::Rollup)
created_at: <%= 1.hour.ago %>
layout_1:
thread: layout
threadable: layout_initial_activity (Event::Rollup)
layout_2:
thread: layout
threadable: layout_overflowing_david (Comment)
text_1:
thread: text
threadable: text_initial_activity (Event::Rollup)
shipping_1:
thread: shipping
threadable: shipping_initial_activity (Event::Rollup)
-11
View File
@@ -1,11 +0,0 @@
logo:
bubble: logo
layout:
bubble: layout
text:
bubble: text
shipping:
bubble: shipping
+12 -12
View File
@@ -2,14 +2,14 @@ logo_created:
creator: david
bubble: logo
action: created
rollup: logo_initial_activity
summary: logo_initial_activity
created_at: <%= 1.week.ago %>
logo_assignment_jz:
creator: david
bubble: logo
action: assigned
rollup: logo_initial_activity
summary: logo_initial_activity
particulars: <%= { assignee_ids: [ ActiveRecord::FixtureSet.identify(:jz) ] }.to_json %>
created_at: <%= 1.week.ago + 1.hour %>
@@ -17,14 +17,14 @@ logo_boost_dhh:
creator: david
bubble: logo
action: boosted
rollup: logo_initial_activity
summary: logo_initial_activity
created_at: <%= 1.week.ago + 2.hours %>
logo_assignment_km:
creator: david
bubble: logo
action: assigned
rollup: logo_second_activity
summary: logo_second_activity
particulars: <%= { assignee_ids: [ ActiveRecord::FixtureSet.identify(:kevin) ] }.to_json %>
created_at: <%= 1.day.ago %>
@@ -32,42 +32,42 @@ logo_boost_km1:
creator: kevin
bubble: logo
action: boosted
rollup: logo_second_activity
summary: logo_second_activity
created_at: <%= 1.day.ago + 1.hour %>
logo_boost_km2:
creator: kevin
bubble: logo
action: boosted
rollup: logo_second_activity
summary: logo_second_activity
created_at: <%= 1.day.ago + 2.hours %>
logo_boost_jz1:
creator: jz
bubble: logo
action: boosted
rollup: logo_second_activity
summary: logo_second_activity
created_at: <%= 1.day.ago + 3.hours %>
logo_boost_jz2:
creator: jz
bubble: logo
action: boosted
rollup: logo_third_activity
summary: logo_third_activity
created_at: <%= 1.hour.ago %>
layout_created:
creator: david
bubble: layout
action: created
rollup: layout_initial_activity
summary: layout_initial_activity
created_at: <%= 1.week.ago %>
layout_assignment_jz:
creator: david
bubble: layout
action: assigned
rollup: layout_initial_activity
summary: layout_initial_activity
particulars: <%= { assignee_ids: [ ActiveRecord::FixtureSet.identify(:jz) ] }.to_json %>
created_at: <%= 1.hour.ago %>
@@ -75,12 +75,12 @@ text_created:
creator: kevin
bubble: text
action: created
rollup: text_initial_activity
summary: text_initial_activity
created_at: <%= 1.week.ago %>
shipping_created:
creator: kevin
bubble: shipping
action: created
rollup: shipping_initial_activity
summary: shipping_initial_activity
created_at: <%= 1.week.ago %>
+40
View File
@@ -0,0 +1,40 @@
logo_1:
bubble: logo
messageable: logo_initial_activity (EventSummary)
created_at: <%= 1.week.ago %>
logo_2:
bubble: logo
messageable: logo_agreement_jz (Comment)
created_at: <%= 2.days.ago %>
logo_3:
bubble: logo
messageable: logo_second_activity (EventSummary)
created_at: <%= 1.day.ago %>
logo_4:
bubble: logo
messageable: logo_agreement_kevin (Comment)
created_at: <%= 2.hours.ago %>
logo_5:
bubble: logo
messageable: logo_third_activity (EventSummary)
created_at: <%= 1.hour.ago %>
layout_1:
bubble: layout
messageable: layout_initial_activity (EventSummary)
layout_2:
bubble: layout
messageable: layout_overflowing_david (Comment)
text_1:
bubble: text
messageable: text_initial_activity (EventSummary)
shipping_1:
bubble: shipping
messageable: shipping_initial_activity (EventSummary)