Permalink
Browse files

here be dragons

  • Loading branch information...
jcs committed Jan 19, 2017
1 parent 8fbdc02 commit 56d37493412be5fc55afc12cebcef1d8e9bef910
@@ -338,6 +338,16 @@ $(document).ready(function() {
return Lobsters.moderateStory(this);
}),
$(".toggle_dragons").click(function(a) {
var c = $(".dragon_threads").first();
if (c) {
if (c.hasClass("hidden"))
c.removeClass("hidden");
else
c.addClass("hidden");
}
}),
$(document).on("click", "a.comment_replier", function() {
if (!Lobsters.curUser) {
Lobsters.bounceToLogin();
@@ -408,6 +418,34 @@ $(document).ready(function() {
});
}
});
$(document).on("click", "a.comment_undeletor", function() {
if (confirm("Are you sure you want to undelete this comment?")) {
var li = $(this).closest(".comment");
$.post("/comments/" + $(li).attr("data-shortid") + "/undelete",
function(d) {
$(li).replaceWith(d);
});
}
});
$(document).on("click", "a.comment_dragon", function() {
if (confirm("Are you sure you want to mark this thread?")) {
var li = $(this).closest(".comment");
$.post("/comments/" + $(li).attr("data-shortid") + "/dragon",
function(d) {
window.location.reload();
});
}
});
$(document).on("click", "a.comment_undragon", function() {
if (confirm("Are you sure you want to unmark this thread?")) {
var li = $(this).closest(".comment");
$.post("/comments/" + $(li).attr("data-shortid") + "/undragon",
function(d) {
window.location.reload();
});
}
});
$(document).on("click", "a.comment_moderator", function() {
var reason = prompt("Moderation reason:");
@@ -421,16 +459,6 @@ $(document).ready(function() {
});
});
$(document).on("click", "a.comment_undeletor", function() {
if (confirm("Are you sure you want to undelete this comment?")) {
var li = $(this).closest(".comment");
$.post("/comments/" + $(li).attr("data-shortid") + "/undelete",
function(d) {
$(li).replaceWith(d);
});
}
});
Lobsters.runSelect2();
$(document).on("click", "div.markdown_help_toggler .markdown_help_label",
@@ -737,6 +737,23 @@ div.comment_actions a {
text-decoration: none;
}
div.dragons {
}
.dragon_text {
background-color: #f8f8f8;
color: gray;
font-style: italic;
margin: 1em;
padding: 2em 0 2.5em 0;
text-align: center;
}
.dragon_text a {
color: gray;
}
.dragon_threads.hidden {
display: none;
}
a.pagelink {
border: 1px solid #ddd;
background-color: #fbfbfb;
@@ -128,6 +128,26 @@ def undelete
:content_type => "text/html", :locals => { :comment => comment }
end
def dragon
if !((comment = find_comment) && @user.is_moderator?)
return render :text => "can't find comment", :status => 400
end
comment.become_dragon_for_user(@user)
render :text => "ok"
end
def undragon
if !((comment = find_comment) && @user.is_moderator?)
return render :text => "can't find comment", :status => 400
end
comment.remove_dragon_for_user(@user)
render :text => "ok"
end
def update
if !((comment = find_comment) && comment.is_editable_by_user?(@user))
return render :text => "can't find comment", :status => 400
@@ -82,7 +82,7 @@ def user_params
:email_replies, :email_messages, :email_mentions,
:pushover_replies, :pushover_messages, :pushover_mentions,
:mailing_list_mode, :show_avatars, :show_story_previews,
:show_submitted_story_threads
:show_submitted_story_threads, :hide_dragons
)
end
end
View
@@ -50,8 +50,8 @@ class Comment < ActiveRecord::Base
end
def self.arrange_for_user(user)
parents = self.order("(upvotes - downvotes) < 0 ASC, confidence DESC").
group_by(&:parent_comment_id)
parents = self.order("is_dragon ASC, (upvotes - downvotes) < 0 ASC, " <<
"confidence DESC").group_by(&:parent_comment_id)
# top-down list of comments, regardless of indent level
ordered = []
@@ -168,6 +168,36 @@ def assign_thread_id
end
end
def become_dragon_for_user(user)
Comment.record_timestamps = false
self.is_dragon = true
m = Moderation.new
m.comment_id = self.id
m.moderator_user_id = user.id
m.action = "turned into a dragon"
m.save
self.save(:validate => false)
Comment.record_timestamps = true
end
def remove_dragon_for_user(user)
Comment.record_timestamps = false
self.is_dragon = false
m = Moderation.new
m.comment_id = self.id
m.moderator_user_id = user.id
m.action = "slayed dragon"
m.save
self.save(:validate => false)
Comment.record_timestamps = true
end
# http://evanmiller.org/how-not-to-sort-by-average-rating.html
# https://github.com/reddit/reddit/blob/master/r2/r2/lib/db/_sorts.pyx
def calculated_confidence
View
@@ -44,6 +44,7 @@ class User < ActiveRecord::Base
s.boolean :show_avatars, :default => true
s.boolean :show_story_previews, :default => false
s.boolean :show_submitted_story_threads, :default => false
s.boolean :hide_dragons, :default => false
end
validates :email, :format => { :with => /\A[^@ ]+@[^@ ]+\.[^@ ]+\Z/ },
@@ -84,6 +84,15 @@ class="comment <%= comment.current_vote ? (comment.current_vote[:vote] == 1 ?
<% end %>
<% end %>
<% if !comment.parent_comment_id && @user && @user.is_moderator? %>
|
<% if comment.is_dragon? %>
<a class="comment_undragon">undragon</a>
<% else %>
<a class="comment_dragon">dragon</a>
<% end %>
<% end %>
<% if @user && !comment.story.is_gone? && !comment.is_gone? %>
|
<a class="comment_replier" unselectable="on">reply</a>
@@ -199,6 +199,10 @@
<%= f.check_box :show_avatars %>
</div>
<div class="boxline">
<%= f.label :hide_dragons, "Hide Dragons:", :class => "required" %>
<%= f.check_box :hide_dragons %>
</div>
<br>
<%= f.submit "Save All Settings" %>
@@ -45,9 +45,22 @@
<% comments_by_parent = @comments.group_by(&:parent_comment_id) %>
<% subtree = comments_by_parent[nil] %>
<% ancestors = [] %>
<% dragons = false %>
<% while subtree %>
<% if (comment = subtree.shift) %>
<% if comment.is_dragon? && !dragons %>
<div class="dragons">
<div class="dragon_text">
<a class="toggle_dragons">
&mdash; here be dragons &mdash;
</a>
</div>
<div class="dragon_threads <%= @user && @user.hide_dragons? ?
"hidden" : "" %>">
<% dragons = true %>
<% end %>
<li>
<%= render "comments/comment", :comment => comment,
:show_story => (comment.story_id != @story.id),
@@ -64,5 +77,10 @@
</ol></li>
<% end %>
<% end %>
<% if dragons %>
</div>
</div>
<% end %>
</ol>
<% end %>
View
@@ -72,6 +72,9 @@
post "delete"
post "undelete"
post "dragon"
post "undragon"
end
end
get "/comments/page/:page" => "comments#index"
@@ -0,0 +1,5 @@
class AddDragons < ActiveRecord::Migration
def change
add_column :comments, :is_dragon, :boolean, :default => false
end
end
View
@@ -30,6 +30,7 @@
t.boolean "is_moderated", default: false
t.boolean "is_from_email", default: false
t.integer "hat_id"
t.boolean "is_dragon", default: false
end
add_index "comments", ["confidence"], name: "confidence_idx", using: :btree
@@ -152,7 +153,7 @@
create_table "suggested_titles", force: true do |t|
t.integer "story_id"
t.integer "user_id"
t.string "title", limit: 150, null: false
t.string "title", limit: 150, default: "", null: false
end
create_table "tag_filters", force: true do |t|

0 comments on commit 56d3749

Please sign in to comment.