how did all of these tabs get here
This commit is contained in:
parent
1bf98318c8
commit
473a026a0e
|
@ -1,17 +1,17 @@
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
protect_from_forgery
|
protect_from_forgery
|
||||||
before_filter :authenticate_user
|
before_filter :authenticate_user
|
||||||
|
|
||||||
def authenticate_user
|
def authenticate_user
|
||||||
if session[:u]
|
if session[:u]
|
||||||
@user = User.find_by_session_token(session[:u])
|
@user = User.find_by_session_token(session[:u])
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_logged_in_user
|
def require_logged_in_user
|
||||||
if @user
|
if @user
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
redirect_to "/login"
|
redirect_to "/login"
|
||||||
|
|
|
@ -95,7 +95,7 @@ class CommentsController < ApplicationController
|
||||||
def threads
|
def threads
|
||||||
recent_threads = @user.recent_threads
|
recent_threads = @user.recent_threads
|
||||||
|
|
||||||
@threads = recent_threads.map{|r|
|
@threads = recent_threads.map{|r|
|
||||||
Comment.ordered_for_story_or_thread_for_user(nil, r, @user.id) }
|
Comment.ordered_for_story_or_thread_for_user(nil, r, @user.id) }
|
||||||
|
|
||||||
# trim each thread to this user's first response
|
# trim each thread to this user's first response
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
class HomeController < ApplicationController
|
class HomeController < ApplicationController
|
||||||
def index
|
def index
|
||||||
conds = [ "is_expired = 0 " ]
|
conds = [ "is_expired = 0 " ]
|
||||||
|
|
||||||
if @user && !@newest
|
if @user && !@newest
|
||||||
# exclude downvoted items
|
# exclude downvoted items
|
||||||
conds[0] << "AND stories.id NOT IN (SELECT story_id FROM votes " <<
|
conds[0] << "AND stories.id NOT IN (SELECT story_id FROM votes " <<
|
||||||
"WHERE user_id = ? AND vote < 0) "
|
"WHERE user_id = ? AND vote < 0) "
|
||||||
conds.push @user.id
|
conds.push @user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
if @tag
|
if @tag
|
||||||
conds[0] << "AND taggings.tag_id = ?"
|
conds[0] << "AND taggings.tag_id = ?"
|
||||||
|
@ -24,16 +24,16 @@ class HomeController < ApplicationController
|
||||||
:limit => 30)
|
:limit => 30)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @user
|
if @user
|
||||||
votes = Vote.votes_by_user_for_stories_hash(@user.id,
|
votes = Vote.votes_by_user_for_stories_hash(@user.id,
|
||||||
@stories.map{|s| s.id })
|
@stories.map{|s| s.id })
|
||||||
|
|
||||||
@stories.each do |s|
|
@stories.each do |s|
|
||||||
if votes[s.id]
|
if votes[s.id]
|
||||||
s.vote = votes[s.id]
|
s.vote = votes[s.id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if @newest
|
if @newest
|
||||||
# TODO: better algorithm here
|
# TODO: better algorithm here
|
||||||
|
@ -43,7 +43,7 @@ class HomeController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
render :action => "index"
|
render :action => "index"
|
||||||
end
|
end
|
||||||
|
|
||||||
def newest
|
def newest
|
||||||
@newest = true
|
@newest = true
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
class LoginController < ApplicationController
|
class LoginController < ApplicationController
|
||||||
before_filter :authenticate_user
|
before_filter :authenticate_user
|
||||||
|
|
||||||
def logout
|
def logout
|
||||||
if @user
|
if @user
|
||||||
reset_session
|
reset_session
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to "/"
|
redirect_to "/"
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@page_title = "Login"
|
@page_title = "Login"
|
||||||
render :action => "index"
|
render :action => "index"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,107 +1,2 @@
|
||||||
class MessagesController < ApplicationController
|
class MessagesController < ApplicationController
|
||||||
# static $verify = array(
|
|
||||||
# array("method" => "post",
|
|
||||||
# "only" => array("reply", "send"),
|
|
||||||
# "redirect_to" => "/",
|
|
||||||
# ),
|
|
||||||
# );
|
|
||||||
#
|
|
||||||
# public function index() {
|
|
||||||
# if (!$this->user) {
|
|
||||||
# $this->add_flash_error("You must be logged in to read messages.");
|
|
||||||
# return $this->redirect_to("/login");
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# $this->page_title = "Your Messages";
|
|
||||||
#
|
|
||||||
# $this->incoming_messages =
|
|
||||||
# Message::find_all_by_recipient_user_id($this->user->id,
|
|
||||||
# array("order" => "created_at DESC"));
|
|
||||||
#
|
|
||||||
# $this->sent_messages =
|
|
||||||
# Message::find_all_by_author_user_id($this->user->id,
|
|
||||||
# array("order" => "created_at DESC"));
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# public function show() {
|
|
||||||
# if (!$this->user) {
|
|
||||||
# $this->add_flash_error("You must be logged in to read messages.");
|
|
||||||
# return $this->redirect_to("/login");
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# if (!($this->message = Message::find_by_random_hash($this->params["id"]))) {
|
|
||||||
# $this->add_flash_error("Could not find message.");
|
|
||||||
# return $this->redirect_to(array("controller" => "messages"));
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# if (!($this->message->recipient_user_id == $this->user->id ||
|
|
||||||
# $this->message->author_user_id == $this->user->id)) {
|
|
||||||
# $this->add_flash_error("Could not find message.");
|
|
||||||
# return $this->redirect_to(array("controller" => "messages"));
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# if ($this->message->recipient_user_id == $this->user->id &&
|
|
||||||
# !$this->message->has_been_read) {
|
|
||||||
# $this->message->has_been_read = true;
|
|
||||||
# $this->message->save();
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# $this->page_title = "Message From "
|
|
||||||
# . $this->message->author->username . " To "
|
|
||||||
# . $this->message->recipient->username;
|
|
||||||
#
|
|
||||||
# $this->reply = new Message;
|
|
||||||
# $this->reply->author_user_id = $this->user->id;
|
|
||||||
# $this->reply->recipient_user_id = $this->message->author_user_id;
|
|
||||||
# $this->reply->subject = preg_match("/^re[: ]/i",
|
|
||||||
# $this->message->subject) ? "" : "Re: " . $this->message->subject;
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# /* id is a message id */
|
|
||||||
# public function reply() {
|
|
||||||
# $this->show();
|
|
||||||
#
|
|
||||||
# $this->page_title = "Message From "
|
|
||||||
# . $this->message->author->username . " To "
|
|
||||||
# . $this->message->recipient->username;
|
|
||||||
#
|
|
||||||
# if ($this->reply->update_attributes($this->params["message"])) {
|
|
||||||
# $this->add_flash_notice("Your reply has been sent.");
|
|
||||||
# return $this->redirect_to(array("controller" => "messages"));
|
|
||||||
# } else {
|
|
||||||
# return $this->render(array("action" => "show"));
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# /* id is a username */
|
|
||||||
# public function compose() {
|
|
||||||
# if (!$this->user) {
|
|
||||||
# $this->add_flash_error("You must be logged in to send messages.");
|
|
||||||
# return $this->redirect_to("/login");
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# if (!($this->recipient_user =
|
|
||||||
# User::find_by_username($this->params["id"]))) {
|
|
||||||
# $this->add_flash_error("Could not find recipient user.");
|
|
||||||
# return $this->redirect_to("/messages");
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# $this->page_title = "Compose Message To "
|
|
||||||
# . $this->recipient_user->username;
|
|
||||||
#
|
|
||||||
# $this->message = new Message;
|
|
||||||
# $this->message->recipient_user_id = $this->recipient_user->id;
|
|
||||||
# $this->message->author_user_id = $this->user->id;
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# public function send() {
|
|
||||||
# $this->compose();
|
|
||||||
#
|
|
||||||
# if ($this->message->update_attributes($this->params["message"])) {
|
|
||||||
# $this->add_flash_notice("Your message has been sent.");
|
|
||||||
# return $this->redirect_to(array("controller" => "messages"));
|
|
||||||
# } else {
|
|
||||||
# return $this->render(array("action" => "compose"));
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ class StoriesController < ApplicationController
|
||||||
@story.user_id = @user.id
|
@story.user_id = @user.id
|
||||||
|
|
||||||
if @story.save
|
if @story.save
|
||||||
Vote.vote_thusly_on_story_or_comment_for_user_because(1, @story.id,
|
Vote.vote_thusly_on_story_or_comment_for_user_because(1, @story.id,
|
||||||
nil, @user.id, nil)
|
nil, @user.id, nil)
|
||||||
|
|
||||||
return redirect_to @story.comments_url
|
return redirect_to @story.comments_url
|
||||||
|
@ -83,27 +83,27 @@ class StoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@story = Story.find_by_short_id!(params[:id])
|
@story = Story.find_by_short_id!(params[:id])
|
||||||
|
|
||||||
@page_title = @story.title
|
@page_title = @story.title
|
||||||
|
|
||||||
@comments = Comment.ordered_for_story_or_thread_for_user(
|
@comments = Comment.ordered_for_story_or_thread_for_user(
|
||||||
@story.id, nil, @user ? @user.id : nil)
|
@story.id, nil, @user ? @user.id : nil)
|
||||||
@comment = Comment.new
|
@comment = Comment.new
|
||||||
|
|
||||||
if @user
|
if @user
|
||||||
if v = Vote.find_by_user_id_and_story_id(@user.id, @story.id)
|
if v = Vote.find_by_user_id_and_story_id(@user.id, @story.id)
|
||||||
@story.vote = v.vote
|
@story.vote = v.vote
|
||||||
end
|
end
|
||||||
|
|
||||||
@votes = Vote.comment_votes_by_user_for_story_hash(@user.id, @story.id)
|
@votes = Vote.comment_votes_by_user_for_story_hash(@user.id, @story.id)
|
||||||
@comments.each do |c|
|
@comments.each do |c|
|
||||||
if @votes[c.id]
|
if @votes[c.id]
|
||||||
c.current_vote = @votes[c.id]
|
c.current_vote = @votes[c.id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def undelete
|
def undelete
|
||||||
|
@ -114,48 +114,48 @@ class StoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@story.is_expired = false
|
@story.is_expired = false
|
||||||
|
|
||||||
if @story.update_attributes(params[:story].except(:url))
|
if @story.update_attributes(params[:story].except(:url))
|
||||||
return redirect_to @story.comments_url
|
return redirect_to @story.comments_url
|
||||||
else
|
else
|
||||||
return render :action => "edit"
|
return render :action => "edit"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# public function update() {
|
# public function update() {
|
||||||
# if (!$this->user) {
|
# if (!$this->user) {
|
||||||
# $this->add_flash_error("You must be logged in to edit an item.");
|
# $this->add_flash_error("You must be logged in to edit an item.");
|
||||||
# return $this->redirect_to("/login");
|
# return $this->redirect_to("/login");
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
# if ($this->user->is_admin)
|
# if ($this->user->is_admin)
|
||||||
# $this->item = Item::find_by_id($this->params["id"]);
|
# $this->item = Item::find_by_id($this->params["id"]);
|
||||||
# else
|
# else
|
||||||
# $this->item = Item::find_by_user_id_and_id($this->user->id,
|
# $this->item = Item::find_by_user_id_and_id($this->user->id,
|
||||||
# $this->params["id"]);
|
# $this->params["id"]);
|
||||||
#
|
#
|
||||||
# if (!$this->item) {
|
# if (!$this->item) {
|
||||||
# $this->add_flash_error("Could not find item or you are not "
|
# $this->add_flash_error("Could not find item or you are not "
|
||||||
# . "authorized to edit it.");
|
# . "authorized to edit it.");
|
||||||
# return $this->redirect_to("/");
|
# return $this->redirect_to("/");
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
# $this->item->is_expired = false;
|
# $this->item->is_expired = false;
|
||||||
# if ($this->item->update_attributes($this->params["item"])) {
|
# if ($this->item->update_attributes($this->params["item"])) {
|
||||||
# $this->add_flash_notice("Successfully saved item changes.");
|
# $this->add_flash_notice("Successfully saved item changes.");
|
||||||
# return $this->redirect_to(array("controller" => "items",
|
# return $this->redirect_to(array("controller" => "items",
|
||||||
# "action" => "show", "id" => $this->item->id));
|
# "action" => "show", "id" => $this->item->id));
|
||||||
# } else
|
# } else
|
||||||
# return $this->render(array("action" => "edit"));
|
# return $this->render(array("action" => "edit"));
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
def unvote
|
def unvote
|
||||||
if !(story = Story.find_by_short_id(params[:story_id]))
|
if !(story = Story.find_by_short_id(params[:story_id]))
|
||||||
return render :text => "can't find story", :status => 400
|
return render :text => "can't find story", :status => 400
|
||||||
end
|
end
|
||||||
|
|
||||||
Vote.vote_thusly_on_story_or_comment_for_user_because(0, story.id,
|
Vote.vote_thusly_on_story_or_comment_for_user_because(0, story.id,
|
||||||
nil, @user.id, nil)
|
nil, @user.id, nil)
|
||||||
|
|
||||||
render :text => "ok"
|
render :text => "ok"
|
||||||
|
@ -166,7 +166,7 @@ class StoriesController < ApplicationController
|
||||||
return render :text => "can't find story", :status => 400
|
return render :text => "can't find story", :status => 400
|
||||||
end
|
end
|
||||||
|
|
||||||
Vote.vote_thusly_on_story_or_comment_for_user_because(1, story.id,
|
Vote.vote_thusly_on_story_or_comment_for_user_because(1, story.id,
|
||||||
nil, @user.id, nil)
|
nil, @user.id, nil)
|
||||||
|
|
||||||
render :text => "ok"
|
render :text => "ok"
|
||||||
|
@ -176,7 +176,7 @@ class StoriesController < ApplicationController
|
||||||
if !(story = Story.find_by_short_id(params[:story_id]))
|
if !(story = Story.find_by_short_id(params[:story_id]))
|
||||||
return render :text => "can't find story", :status => 400
|
return render :text => "can't find story", :status => 400
|
||||||
end
|
end
|
||||||
|
|
||||||
if !Vote::STORY_REASONS[params[:reason]]
|
if !Vote::STORY_REASONS[params[:reason]]
|
||||||
return render :text => "invalid reason", :status => 400
|
return render :text => "invalid reason", :status => 400
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@showing_user = User.find_by_username!(params[:id])
|
@showing_user = User.find_by_username!(params[:id])
|
||||||
|
|
||||||
@page_title = "User: #{@showing_user.username}"
|
@page_title = "User: #{@showing_user.username}"
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ class PasswordReset < ActionMailer::Base
|
||||||
@user = user
|
@user = user
|
||||||
@ip = ip
|
@ip = ip
|
||||||
|
|
||||||
mail(to: user.email, from: "Lobsters <nobody@lobste.rs",
|
mail(to: user.email, from: "Lobsters <nobody@lobste.rs>",
|
||||||
subject: "[Lobsters] Reset your password")
|
subject: "[Lobsters] Reset your password")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class Comment < ActiveRecord::Base
|
class Comment < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :story
|
belongs_to :story
|
||||||
has_many :votes,
|
has_many :votes,
|
||||||
:dependent => :delete_all
|
:dependent => :delete_all
|
||||||
|
@ -13,42 +13,42 @@ class Comment < ActiveRecord::Base
|
||||||
after_create :assign_votes
|
after_create :assign_votes
|
||||||
after_destroy :unassign_votes
|
after_destroy :unassign_votes
|
||||||
|
|
||||||
MAX_EDIT_MINS = 45
|
MAX_EDIT_MINS = 45
|
||||||
|
|
||||||
validate do
|
validate do
|
||||||
self.comment.to_s.strip == "" &&
|
self.comment.to_s.strip == "" &&
|
||||||
errors.add(:comment, "cannot be blank.")
|
errors.add(:comment, "cannot be blank.")
|
||||||
|
|
||||||
self.user_id.blank? &&
|
self.user_id.blank? &&
|
||||||
errors.add(:user_id, "cannot be blank.")
|
errors.add(:user_id, "cannot be blank.")
|
||||||
|
|
||||||
self.story_id.blank? &&
|
self.story_id.blank? &&
|
||||||
errors.add(:story_id, "cannot be blank.")
|
errors.add(:story_id, "cannot be blank.")
|
||||||
|
|
||||||
(m = self.comment.to_s.strip.match(/\A(t)his([\.!])?$\z/i)) &&
|
(m = self.comment.to_s.strip.match(/\A(t)his([\.!])?$\z/i)) &&
|
||||||
errors.add(:base, (m[1] == "T" ? "N" : "n") + "ope" + m[2].to_s)
|
errors.add(:base, (m[1] == "T" ? "N" : "n") + "ope" + m[2].to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_short_id_and_upvote
|
def assign_short_id_and_upvote
|
||||||
(1...10).each do |tries|
|
(1...10).each do |tries|
|
||||||
if tries == 10
|
if tries == 10
|
||||||
raise "too many hash collisions"
|
raise "too many hash collisions"
|
||||||
end
|
end
|
||||||
|
|
||||||
if !Comment.find_by_short_id(self.short_id = Utils.random_str(6))
|
if !Comment.find_by_short_id(self.short_id = Utils.random_str(6))
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.upvotes = 1
|
self.upvotes = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def assign_votes
|
def assign_votes
|
||||||
Vote.vote_thusly_on_story_or_comment_for_user_because(1, self.story_id,
|
Vote.vote_thusly_on_story_or_comment_for_user_because(1, self.story_id,
|
||||||
self.id, self.user.id, nil, false)
|
self.id, self.user.id, nil, false)
|
||||||
|
|
||||||
self.story.update_comment_count!
|
self.story.update_comment_count!
|
||||||
end
|
end
|
||||||
|
|
||||||
# http://evanmiller.org/how-not-to-sort-by-average-rating.html
|
# http://evanmiller.org/how-not-to-sort-by-average-rating.html
|
||||||
# https://github.com/reddit/reddit/blob/master/r2/r2/lib/db/_sorts.pyx
|
# https://github.com/reddit/reddit/blob/master/r2/r2/lib/db/_sorts.pyx
|
||||||
|
@ -68,28 +68,28 @@ class Comment < ActiveRecord::Base
|
||||||
return (left - right) / under
|
return (left - right) / under
|
||||||
end
|
end
|
||||||
|
|
||||||
def unassign_votes
|
def unassign_votes
|
||||||
self.story.update_comment_count!
|
self.story.update_comment_count!
|
||||||
end
|
|
||||||
|
|
||||||
def score
|
|
||||||
self.upvotes - self.downvotes
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def linkified_comment
|
def score
|
||||||
Markdowner.markdown(self.comment)
|
self.upvotes - self.downvotes
|
||||||
end
|
end
|
||||||
|
|
||||||
def upvote!(amount = 1)
|
def linkified_comment
|
||||||
Story.update_counters self.id, :upvotes => amount
|
Markdowner.markdown(self.comment)
|
||||||
end
|
end
|
||||||
|
|
||||||
def flag!
|
def upvote!(amount = 1)
|
||||||
|
Story.update_counters self.id, :upvotes => amount
|
||||||
|
end
|
||||||
|
|
||||||
|
def flag!
|
||||||
Story.update_counters self.id, :flaggings => 1
|
Story.update_counters self.id, :flaggings => 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.ordered_for_story_or_thread_for_user(story_id, thread_id, user_id)
|
def self.ordered_for_story_or_thread_for_user(story_id, thread_id, user_id)
|
||||||
parents = {}
|
parents = {}
|
||||||
|
|
||||||
if thread_id
|
if thread_id
|
||||||
cs = [ "thread_id = ?", thread_id ]
|
cs = [ "thread_id = ?", thread_id ]
|
||||||
|
@ -118,13 +118,13 @@ class Comment < ActiveRecord::Base
|
||||||
recursor.call(nil, 0)
|
recursor.call(nil, 0)
|
||||||
|
|
||||||
ordered
|
ordered
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_editable_by_user?(user)
|
def is_editable_by_user?(user)
|
||||||
if !user || user.id != self.user_id
|
if !user || user.id != self.user_id
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
(Time.now.to_i - self.created_at.to_i < (60 * MAX_EDIT_MINS))
|
(Time.now.to_i - self.created_at.to_i < (60 * MAX_EDIT_MINS))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class Tagging < ActiveRecord::Base
|
class Tagging < ActiveRecord::Base
|
||||||
belongs_to :tag
|
belongs_to :tag
|
||||||
belongs_to :story
|
belongs_to :story
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
has_many :stories,
|
has_many :stories,
|
||||||
:include => :user
|
:include => :user
|
||||||
has_secure_password
|
has_secure_password
|
||||||
|
|
||||||
|
@ -22,13 +22,13 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def unread_message_count
|
def unread_message_count
|
||||||
0
|
0
|
||||||
#Message.where(:recipient_user_id => self.id, :has_been_read => 0).count
|
#Message.where(:recipient_user_id => self.id, :has_been_read => 0).count
|
||||||
end
|
end
|
||||||
|
|
||||||
def karma
|
def karma
|
||||||
Keystore.value_for("user:#{self.id}:karma").to_i
|
Keystore.value_for("user:#{self.id}:karma").to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def stories_submitted_count
|
def stories_submitted_count
|
||||||
|
@ -47,7 +47,7 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def linkified_about
|
def linkified_about
|
||||||
Markdowner.markdown(self.about)
|
Markdowner.markdown(self.about)
|
||||||
end
|
end
|
||||||
|
|
||||||
def recent_threads(amount = 20)
|
def recent_threads(amount = 20)
|
||||||
|
|
|
@ -1,47 +1,47 @@
|
||||||
class Vote < ActiveRecord::Base
|
class Vote < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :story
|
belongs_to :story
|
||||||
|
|
||||||
STORY_REASONS = {
|
STORY_REASONS = {
|
||||||
"S" => "Spam",
|
"S" => "Spam",
|
||||||
"A" => "Already Posted",
|
"A" => "Already Posted",
|
||||||
"L" => "Poorly Titled",
|
"L" => "Poorly Titled",
|
||||||
"T" => "Poorly Tagged",
|
"T" => "Poorly Tagged",
|
||||||
"O" => "Off-topic",
|
"O" => "Off-topic",
|
||||||
"" => "Cancel",
|
"" => "Cancel",
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMENT_REASONS = {
|
COMMENT_REASONS = {
|
||||||
"O" => "Off-topic",
|
"O" => "Off-topic",
|
||||||
"I" => "Incorrect",
|
"I" => "Incorrect",
|
||||||
"M" => "Me-too",
|
"M" => "Me-too",
|
||||||
"T" => "Troll",
|
"T" => "Troll",
|
||||||
"S" => "Spam",
|
"S" => "Spam",
|
||||||
"" => "Cancel",
|
"" => "Cancel",
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.votes_by_user_for_stories_hash(user, stories)
|
def self.votes_by_user_for_stories_hash(user, stories)
|
||||||
votes = []
|
votes = []
|
||||||
Vote.where(:user_id => user, :story_id => stories,
|
Vote.where(:user_id => user, :story_id => stories,
|
||||||
:comment_id => nil).each do |v|
|
:comment_id => nil).each do |v|
|
||||||
votes[v.story_id] = v.vote
|
votes[v.story_id] = v.vote
|
||||||
end
|
|
||||||
|
|
||||||
votes
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.comment_votes_by_user_for_story_hash(user_id, story_id)
|
|
||||||
votes = {}
|
|
||||||
|
|
||||||
Vote.find(:all, :conditions => [ "user_id = ? AND story_id = ? AND " +
|
|
||||||
"comment_id IS NOT NULL", user_id, story_id ]).each do |v|
|
|
||||||
votes[v.comment_id] = { :vote => v.vote, :reason => v.reason }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
votes
|
votes
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.vote_thusly_on_story_or_comment_for_user_because(vote, story_id,
|
def self.comment_votes_by_user_for_story_hash(user_id, story_id)
|
||||||
|
votes = {}
|
||||||
|
|
||||||
|
Vote.find(:all, :conditions => [ "user_id = ? AND story_id = ? AND " +
|
||||||
|
"comment_id IS NOT NULL", user_id, story_id ]).each do |v|
|
||||||
|
votes[v.comment_id] = { :vote => v.vote, :reason => v.reason }
|
||||||
|
end
|
||||||
|
|
||||||
|
votes
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.vote_thusly_on_story_or_comment_for_user_because(vote, story_id,
|
||||||
comment_id, user_id, reason, update_counters = true)
|
comment_id, user_id, reason, update_counters = true)
|
||||||
v = if comment_id
|
v = if comment_id
|
||||||
Vote.find_or_initialize_by_user_id_and_story_id_and_comment_id(user_id,
|
Vote.find_or_initialize_by_user_id_and_story_id_and_comment_id(user_id,
|
||||||
|
|
Loading…
Reference in a new issue