Skip to content

Commit 3f69c0e

Browse files
committed
warn heavily flagged users
1 parent 0abe124 commit 3f69c0e

9 files changed

+33
-7
lines changed

app/controllers/application_controller.rb

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def check_for_read_only_mode
4646
true
4747
end
4848

49+
def flag_warning
50+
@flag_warning = @user && !!DownvotedCommenters.new('1m', 1.day).check_list_for(@user)
51+
end
52+
4953
# https://web.archive.org/web/20180108083712/http://umaine.edu/lobsterinstitute/files/2011/12/LobsterColorsWeb.pdf
5054
def set_traffic_style
5155
@traffic_intensity = '?'

app/controllers/comments_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class CommentsController < ApplicationController
66
before_action :require_logged_in_user_or_400,
77
:only => [:create, :preview, :upvote, :downvote, :unvote]
88
before_action :require_logged_in_user, :only => [:upvoted]
9+
before_action :flag_warning, only: [:threads]
910

1011
# for rss feeds, load the user's tag filters if a token is passed
1112
before_action :find_user_from_rss_token, :only => [:index]

app/controllers/replies_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class RepliesController < ApplicationController
22
REPLIES_PER_PAGE = 25
33

4-
before_action :require_logged_in_user, :set_page
4+
before_action :require_logged_in_user, :flag_warning, :set_page
55
after_action :update_read_ribbons, only: [:unread]
66

77
def all

app/controllers/users_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class UsersController < ApplicationController
22
before_action :require_logged_in_moderator,
33
:only => [:enable_invitation, :disable_invitation, :ban, :unban]
4+
before_action :flag_warning, only: [:show]
45

56
def show
67
@showing_user = User.where(:username => params[:username]).first!

app/models/downvoted_commenters.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
class DownvotedCommenters
55
include IntervalHelper
66

7-
CACHE_TIME = 30.minutes
7+
attr_reader :interval, :period, :cache_time
88

9-
attr_reader :interval, :period
10-
11-
def initialize(interval)
9+
def initialize(interval, cache_time = 30.minutes)
1210
@interval = interval
11+
@cache_time = cache_time
1312
length = time_interval(interval)
1413
@period = length[:dur].send(length[:intv].downcase).ago
1514
end
@@ -20,7 +19,7 @@ def check_list_for(showing_user)
2019

2120
# aggregates for all commenters; not just those receiving downvotes
2221
def aggregates
23-
Rails.cache.fetch("aggregates_#{interval}", expires_in: CACHE_TIME) {
22+
Rails.cache.fetch("aggregates_#{interval}_#{cache_time}", expires_in: self.cache_time) {
2423
ActiveRecord::Base.connection.exec_query("
2524
select
2625
stddev(sum_downvotes) as stddev,
@@ -52,7 +51,8 @@ def avg_sum_downvotes
5251
end
5352

5453
def commenters
55-
Rails.cache.fetch("downvoted_commenters_#{interval}", expires_in: CACHE_TIME) {
54+
Rails.cache.fetch("downvoted_commenters_#{interval}_#{cache_time}",
55+
expires_in: self.cache_time) {
5656
rank = 0
5757
User.active.joins(:comments)
5858
.where("comments.created_at >= ?", period)

app/views/comments/threads.html.erb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<%= render partial: 'users/flag_warning' if @flag_warning && @showing_user == @user %>
2+
13
<% @threads.each do |thread| %>
24
<ol class="comments comments1">
35
<% comments_by_parent = thread.group_by(&:parent_comment_id) %>

app/views/replies/show.html.erb

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
</div>
1212
</div>
1313

14+
<%= render partial: 'users/flag_warning' if @flag_warning %>
15+
1416
<% if @replies.present? %>
1517
<ol class="comments comments1">
1618
<% @replies.each do |reply| %>
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div class="box wide flag_warning flash-error">
2+
<p>
3+
Your comments have been heavily flagged across several stories in the last 30 days.
4+
This notice appears conservatively: if you're seeing it, something is unusual and bad and you need to make a change.
5+
Reconsider your behavior or just <a href="https://xkcd.com/386">take a break</a>.
6+
If you don't understand why you're seeing this after reviewing your <%= link_to 'recent threads', threads_path %>,
7+
talk to <%= link_to 'a mod', moderators_path %> about what went wrong.
8+
</p>
9+
10+
<p>
11+
If you are outraged by this notice from a site that's full of idiots and led by mods who are power-tripping assholes,
12+
you can delete your account from the bottom of your <%= link_to 'settings', settings_path %>.
13+
</p>
14+
</div>

app/views/users/show.html.erb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
<%= render partial: 'users/flag_warning' if @flag_warning && @showing_user == @user %>
2+
13
<div class="box wide">
24
<div class="legend">
35
<% if !@showing_user.is_active? %>

0 commit comments

Comments
 (0)