mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Apply syntax_tree formatting to lib/*
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ComposerMessagesFinder
|
||||
|
||||
def initialize(user, details)
|
||||
@user = user
|
||||
@details = details
|
||||
@@ -29,26 +28,30 @@ class ComposerMessagesFinder
|
||||
|
||||
if creating_topic?
|
||||
count = @user.created_topic_count
|
||||
education_key = 'education.new-topic'
|
||||
education_key = "education.new-topic"
|
||||
else
|
||||
count = @user.post_count
|
||||
education_key = 'education.new-reply'
|
||||
education_key = "education.new-reply"
|
||||
end
|
||||
|
||||
if count < SiteSetting.educate_until_posts
|
||||
return {
|
||||
id: 'education',
|
||||
templateName: 'education',
|
||||
wait_for_typing: true,
|
||||
body: PrettyText.cook(
|
||||
I18n.t(
|
||||
education_key,
|
||||
education_posts_text: I18n.t('education.until_posts', count: SiteSetting.educate_until_posts),
|
||||
site_name: SiteSetting.title,
|
||||
base_path: Discourse.base_path
|
||||
)
|
||||
)
|
||||
}
|
||||
return(
|
||||
{
|
||||
id: "education",
|
||||
templateName: "education",
|
||||
wait_for_typing: true,
|
||||
body:
|
||||
PrettyText.cook(
|
||||
I18n.t(
|
||||
education_key,
|
||||
education_posts_text:
|
||||
I18n.t("education.until_posts", count: SiteSetting.educate_until_posts),
|
||||
site_name: SiteSetting.title,
|
||||
base_path: Discourse.base_path,
|
||||
),
|
||||
),
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
nil
|
||||
@@ -59,35 +62,55 @@ class ComposerMessagesFinder
|
||||
return unless replying? && @user.posted_too_much_in_topic?(@details[:topic_id])
|
||||
|
||||
{
|
||||
id: 'too_many_replies',
|
||||
templateName: 'education',
|
||||
body: PrettyText.cook(I18n.t('education.too_many_replies', newuser_max_replies_per_topic: SiteSetting.newuser_max_replies_per_topic))
|
||||
id: "too_many_replies",
|
||||
templateName: "education",
|
||||
body:
|
||||
PrettyText.cook(
|
||||
I18n.t(
|
||||
"education.too_many_replies",
|
||||
newuser_max_replies_per_topic: SiteSetting.newuser_max_replies_per_topic,
|
||||
),
|
||||
),
|
||||
}
|
||||
end
|
||||
|
||||
# Should a user be contacted to update their avatar?
|
||||
def check_avatar_notification
|
||||
|
||||
# A user has to be basic at least to be considered for an avatar notification
|
||||
return unless @user.has_trust_level?(TrustLevel[1])
|
||||
|
||||
# We don't notify users who have avatars or who have been notified already.
|
||||
return if @user.uploaded_avatar_id || UserHistory.exists_for_user?(@user, :notified_about_avatar)
|
||||
if @user.uploaded_avatar_id || UserHistory.exists_for_user?(@user, :notified_about_avatar)
|
||||
return
|
||||
end
|
||||
|
||||
# Do not notify user if any of the following is true:
|
||||
# - "disable avatar education message" is enabled
|
||||
# - "sso overrides avatar" is enabled
|
||||
# - "allow uploaded avatars" is disabled
|
||||
return if SiteSetting.disable_avatar_education_message || SiteSetting.discourse_connect_overrides_avatar || !TrustLevelAndStaffAndDisabledSetting.matches?(SiteSetting.allow_uploaded_avatars, @user)
|
||||
if SiteSetting.disable_avatar_education_message ||
|
||||
SiteSetting.discourse_connect_overrides_avatar ||
|
||||
!TrustLevelAndStaffAndDisabledSetting.matches?(SiteSetting.allow_uploaded_avatars, @user)
|
||||
return
|
||||
end
|
||||
|
||||
# If we got this far, log that we've nagged them about the avatar
|
||||
UserHistory.create!(action: UserHistory.actions[:notified_about_avatar], target_user_id: @user.id)
|
||||
UserHistory.create!(
|
||||
action: UserHistory.actions[:notified_about_avatar],
|
||||
target_user_id: @user.id,
|
||||
)
|
||||
|
||||
# Return the message
|
||||
{
|
||||
id: 'avatar',
|
||||
templateName: 'education',
|
||||
body: PrettyText.cook(I18n.t('education.avatar', profile_path: "/u/#{@user.username_lower}/preferences/account#profile-picture"))
|
||||
id: "avatar",
|
||||
templateName: "education",
|
||||
body:
|
||||
PrettyText.cook(
|
||||
I18n.t(
|
||||
"education.avatar",
|
||||
profile_path: "/u/#{@user.username_lower}/preferences/account#profile-picture",
|
||||
),
|
||||
),
|
||||
}
|
||||
end
|
||||
|
||||
@@ -96,39 +119,45 @@ class ComposerMessagesFinder
|
||||
return unless educate_reply?(:notified_about_sequential_replies)
|
||||
|
||||
# Count the posts made by this user in the last day
|
||||
recent_posts_user_ids = Post.where(topic_id: @details[:topic_id])
|
||||
.where("created_at > ?", 1.day.ago)
|
||||
.where(post_type: Post.types[:regular])
|
||||
.order('created_at desc')
|
||||
.limit(SiteSetting.sequential_replies_threshold)
|
||||
.pluck(:user_id)
|
||||
recent_posts_user_ids =
|
||||
Post
|
||||
.where(topic_id: @details[:topic_id])
|
||||
.where("created_at > ?", 1.day.ago)
|
||||
.where(post_type: Post.types[:regular])
|
||||
.order("created_at desc")
|
||||
.limit(SiteSetting.sequential_replies_threshold)
|
||||
.pluck(:user_id)
|
||||
|
||||
# Did we get back as many posts as we asked for, and are they all by the current user?
|
||||
return if recent_posts_user_ids.size != SiteSetting.sequential_replies_threshold ||
|
||||
recent_posts_user_ids.detect { |u| u != @user.id }
|
||||
if recent_posts_user_ids.size != SiteSetting.sequential_replies_threshold ||
|
||||
recent_posts_user_ids.detect { |u| u != @user.id }
|
||||
return
|
||||
end
|
||||
|
||||
# If we got this far, log that we've nagged them about the sequential replies
|
||||
UserHistory.create!(action: UserHistory.actions[:notified_about_sequential_replies],
|
||||
target_user_id: @user.id,
|
||||
topic_id: @details[:topic_id])
|
||||
UserHistory.create!(
|
||||
action: UserHistory.actions[:notified_about_sequential_replies],
|
||||
target_user_id: @user.id,
|
||||
topic_id: @details[:topic_id],
|
||||
)
|
||||
|
||||
{
|
||||
id: 'sequential_replies',
|
||||
templateName: 'education',
|
||||
id: "sequential_replies",
|
||||
templateName: "education",
|
||||
wait_for_typing: true,
|
||||
extraClass: 'education-message',
|
||||
extraClass: "education-message",
|
||||
hide_if_whisper: true,
|
||||
body: PrettyText.cook(I18n.t('education.sequential_replies'))
|
||||
body: PrettyText.cook(I18n.t("education.sequential_replies")),
|
||||
}
|
||||
end
|
||||
|
||||
def check_dominating_topic
|
||||
return unless educate_reply?(:notified_about_dominating_topic)
|
||||
|
||||
return if @topic.blank? ||
|
||||
@topic.user_id == @user.id ||
|
||||
@topic.posts_count < SiteSetting.summary_posts_required ||
|
||||
@topic.private_message?
|
||||
if @topic.blank? || @topic.user_id == @user.id ||
|
||||
@topic.posts_count < SiteSetting.summary_posts_required || @topic.private_message?
|
||||
return
|
||||
end
|
||||
|
||||
posts_by_user = @user.posts.where(topic_id: @topic.id).count
|
||||
|
||||
@@ -136,16 +165,18 @@ class ComposerMessagesFinder
|
||||
return if ratio < (SiteSetting.dominating_topic_minimum_percent.to_f / 100.0)
|
||||
|
||||
# Log the topic notification
|
||||
UserHistory.create!(action: UserHistory.actions[:notified_about_dominating_topic],
|
||||
target_user_id: @user.id,
|
||||
topic_id: @details[:topic_id])
|
||||
UserHistory.create!(
|
||||
action: UserHistory.actions[:notified_about_dominating_topic],
|
||||
target_user_id: @user.id,
|
||||
topic_id: @details[:topic_id],
|
||||
)
|
||||
|
||||
{
|
||||
id: 'dominating_topic',
|
||||
templateName: 'dominating-topic',
|
||||
id: "dominating_topic",
|
||||
templateName: "dominating-topic",
|
||||
wait_for_typing: true,
|
||||
extraClass: 'education-message dominating-topic-message',
|
||||
body: PrettyText.cook(I18n.t('education.dominating_topic'))
|
||||
extraClass: "education-message dominating-topic-message",
|
||||
body: PrettyText.cook(I18n.t("education.dominating_topic")),
|
||||
}
|
||||
end
|
||||
|
||||
@@ -157,73 +188,85 @@ class ComposerMessagesFinder
|
||||
reply_to_user_id = Post.where(id: @details[:post_id]).pluck(:user_id)[0]
|
||||
|
||||
# Users's last x posts in the topic
|
||||
last_x_replies = @topic.
|
||||
posts.
|
||||
where(user_id: @user.id).
|
||||
order('created_at desc').
|
||||
limit(SiteSetting.get_a_room_threshold).
|
||||
pluck(:reply_to_user_id).
|
||||
find_all { |uid| uid != @user.id && uid == reply_to_user_id }
|
||||
last_x_replies =
|
||||
@topic
|
||||
.posts
|
||||
.where(user_id: @user.id)
|
||||
.order("created_at desc")
|
||||
.limit(SiteSetting.get_a_room_threshold)
|
||||
.pluck(:reply_to_user_id)
|
||||
.find_all { |uid| uid != @user.id && uid == reply_to_user_id }
|
||||
|
||||
return unless last_x_replies.size == SiteSetting.get_a_room_threshold
|
||||
return unless @topic.posts.count('distinct user_id') >= min_users_posted
|
||||
return unless @topic.posts.count("distinct user_id") >= min_users_posted
|
||||
|
||||
UserHistory.create!(action: UserHistory.actions[:notified_about_get_a_room],
|
||||
target_user_id: @user.id,
|
||||
topic_id: @details[:topic_id])
|
||||
UserHistory.create!(
|
||||
action: UserHistory.actions[:notified_about_get_a_room],
|
||||
target_user_id: @user.id,
|
||||
topic_id: @details[:topic_id],
|
||||
)
|
||||
|
||||
reply_username = User.where(id: last_x_replies[0]).pluck_first(:username)
|
||||
|
||||
{
|
||||
id: 'get_a_room',
|
||||
templateName: 'get-a-room',
|
||||
id: "get_a_room",
|
||||
templateName: "get-a-room",
|
||||
wait_for_typing: true,
|
||||
reply_username: reply_username,
|
||||
extraClass: 'education-message get-a-room',
|
||||
body: PrettyText.cook(
|
||||
I18n.t(
|
||||
'education.get_a_room',
|
||||
count: SiteSetting.get_a_room_threshold,
|
||||
reply_username: reply_username,
|
||||
base_path: Discourse.base_path
|
||||
)
|
||||
)
|
||||
extraClass: "education-message get-a-room",
|
||||
body:
|
||||
PrettyText.cook(
|
||||
I18n.t(
|
||||
"education.get_a_room",
|
||||
count: SiteSetting.get_a_room_threshold,
|
||||
reply_username: reply_username,
|
||||
base_path: Discourse.base_path,
|
||||
),
|
||||
),
|
||||
}
|
||||
end
|
||||
|
||||
def check_reviving_old_topic
|
||||
return unless replying?
|
||||
return if @topic.nil? ||
|
||||
SiteSetting.warn_reviving_old_topic_age < 1 ||
|
||||
@topic.last_posted_at.nil? ||
|
||||
@topic.last_posted_at > SiteSetting.warn_reviving_old_topic_age.days.ago
|
||||
if @topic.nil? || SiteSetting.warn_reviving_old_topic_age < 1 || @topic.last_posted_at.nil? ||
|
||||
@topic.last_posted_at > SiteSetting.warn_reviving_old_topic_age.days.ago
|
||||
return
|
||||
end
|
||||
|
||||
{
|
||||
id: 'reviving_old',
|
||||
templateName: 'education',
|
||||
id: "reviving_old",
|
||||
templateName: "education",
|
||||
wait_for_typing: false,
|
||||
extraClass: 'education-message',
|
||||
body: PrettyText.cook(
|
||||
I18n.t(
|
||||
'education.reviving_old_topic',
|
||||
time_ago: FreedomPatches::Rails4.time_ago_in_words(@topic.last_posted_at, false, scope: :'datetime.distance_in_words_verbose')
|
||||
)
|
||||
)
|
||||
extraClass: "education-message",
|
||||
body:
|
||||
PrettyText.cook(
|
||||
I18n.t(
|
||||
"education.reviving_old_topic",
|
||||
time_ago:
|
||||
FreedomPatches::Rails4.time_ago_in_words(
|
||||
@topic.last_posted_at,
|
||||
false,
|
||||
scope: :"datetime.distance_in_words_verbose",
|
||||
),
|
||||
),
|
||||
),
|
||||
}
|
||||
end
|
||||
|
||||
def self.user_not_seen_in_a_while(usernames)
|
||||
User.where(username_lower: usernames).where("last_seen_at < ?", SiteSetting.pm_warn_user_last_seen_months_ago.months.ago).pluck(:username).sort
|
||||
User
|
||||
.where(username_lower: usernames)
|
||||
.where("last_seen_at < ?", SiteSetting.pm_warn_user_last_seen_months_ago.months.ago)
|
||||
.pluck(:username)
|
||||
.sort
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def educate_reply?(type)
|
||||
replying? &&
|
||||
@details[:topic_id] &&
|
||||
(@topic.present? && !@topic.private_message?) &&
|
||||
(@user.post_count >= SiteSetting.educate_until_posts) &&
|
||||
!UserHistory.exists_for_user?(@user, type, topic_id: @details[:topic_id])
|
||||
replying? && @details[:topic_id] && (@topic.present? && !@topic.private_message?) &&
|
||||
(@user.post_count >= SiteSetting.educate_until_posts) &&
|
||||
!UserHistory.exists_for_user?(@user, type, topic_id: @details[:topic_id])
|
||||
end
|
||||
|
||||
def creating_topic?
|
||||
@@ -237,5 +280,4 @@ class ComposerMessagesFinder
|
||||
def editing_post?
|
||||
@details[:composer_action] == "edit"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user