From 696732a90a63a716beba5a862f94bededd3dc3b7 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Wed, 23 Apr 2025 13:41:34 +0200 Subject: [PATCH] Rename mentions' container => source --- app/models/concerns/mentions.rb | 2 +- app/models/mention.rb | 4 +- app/models/notifier/mention.rb | 10 +++-- app/models/user/mentionable.rb | 2 +- .../notification/_mention.html.erb | 2 +- db/migrate/20250421120008_create_mentions.rb | 2 +- db/schema.rb | 6 +-- db/schema_cache.yml | 43 ++++++++----------- 8 files changed, 32 insertions(+), 39 deletions(-) diff --git a/app/models/concerns/mentions.rb b/app/models/concerns/mentions.rb index 41a818794..9e00ed3f7 100644 --- a/app/models/concerns/mentions.rb +++ b/app/models/concerns/mentions.rb @@ -2,7 +2,7 @@ module Mentions extend ActiveSupport::Concern included do - has_many :mentions, as: :container, dependent: :destroy + has_many :mentions, as: :source, dependent: :destroy has_many :mentionees, through: :mentions before_save :remember_mentionable_content after_touch :remember_mentionable_content diff --git a/app/models/mention.rb b/app/models/mention.rb index 2534eb631..2c6c95750 100644 --- a/app/models/mention.rb +++ b/app/models/mention.rb @@ -1,7 +1,7 @@ class Mention < ApplicationRecord include Notifiable - belongs_to :container, polymorphic: true + belongs_to :source, polymorphic: true belongs_to :mentioner, class_name: "User" belongs_to :mentionee, class_name: "User", inverse_of: :mentions @@ -13,6 +13,6 @@ class Mention < ApplicationRecord private def add_mentionee_as_watcher - container.watch_by(mentionee) + source.watch_by(mentionee) end end diff --git a/app/models/notifier/mention.rb b/app/models/notifier/mention.rb index 2085c42ed..ac1a3d413 100644 --- a/app/models/notifier/mention.rb +++ b/app/models/notifier/mention.rb @@ -1,18 +1,20 @@ class Notifier::Mention < Notifier + alias mention source + private def resource - source.container + mention.source end def recipients - if source.self_mention? + if mention.self_mention? [] else - [ source.mentionee ] + [ mention.mentionee ] end end def creator - source.mentioner + mention.mentioner end end diff --git a/app/models/user/mentionable.rb b/app/models/user/mentionable.rb index e3e5a9dbf..ab1906659 100644 --- a/app/models/user/mentionable.rb +++ b/app/models/user/mentionable.rb @@ -6,7 +6,7 @@ module User::Mentionable end def mentioned_by(mentioner, at:) - mentions.create! container: at, mentioner: mentioner + mentions.create! source: at, mentioner: mentioner end def mentionable_handles diff --git a/app/views/notifications/notification/_mention.html.erb b/app/views/notifications/notification/_mention.html.erb index 96abde715..7ed8ffdc5 100644 --- a/app/views/notifications/notification/_mention.html.erb +++ b/app/views/notifications/notification/_mention.html.erb @@ -2,6 +2,6 @@ <%= mention.mentioner.first_name %> mentioned you
- <%= mention.container.mentionable_content.truncate(200) %> + <%= mention.source.mentionable_content.truncate(200) %>
<%= local_datetime_tag(notification.created_at, style: :ago) %>
diff --git a/db/migrate/20250421120008_create_mentions.rb b/db/migrate/20250421120008_create_mentions.rb index da4923950..db27f7b2c 100644 --- a/db/migrate/20250421120008_create_mentions.rb +++ b/db/migrate/20250421120008_create_mentions.rb @@ -1,7 +1,7 @@ class CreateMentions < ActiveRecord::Migration[8.1] def change create_table :mentions do |t| - t.references :container, polymorphic: true, null: false, index: true + t.references :source, polymorphic: true, null: false, index: true t.references :mentionee, foreign_key: { to_table: :users }, null: false t.references :mentioner, foreign_key: { to_table: :users }, null: false diff --git a/db/schema.rb b/db/schema.rb index 2dbc1c529..49b1827d2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -213,15 +213,15 @@ ActiveRecord::Schema[8.1].define(version: 2025_04_22_112857) do end create_table "mentions", force: :cascade do |t| - t.integer "container_id", null: false - t.string "container_type", null: false t.datetime "created_at", null: false t.integer "mentionee_id", null: false t.integer "mentioner_id", null: false + t.integer "source_id", null: false + t.string "source_type", null: false t.datetime "updated_at", null: false - t.index ["container_type", "container_id"], name: "index_mentions_on_container" t.index ["mentionee_id"], name: "index_mentions_on_mentionee_id" t.index ["mentioner_id"], name: "index_mentions_on_mentioner_id" + t.index ["source_type", "source_id"], name: "index_mentions_on_source" end create_table "messages", force: :cascade do |t| diff --git a/db/schema_cache.yml b/db/schema_cache.yml index eb67d0f45..dc7cfae88 100644 --- a/db/schema_cache.yml +++ b/db/schema_cache.yml @@ -374,7 +374,7 @@ columns: - *9 cards: - *5 - - &30 !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column + - &31 !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column auto_increment: name: title cast_type: *6 @@ -494,11 +494,11 @@ columns: - !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column auto_increment: name: all_access - cast_type: &31 !ruby/object:ActiveModel::Type::Boolean + cast_type: &32 !ruby/object:ActiveModel::Type::Boolean precision: scale: limit: - sql_type_metadata: &32 !ruby/object:ActiveRecord::ConnectionAdapters::SqlTypeMetadata + sql_type_metadata: &33 !ruby/object:ActiveRecord::ConnectionAdapters::SqlTypeMetadata sql_type: boolean type: :boolean limit: @@ -627,7 +627,7 @@ columns: comment: filters_tags: - *18 - - &29 !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column + - &30 !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column auto_increment: name: tag_id cast_type: *1 @@ -639,9 +639,9 @@ columns: comment: mentions: - *5 - - !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column + - &29 !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column auto_increment: - name: container_type + name: source_type cast_type: *6 sql_type_metadata: *7 'null': false @@ -651,7 +651,7 @@ columns: comment: - !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column auto_increment: - name: container_id + name: source_id cast_type: *1 sql_type_metadata: *2 'null': false @@ -741,16 +741,7 @@ columns: default_function: collation: comment: - - !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column - auto_increment: - name: source_type - cast_type: *6 - sql_type_metadata: *7 - 'null': false - default: - default_function: - collation: - comment: + - *29 - !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column auto_increment: name: source_id @@ -860,12 +851,12 @@ columns: taggings: - *5 - *21 - - *29 + - *30 - *8 - *9 tags: - *5 - - *30 + - *31 - *8 - *9 users: @@ -894,8 +885,8 @@ columns: - !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column auto_increment: name: active - cast_type: *31 - sql_type_metadata: *32 + cast_type: *32 + sql_type_metadata: *33 'null': false default: true default_function: @@ -920,8 +911,8 @@ columns: - !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column auto_increment: name: watching - cast_type: *31 - sql_type_metadata: *32 + cast_type: *32 + sql_type_metadata: *33 'null': false default: true default_function: @@ -1698,11 +1689,11 @@ indexes: valid: true - !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition table: mentions - name: index_mentions_on_container + name: index_mentions_on_source unique: false columns: - - container_type - - container_id + - source_type + - source_id lengths: {} orders: {} opclasses: {}