Render proper content for mentions, don't send mentions to yourself
This commit is contained in:
@@ -5,8 +5,7 @@ module Card::Mentions
|
||||
include ::Mentions
|
||||
end
|
||||
|
||||
private
|
||||
def mentionable_content
|
||||
description.to_plain_text
|
||||
end
|
||||
def mentionable_content
|
||||
description.to_plain_text
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,4 +4,8 @@ class Mention < ApplicationRecord
|
||||
belongs_to :container, polymorphic: true
|
||||
belongs_to :mentioner, class_name: "User"
|
||||
belongs_to :mentionee, class_name: "User", inverse_of: :mentions
|
||||
|
||||
def self_mention?
|
||||
mentioner == mentionee
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,8 +5,7 @@ module Message::Mentions
|
||||
include ::Mentions
|
||||
end
|
||||
|
||||
private
|
||||
def mentionable_content
|
||||
messageable.try(:body_plain_text)
|
||||
end
|
||||
def mentionable_content
|
||||
messageable.try(:body_plain_text)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,9 +4,9 @@ class Notifier
|
||||
class << self
|
||||
def for(source)
|
||||
case source
|
||||
when Event
|
||||
when Event
|
||||
"Notifier::Events::#{source.action.classify}".safe_constantize&.new(source)
|
||||
when ::Mention
|
||||
when ::Mention
|
||||
Notifier::Mention.new(source)
|
||||
end
|
||||
end
|
||||
@@ -26,7 +26,7 @@ class Notifier
|
||||
end
|
||||
|
||||
def should_notify?
|
||||
true
|
||||
!creator.system?
|
||||
end
|
||||
|
||||
def resource
|
||||
|
||||
@@ -2,10 +2,6 @@ class Notifier::Events::Base < Notifier
|
||||
delegate :card, :creator, to: :source
|
||||
|
||||
private
|
||||
def should_notify?
|
||||
!creator.system?
|
||||
end
|
||||
|
||||
def resource
|
||||
card
|
||||
end
|
||||
|
||||
@@ -5,7 +5,11 @@ class Notifier::Mention < Notifier
|
||||
end
|
||||
|
||||
def recipients
|
||||
[ source.mentionee ]
|
||||
if source.self_mention?
|
||||
[]
|
||||
else
|
||||
[ source.mentionee ]
|
||||
end
|
||||
end
|
||||
|
||||
def creator
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<strong class="overflow-ellipsis notification__title txt-small txt-tight-lines"><%= "OMG" %></strong>
|
||||
<% mention = notification.source %>
|
||||
|
||||
<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">
|
||||
YOU WERE MENTIONED!
|
||||
<%= mention.container.mentionable_content.truncate(200) %>
|
||||
</div>
|
||||
<div class="tray__item-meta overflow-ellipsis translucent"> <%= local_datetime_tag(notification.created_at, style: :ago) %></div>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
class AddCreatorToNotifications < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
add_reference :notifications, :creator, null: true, foreign_key: { to_table: :users }
|
||||
|
||||
execute <<~SQL
|
||||
UPDATE notifications
|
||||
SET creator_id = (
|
||||
SELECT events.creator_id
|
||||
FROM events
|
||||
WHERE events.id = notifications.source_id
|
||||
AND notifications.source_type = 'Event'
|
||||
)
|
||||
WHERE source_type = 'Event';
|
||||
SQL
|
||||
|
||||
change_column_null :notifications, :creator_id, true
|
||||
end
|
||||
end
|
||||
Generated
+1
-1
@@ -236,7 +236,7 @@ ActiveRecord::Schema[8.1].define(version: 2025_04_22_112857) do
|
||||
|
||||
create_table "notifications", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.integer "creator_id", null: false
|
||||
t.integer "creator_id"
|
||||
t.datetime "read_at"
|
||||
t.integer "resource_id", null: false
|
||||
t.string "resource_type", null: false
|
||||
|
||||
+10
-1
@@ -761,7 +761,16 @@ columns:
|
||||
default_function:
|
||||
collation:
|
||||
comment:
|
||||
- *23
|
||||
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
|
||||
auto_increment:
|
||||
name: creator_id
|
||||
cast_type: *1
|
||||
sql_type_metadata: *2
|
||||
'null': true
|
||||
default:
|
||||
default_function:
|
||||
collation:
|
||||
comment:
|
||||
pins:
|
||||
- *5
|
||||
- *21
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require 'test_helper'
|
||||
require "test_helper"
|
||||
|
||||
class User::MentionableTest < ActiveSupport::TestCase
|
||||
test "mentionable handles" do
|
||||
|
||||
Reference in New Issue
Block a user