Support rich text mentions
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
GIT
|
||||
remote: https://github.com/basecamp/actiontext-lexical
|
||||
revision: e6a47a42272d9e9250b47f6ea90caef8e8807c55
|
||||
revision: d372bcc8ecc5e725086a68992387b86f80210605
|
||||
branch: prompts
|
||||
specs:
|
||||
actiontext-lexical (0.1.0)
|
||||
|
||||
@@ -19,6 +19,10 @@ module Mentions
|
||||
|
||||
private
|
||||
def scan_mentionees
|
||||
mentionees_from_plain_text | mentionees_from_rich_text
|
||||
end
|
||||
|
||||
def mentionees_from_plain_text
|
||||
scan_mentioned_handles.filter_map do |mention|
|
||||
mentionable_users.find { |user| user.mentionable_handles.include?(mention) }
|
||||
end
|
||||
@@ -28,6 +32,14 @@ module Mentions
|
||||
mentionable_content.scan(/(?<!\w)@(\w+)/).flatten.uniq(&:downcase)
|
||||
end
|
||||
|
||||
def mentionees_from_rich_text
|
||||
mentionees_from_attachments & mentionable_users
|
||||
end
|
||||
|
||||
def mentionees_from_attachments
|
||||
rich_text_associations.flat_map { send(it.name)&.body&.attachments&.collect { it.attachable } }.compact
|
||||
end
|
||||
|
||||
def mentionable_users
|
||||
collection.users
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ class MentionsTest < ActiveSupport::TestCase
|
||||
Current.session = sessions(:david)
|
||||
end
|
||||
|
||||
test "create mentions when creating messages" do
|
||||
test "create mentions from plain text mentions" do
|
||||
assert_difference -> { Mention.count }, +1 do
|
||||
perform_enqueued_jobs only: Mention::CreateJob do
|
||||
collections(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, @david?"
|
||||
@@ -13,6 +13,27 @@ class MentionsTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
test "create mentions from rich text mentions" do
|
||||
assert_difference -> { Mention.count }, +1 do
|
||||
perform_enqueued_jobs only: Mention::CreateJob do
|
||||
attachment = ActionText::Attachment.from_attachable(users(:david))
|
||||
collections(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, #{attachment.to_html}?"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "can't mention users that don't have access to the collection" do
|
||||
collections(:writebook).update! all_access: false
|
||||
collections(:writebook).accesses.revoke_from(users(:david))
|
||||
|
||||
assert_no_difference -> { Mention.count }, +1 do
|
||||
perform_enqueued_jobs only: Mention::CreateJob do
|
||||
attachment = ActionText::Attachment.from_attachable(users(:david))
|
||||
collections(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup, #{attachment.to_html}?"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "mentionees are added as watchers of the card" do
|
||||
perform_enqueued_jobs only: Mention::CreateJob do
|
||||
card = collections(:writebook).cards.create title: "Cleanup", description: "Did you finish up with the cleanup @kevin?"
|
||||
|
||||
Reference in New Issue
Block a user