Rename mentions' container => source
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
<strong class="overflow-ellipsis notification__title txt-small txt-tight-lines"><%= mention.mentioner.first_name %> mentioned you</strong>
|
||||
<div class="overflow-ellipsis txt-small txt-tight-lines">
|
||||
<%= mention.container.mentionable_content.truncate(200) %>
|
||||
<%= mention.source.mentionable_content.truncate(200) %>
|
||||
</div>
|
||||
<div class="tray__item-meta overflow-ellipsis translucent"> <%= local_datetime_tag(notification.created_at, style: :ago) %></div>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Generated
+3
-3
@@ -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|
|
||||
|
||||
+17
-26
@@ -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: {}
|
||||
|
||||
Reference in New Issue
Block a user