Merge branch 'main' into dev/hashtag-system-spec-3
This commit is contained in:
commit
0b0d4e5199
@ -385,7 +385,7 @@ GEM
|
||||
json-schema (>= 2.2, < 4.0)
|
||||
railties (>= 3.1, < 7.1)
|
||||
rspec-core (>= 2.14)
|
||||
rubocop (1.39.0)
|
||||
rubocop (1.40.0)
|
||||
json (~> 2.3)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 3.1.2.1)
|
||||
|
||||
@ -126,6 +126,7 @@ class PostAlerter
|
||||
|
||||
if mentioned_users
|
||||
mentioned_users = only_allowed_users(mentioned_users, post)
|
||||
mentioned_users = mentioned_users - pm_watching_users(post)
|
||||
notified += notify_users(mentioned_users - notified, :mentioned, post, mentioned_opts)
|
||||
end
|
||||
|
||||
@ -642,6 +643,14 @@ class PostAlerter
|
||||
users
|
||||
end
|
||||
|
||||
def pm_watching_users(post)
|
||||
return [] if !post.topic.private_message?
|
||||
directly_targeted_users(post).filter do |u|
|
||||
notification_level = TopicUser.get(post.topic, u)&.notification_level
|
||||
notification_level == TopicUser.notification_levels[:watching]
|
||||
end
|
||||
end
|
||||
|
||||
def notify_pm_users(post, reply_to_user, quoted_users, notified)
|
||||
return [] unless post.topic
|
||||
|
||||
@ -660,8 +669,7 @@ class PostAlerter
|
||||
users = directly_targeted_users(post).reject { |u| notified.include?(u) }
|
||||
DiscourseEvent.trigger(:before_create_notifications_for_users, users, post)
|
||||
users.each do |user|
|
||||
notification_level = TopicUser.get(post.topic, user)&.notification_level
|
||||
if reply_to_user == user || notification_level == TopicUser.notification_levels[:watching] || user.staged?
|
||||
if reply_to_user == user || pm_watching_users(post).include?(user) || user.staged?
|
||||
create_notification(user, Notification.types[:private_message], post, skip_send_email_to: emails_to_skip_send)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe CategoryHashtagDataSource do
|
||||
fab!(:parent_category) { Fabricate(:category, slug: "fun") }
|
||||
fab!(:parent_category) { Fabricate(:category, slug: "fun", topic_count: 2) }
|
||||
fab!(:category1) do
|
||||
Fabricate(:category, slug: "random", topic_count: 12, parent_category: parent_category)
|
||||
end
|
||||
@ -71,7 +71,7 @@ RSpec.describe CategoryHashtagDataSource do
|
||||
describe "#search_without_term" do
|
||||
it "returns distinct categories ordered by topic_count" do
|
||||
expect(described_class.search_without_term(guardian, 5).map(&:slug)).to eq(
|
||||
["books", "movies", "casual", "random", "#{uncategorized_category.slug}"],
|
||||
["books", "movies", "casual", "random", "fun"],
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@ -83,6 +83,17 @@ RSpec.describe PostAlerter do
|
||||
|
||||
end
|
||||
|
||||
it "notifies about private message even if direct mention" do
|
||||
pm = Fabricate(:topic, archetype: 'private_message', category_id: nil)
|
||||
op = Fabricate(:post, topic: pm, user: pm.user, raw: "Hello @#{user.username}, nice to meet you")
|
||||
pm.allowed_users << pm.user
|
||||
pm.allowed_users << user
|
||||
TopicUser.create!(user_id: user.id, topic_id: pm.id, notification_level: TopicUser.notification_levels[:watching])
|
||||
PostAlerter.post_created(op)
|
||||
|
||||
expect(Notification.where(user_id: user.id).pluck_first(:notification_type)).to eq(Notification.types[:private_message])
|
||||
end
|
||||
|
||||
context "with group inboxes" do
|
||||
fab!(:user1) { Fabricate(:user) }
|
||||
fab!(:user2) { Fabricate(:user) }
|
||||
@ -758,15 +769,18 @@ RSpec.describe PostAlerter do
|
||||
before do
|
||||
set_topic_notification_level(alice, pm_topic, notification_level)
|
||||
end
|
||||
let(:expected_notification) {
|
||||
notification_level == :watching ? :private_message : :mentioned
|
||||
}
|
||||
|
||||
it "notifies about @username mention" do
|
||||
args = { user: bob, topic: pm_topic, raw: 'Hello @alice' }
|
||||
expect { create_post_with_alerts(args) }.to add_notification(alice, :mentioned)
|
||||
expect { create_post_with_alerts(args) }.to add_notification(alice, expected_notification)
|
||||
end
|
||||
|
||||
it "notifies about @username mentions by non-human users" do
|
||||
args = { user: Discourse.system_user, topic: pm_topic, raw: 'Hello @alice' }
|
||||
expect { create_post_with_alerts(args) }.to add_notification(alice, :mentioned)
|
||||
expect { create_post_with_alerts(args) }.to add_notification(alice, expected_notification)
|
||||
end
|
||||
|
||||
it "notifies about @group mention when allowed user is part of group" do
|
||||
|
||||
Reference in New Issue
Block a user