rubocop: Layout/MultilineOperationIndentation, 1208

This commit is contained in:
Peter Bhat Harkins 2018-03-14 09:15:35 -06:00
parent 738326d284
commit a2288d8af9
26 changed files with 125 additions and 141 deletions

View File

@ -16,8 +16,8 @@ class ApplicationController < ActionController::Base
end
if session[:u] &&
(user = User.where(:session_token => session[:u].to_s).first) &&
user.is_active?
(user = User.where(:session_token => session[:u].to_s).first) &&
user.is_active?
@user = user
Rails.logger.info " Logged in as user #{@user.id} (#{@user.username})"
end

View File

@ -21,7 +21,7 @@ class AvatarsController < ApplicationController
end
flash[:success] = "Your avatar cache has been purged of #{expired} " <<
"file#{expired == 1 ? "" : "s"}"
"file#{expired == 1 ? "" : "s"}"
return redirect_to "/settings"
end

View File

@ -11,7 +11,7 @@ class CommentsController < ApplicationController
def create
if !(story = Story.where(:short_id => params[:story_id]).first) ||
story.is_gone?
story.is_gone?
return render :plain => "can't find story", :status => 400
end
@ -34,8 +34,9 @@ class CommentsController < ApplicationController
# prevent double-clicks of the post button
if params[:preview].blank? &&
(pc = Comment.where(:story_id => story.id, :user_id => @user.id,
:parent_comment_id => comment.parent_comment_id).first)
(pc = Comment.where(:story_id => story.id,
:user_id => @user.id,
:parent_comment_id => comment.parent_comment_id).first)
if (Time.now - pc.created_at) < 5.minutes && !@user.is_moderator?
comment.errors.add(:comment, "^You have already posted a comment " <<
"here recently.")

View File

@ -45,8 +45,8 @@ class HomeController < ApplicationController
render :action => "privacy"
rescue ActionView::MissingTemplate
render :html => "<div class=\"box wide\">" <<
"You apparently have no privacy." <<
"</div>", :layout => "application"
"You apparently have no privacy." <<
"</div>", :layout => "application"
end
end
@ -232,7 +232,7 @@ class HomeController < ApplicationController
if length[:dur] > 1
@heading = @title = "Top Stories of the Past #{length[:dur]} " <<
length[:intv] << "s"
length[:intv] << "s"
else
@heading = @title = "Top Stories of the Past " << length[:intv]
end

View File

@ -13,8 +13,7 @@ class InvitationsController < ApplicationController
def index
if !@user.can_see_invitation_requests?
flash[:error] = "Your account is not permitted to view invitation " <<
"requests."
flash[:error] = "Your account is not permitted to view invitation requests."
return redirect_to "/"
end
@ -31,7 +30,7 @@ class InvitationsController < ApplicationController
ir.save!
flash[:success] = "Your invitation request has been validated and " <<
"will now be shown to other logged-in users."
"will now be shown to other logged-in users."
return redirect_to "/invitations/request"
end
@ -51,10 +50,10 @@ class InvitationsController < ApplicationController
i.save!
i.send_email
flash[:success] = "Successfully e-mailed invitation to " <<
params[:email].to_s << "."
params[:email].to_s << "."
rescue
flash[:error] = "Could not send invitation, verify the e-mail " <<
"address is valid."
"address is valid."
end
if params[:return_home]
@ -73,7 +72,7 @@ class InvitationsController < ApplicationController
if @invitation_request.save
flash[:success] = "You have been e-mailed a confirmation to " <<
params[:invitation_request][:email].to_s << "."
params[:invitation_request][:email].to_s << "."
return redirect_to "/invitations/request"
else
render :action => :build
@ -86,7 +85,7 @@ class InvitationsController < ApplicationController
def send_for_request
if !@user.can_see_invitation_requests?
flash[:error] = "Your account is not permitted to view invitation " <<
"requests."
"requests."
return redirect_to "/"
end
@ -102,10 +101,10 @@ class InvitationsController < ApplicationController
i.send_email
ir.destroy!
flash[:success] = "Successfully e-mailed invitation to " <<
ir.name.to_s << "."
ir.name.to_s << "."
Rails.logger.info "[u#{@user.id}] sent invitiation for request " <<
ir.inspect
ir.inspect
return redirect_to "/invitations"
end
@ -122,10 +121,10 @@ class InvitationsController < ApplicationController
ir.destroy!
flash[:success] = "Successfully deleted invitation request from " <<
ir.name.to_s << "."
ir.name.to_s << "."
Rails.logger.info "[u#{@user.id}] deleted invitation request " <<
"from #{ir.inspect}"
"from #{ir.inspect}"
return redirect_to "/invitations"
end

View File

@ -105,8 +105,7 @@ class LoginController < ApplicationController
@found_user.initiate_password_reset_for_ip(request.remote_ip)
flash.now[:success] = "Password reset instructions have been e-mailed " <<
"to you."
flash.now[:success] = "Password reset instructions have been e-mailed to you."
return index
end
@ -114,7 +113,7 @@ class LoginController < ApplicationController
@title = "Reset Password"
if (m = params[:token].to_s.match(/^(\d+)-/)) &&
(Time.now - Time.at(m[1].to_i)) < 24.hours
(Time.now - Time.at(m[1].to_i)) < 24.hours
@reset_user = User.where(:password_reset_token => params[:token].to_s).first
end
@ -145,7 +144,7 @@ class LoginController < ApplicationController
end
else
flash[:error] = "Invalid reset token. It may have already been " <<
"used or you may have copied it incorrectly."
"used or you may have copied it incorrectly."
return redirect_to forgot_password_path
end
end
@ -153,7 +152,7 @@ class LoginController < ApplicationController
def twofa
if tmpu = find_twofa_user
Rails.logger.info " Authenticated as user #{tmpu.id} " <<
"(#{tmpu.username}), verifying TOTP"
"(#{tmpu.username}), verifying TOTP"
else
reset_session
return redirect_to "/login"

View File

@ -56,7 +56,7 @@ class MessagesController < ApplicationController
if @new_message.save
flash[:success] = "Your message has been sent to " <<
@new_message.recipient.username.to_s << "."
@new_message.recipient.username.to_s << "."
return redirect_to "/messages"
else
render :action => "index"

View File

@ -28,7 +28,7 @@ class SettingsController < ApplicationController
@edit_user = @user.clone
if params[:user][:password].empty? ||
@user.authenticate(params[:current_password].to_s)
@user.authenticate(params[:current_password].to_s)
if @edit_user.update_attributes(user_params)
flash.now[:success] = "Successfully updated settings."
@user = @edit_user
@ -80,8 +80,10 @@ class SettingsController < ApplicationController
# no option for inline svg, so just strip off leading <?xml> tag
qrcode = RQRCode::QRCode.new(totp_url)
qr = qrcode.as_svg(offset: 0, color: "000", module_size: 5,
shape_rendering: "crispEdges").gsub(/^<\?xml.*>/, "")
qr = qrcode.as_svg(offset: 0,
color: "000",
module_size: 5,
shape_rendering: "crispEdges").gsub(/^<\?xml.*>/, "")
@qr_svg = "<a href=\"#{totp_url}\">#{qr}</a>"
end
@ -90,7 +92,7 @@ class SettingsController < ApplicationController
@title = "Two-Factor Authentication"
if ((Time.now.to_i - session[:last_authed].to_i) > TOTP_SESSION_TIMEOUT) ||
!session[:totp_secret]
!session[:totp_secret]
flash[:error] = "Your enrollment period timed out."
return redirect_to twofa_url
end
@ -98,7 +100,7 @@ class SettingsController < ApplicationController
def twofa_update
if ((Time.now.to_i - session[:last_authed].to_i) > TOTP_SESSION_TIMEOUT) ||
!session[:totp_secret]
!session[:totp_secret]
flash[:error] = "Your enrollment period timed out."
return redirect_to twofa_url
end
@ -111,13 +113,12 @@ class SettingsController < ApplicationController
session[:u] = @user.session_token
flash[:success] = "Two-Factor Authentication has been enabled on " <<
"your account."
flash[:success] = "Two-Factor Authentication has been enabled on your account."
session.delete(:totp_secret)
return redirect_to "/settings"
else
flash[:error] = "Your TOTP code was invalid, please verify the " <<
"current code in your TOTP application."
"current code in your TOTP application."
return redirect_to twofa_verify_url
end
end
@ -151,8 +152,7 @@ class SettingsController < ApplicationController
end
if params[:rand].to_s != session[:pushover_rand].to_s
raise "rand param #{params[:rand].inspect} != " <<
session[:pushover_rand].inspect
raise "rand param #{params[:rand].inspect} != #{session[:pushover_rand].inspect}"
end
@user.pushover_user_key = params[:pushover_user_key].to_s
@ -161,8 +161,7 @@ class SettingsController < ApplicationController
if @user.pushover_user_key.present?
flash[:success] = "Your account is now setup for Pushover notifications."
else
flash[:success] = "Your account is no longer setup for Pushover " <<
"notifications."
flash[:success] = "Your account is no longer setup for Pushover notifications."
end
return redirect_to "/settings"
@ -174,8 +173,9 @@ class SettingsController < ApplicationController
end
def github_callback
if !session[:github_state].present? || !params[:code].present? ||
(params[:state].to_s != session[:github_state].to_s)
if !session[:github_state].present? ||
!params[:code].present? ||
(params[:state].to_s != session[:github_state].to_s)
flash[:error] = "Invalid OAuth state"
return redirect_to "/settings"
end
@ -187,8 +187,7 @@ class SettingsController < ApplicationController
@user.github_oauth_token = tok
@user.github_username = username
@user.save!
flash[:success] = "Your account has been linked to GitHub user " <<
"#{username}."
flash[:success] = "Your account has been linked to GitHub user #{username}."
else
return github_disconnect
end
@ -210,8 +209,8 @@ class SettingsController < ApplicationController
end
def twitter_callback
if !session[:twitter_state].present? ||
(params[:state].to_s != session[:twitter_state].to_s)
if session[:twitter_state].blank? ||
(params[:state].to_s != session[:twitter_state].to_s)
flash[:error] = "Invalid OAuth state"
return redirect_to "/settings"
end
@ -225,8 +224,7 @@ class SettingsController < ApplicationController
@user.twitter_oauth_token_secret = sec
@user.twitter_username = username
@user.save!
flash[:success] = "Your account has been linked to Twitter user @" <<
"#{username}."
flash[:success] = "Your account has been linked to Twitter user @#{username}."
else
return twitter_disconnect
end

View File

@ -49,7 +49,7 @@ class SignupController < ApplicationController
@invitation.destroy
session[:u] = @new_user.session_token
flash[:success] = "Welcome to #{Rails.application.name}, " <<
"#{@new_user.username}!"
"#{@new_user.username}!"
return redirect_to "/signup/invite"
else

View File

@ -78,7 +78,7 @@ class StoriesController < ApplicationController
if sattrs[:url].present? && @story.url != sattrs[:url]
flash.now[:notice] = "Note: URL has been changed to fetched " <<
"canonicalized version"
"canonicalized version"
@story.url = sattrs[:url]
end
@ -144,9 +144,9 @@ class StoriesController < ApplicationController
"twitter:site" => "@lobsters",
"twitter:title" => @story.title,
"twitter:description" => "#{@story.comments_count} comment" <<
"#{@story.comments_count == 1 ? "" : "s"}",
"#{@story.comments_count == 1 ? "" : "s"}",
"twitter:image" => Rails.application.root_url +
"apple-touch-icon-144.png",
"apple-touch-icon-144.png",
}
if @story.user.twitter_username.present?
@ -377,7 +377,7 @@ private
if !@story
flash[:error] = "Could not find story or you are not authorized " <<
"to manage it."
"to manage it."
redirect_to "/"
return false
end

View File

@ -1,6 +1,5 @@
class BanNotification < ActionMailer::Base
default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"
default :from => "#{Rails.application.name} <nobody@#{Rails.application.domain}>"
def notify(user, banner, reason)
@banner = banner

View File

@ -1,6 +1,5 @@
class EmailMessage < ActionMailer::Base
default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"
default :from => "#{Rails.application.name} <nobody@#{Rails.application.domain}>"
def notify(message, user)
@message = message
@ -9,7 +8,7 @@ class EmailMessage < ActionMailer::Base
mail(
:to => user.email,
:subject => "[#{Rails.application.name}] Private Message from " <<
"#{message.author_username}: #{message.subject}"
"#{message.author_username}: #{message.subject}"
)
end
end

View File

@ -1,6 +1,5 @@
class EmailReply < ActionMailer::Base
default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"
default :from => "#{Rails.application.name} <nobody@#{Rails.application.domain}>"
def reply(comment, user)
@comment = comment
@ -9,7 +8,7 @@ class EmailReply < ActionMailer::Base
mail(
:to => user.email,
:subject => "[#{Rails.application.name}] Reply from " <<
"#{comment.user.username} on #{comment.story.title}"
"#{comment.user.username} on #{comment.story.title}"
)
end
@ -20,7 +19,7 @@ class EmailReply < ActionMailer::Base
mail(
:to => user.email,
:subject => "[#{Rails.application.name}] Mention from " <<
"#{comment.user.username} on #{comment.story.title}"
"#{comment.user.username} on #{comment.story.title}"
)
end
end

View File

@ -1,14 +1,13 @@
class InvitationMailer < ActionMailer::Base
default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"
default :from => "#{Rails.application.name} <nobody@#{Rails.application.domain}>"
def invitation(invitation)
@invitation = invitation
mail(
to: invitation.email,
subject: "[#{Rails.application.name}] You have been invited to " <<
Rails.application.name
subject: "[#{Rails.application.name}] You are invited to join " <<
Rails.application.name
)
end
end

View File

@ -1,6 +1,5 @@
class InvitationRequestMailer < ActionMailer::Base
default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"
default :from => "#{Rails.application.name} <nobody@#{Rails.application.domain}>"
def invitation_request(invitation_request)
@invitation_request = invitation_request
@ -8,7 +7,7 @@ class InvitationRequestMailer < ActionMailer::Base
mail(
to: invitation_request.email,
subject: "[#{Rails.application.name}] Confirm your invitation " <<
"request to " << Rails.application.name
"request to " << Rails.application.name
)
end
end

View File

@ -1,6 +1,5 @@
class PasswordReset < ActionMailer::Base
default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"
default :from => "#{Rails.application.name} <nobody@#{Rails.application.domain}>"
def password_reset_link(user, ip)
@user = user

View File

@ -75,8 +75,8 @@ class Comment < ActiveRecord::Base
# from the tree. otherwise they have to stay and a "[deleted]" stub
# will be shown
if node.is_gone? && # deleted or moderated
!children.present? && # don't have child comments
(!user || (!user.is_moderator? && node.user_id != user.id))
children.empty? && # don't have child comments
(!user || (!user.is_moderator? && node.user_id != user.id))
# admins and authors should be able to see their deleted comments
next
end
@ -246,8 +246,9 @@ class Comment < ActiveRecord::Base
end
def deliver_reply_notifications
if self.parent_comment_id && (u = self.parent_comment.try(:user)) &&
u.id != self.user.id
if self.parent_comment_id &&
(u = self.parent_comment.try(:user)) &&
u.id != self.user.id
if u.email_replies?
begin
EmailReply.reply(self, u).deliver_now
@ -308,7 +309,7 @@ class Comment < ActiveRecord::Base
elsif self.user.is_new?
c.push "new_user"
elsif self.story && self.story.user_is_author? &&
self.story.user_id == self.user_id
self.story.user_id == self.user_id
c.push "user_is_author"
end
@ -420,8 +421,8 @@ class Comment < ActiveRecord::Base
def showing_downvotes_for_user?(u)
return (u && u.is_moderator?) ||
(self.created_at && self.created_at < 36.hours.ago) ||
!SCORE_RANGE_TO_HIDE.include?(self.score)
(self.created_at && self.created_at < 36.hours.ago) ||
!SCORE_RANGE_TO_HIDE.include?(self.score)
end
def to_param

View File

@ -33,9 +33,9 @@ class Hat < ActiveRecord::Base
hl = (self.link.present? && self.link.match(/^https?:\/\//))
h = "<span class=\"hat " <<
"hat_#{self.hat.gsub(/[^A-Za-z0-9]/, "_").downcase}\" " <<
"title=\"Granted by " << "#{self.granted_by_user.username} on " <<
"#{self.created_at.strftime("%Y-%m-%d")}"
"hat_#{self.hat.gsub(/[^A-Za-z0-9]/, "_").downcase}\" " <<
"title=\"Granted by " << "#{self.granted_by_user.username} on " <<
"#{self.created_at.strftime("%Y-%m-%d")}"
if !hl && self.link.present?
h << " - #{ERB::Util.html_escape(self.link)}"

View File

@ -22,7 +22,7 @@ class HatRequest < ActiveRecord::Base
m.recipient_user_id = self.user_id
m.subject = "Your hat \"#{self.hat}\" has been approved"
m.body = "This hat may now be worn when commenting.\n\n" +
"This is an automated message."
"This is an automated message."
m.save!
self.destroy

View File

@ -18,12 +18,12 @@ class Moderation < ActiveRecord::Base
if self.story
m.recipient_user_id = self.story.user_id
m.subject = "Your story has been edited by " <<
(self.is_from_suggestions? ? "user suggestions" : "a moderator")
(self.is_from_suggestions? ? "user suggestions" : "a moderator")
m.body = "Your story [#{self.story.title}](" <<
"#{self.story.comments_url}) has been edited with the following " <<
"changes:\n" <<
"\n" <<
"> *#{self.action}*\n"
"#{self.story.comments_url}) has been edited with the following " <<
"changes:\n" <<
"\n" <<
"> *#{self.action}*\n"
if self.reason.present?
m.body << "\n" <<
@ -36,9 +36,9 @@ class Moderation < ActiveRecord::Base
m.recipient_user_id = self.comment.user_id
m.subject = "Your comment has been moderated"
m.body = "Your comment on [#{self.comment.story.title}](" <<
"#{self.comment.story.comments_url}) has been moderated:\n" <<
"\n" <<
"> *#{self.comment.comment}*\n"
"#{self.comment.story.comments_url}) has been moderated:\n" <<
"\n" <<
"> *#{self.comment.comment}*\n"
if self.reason.present?
m.body << "\n" <<

View File

@ -284,8 +284,7 @@ class Story < ActiveRecord::Base
self.taggings.each do |t|
if !t.tag.valid_for?(u)
raise "#{u.username} does not have permission to use privileged " <<
"tag #{t.tag.tag}"
raise "#{u.username} does not have permission to use privileged tag #{t.tag.tag}"
elsif t.tag.inactive? && t.new_record? && !t.marked_for_destruction?
# stories can have inactive tags as long as they existed before
raise "#{u.username} cannot add inactive tag #{t.tag.tag}"
@ -444,8 +443,7 @@ class Story < ActiveRecord::Base
end
def is_unavailable=(what)
self.unavailable_at = (what.to_i == 1 && !self.is_unavailable ?
Time.now : nil)
self.unavailable_at = (what.to_i == 1 && !self.is_unavailable ? Time.now : nil)
end
def is_undeletable_by_user?(user)
@ -460,8 +458,7 @@ class Story < ActiveRecord::Base
def log_moderation
if self.new_record? ||
(!self.editing_from_suggestions &&
(!self.editor || self.editor.id == self.user_id))
(!self.editing_from_suggestions && (!self.editor || self.editor.id == self.user_id))
return
end
@ -607,7 +604,7 @@ class Story < ActiveRecord::Base
# XXX: AR bug? st.exists?(:tag => tag_name) does not work
if tag_name.to_s != "" && !st.map {|x| x.tag.tag }.include?(tag_name)
if (t = Tag.active.where(:tag => tag_name).first) &&
t.valid_for?(user)
t.valid_for?(user)
tg = self.suggested_taggings.build
tg.user_id = user.id
tg.tag_id = t.id
@ -638,14 +635,14 @@ class Story < ActiveRecord::Base
if final_tags.any? && (final_tags.sort != self.tags_a.sort)
Rails.logger.info "[s#{self.id}] promoting suggested tags " <<
"#{final_tags.inspect} instead of #{self.tags_a.inspect}"
"#{final_tags.inspect} instead of #{self.tags_a.inspect}"
self.editor = nil
self.editing_from_suggestions = true
self.moderation_reason = "Automatically changed from user suggestions"
self.tags_a = final_tags.sort
if !self.save
Rails.logger.error "[s#{self.id}] failed auto promoting: " <<
self.errors.inspect
self.errors.inspect
end
end
end
@ -669,14 +666,14 @@ class Story < ActiveRecord::Base
title_votes.sort_by {|_k, v| v }.reverse.each do |kv|
if kv[1] >= SUGGESTION_QUORUM
Rails.logger.info "[s#{self.id}] promoting suggested title " <<
"#{kv[0].inspect} instead of #{self.title.inspect}"
"#{kv[0].inspect} instead of #{self.title.inspect}"
self.editor = nil
self.editing_from_suggestions = true
self.moderation_reason = "Automatically changed from user suggestions"
self.title = kv[0]
if !self.save
Rails.logger.error "[s#{self.id}] failed auto promoting: " <<
self.errors.inspect
self.errors.inspect
end
break
@ -852,8 +849,9 @@ class Story < ActiveRecord::Base
site_name = parsed.at_css("meta[property='og:site_name']")
.attributes["content"].text
if site_name.present? && site_name.length < title.length &&
title[-(site_name.length), site_name.length] == site_name
if site_name.present? &&
site_name.length < title.length &&
title[-(site_name.length), site_name.length] == site_name
title = title[0, title.length - site_name.length]
# remove title/site name separator
@ -869,9 +867,9 @@ class Story < ActiveRecord::Base
# now get canonical version of url (though some cms software puts incorrect
# urls here, hopefully the user will notice)
begin
if (cu = parsed.at_css("link[rel='canonical']").attributes["href"]
.text).present? && (ucu = URI.parse(cu)) && ucu.scheme.present? &&
ucu.host.present?
if (cu = parsed.at_css("link[rel='canonical']").attributes["href"] .text).present? &&
(ucu = URI.parse(cu)) && ucu.scheme.present? &&
ucu.host.present?
@fetched_attributes[:url] = cu
end
rescue

View File

@ -178,10 +178,10 @@ class User < ActiveRecord::Base
msg.recipient_user_id = self.id
msg.subject = "Your invite privileges have been revoked"
msg.body = "The reason given:\n" <<
"\n" <<
"> *#{reason}*\n" <<
"\n" <<
"*This is an automated message.*"
"\n" <<
"> *#{reason}*\n" <<
"\n" <<
"*This is an automated message.*"
msg.save!
m = Moderation.new
@ -278,8 +278,8 @@ class User < ActiveRecord::Base
def fetched_avatar(size = 100)
gravatar_url = "https://www.gravatar.com/avatar/" <<
Digest::MD5.hexdigest(self.email.strip.downcase) <<
"?r=pg&d=identicon&s=#{size}"
Digest::MD5.hexdigest(self.email.strip.downcase) <<
"?r=pg&d=identicon&s=#{size}"
begin
s = Sponge.new

View File

@ -83,8 +83,7 @@ class Sponge
# check for domain cookies
@cookies.keys.each do |dom|
if dom.length < host.length &&
dom == host[host.length - dom.length .. host.length - 1]
if dom.length < host.length && dom == host[host.length - dom.length .. host.length - 1]
dputs "adding domain keys from #{dom}"
cooks = cooks.merge @cookies[dom]
end
@ -178,9 +177,9 @@ class Sponge
path.gsub!(/^\/\//, "/")
dputs "fetching #{url} (#{ip.to_s}) " + (uri.user ? "with http auth " +
uri.user + "/" + ("*" * uri.password.length) + " " : "") +
"by #{method} with cookies #{cookies(uri.host)}"
dputs "fetching #{url} (#{ip.to_s}) " +
(uri.user ? "with http auth " + uri.user + "/" + ("*" * uri.password.length) + " " : "") +
"by #{method} with cookies #{cookies(uri.host)}"
send_headers = {
"Host" => uri.host,
@ -190,8 +189,7 @@ class Sponge
}.merge(send_headers || {})
if uri.user
send_headers["Authorization"] = "Basic " +
["#{uri.user}:#{uri.password}"].pack('m').delete("\r\n")
send_headers["Authorization"] = "Basic " + ["#{uri.user}:#{uri.password}"].pack('m').delete("\r\n")
end
res = nil

View File

@ -16,8 +16,7 @@ class StoryCacher
return nil
end
db_url = "#{DIFFBOT_API_URL}?token=#{@@DIFFBOT_API_KEY}&url=" <<
CGI.escape(story.url)
db_url = "#{DIFFBOT_API_URL}?token=#{@@DIFFBOT_API_KEY}&url=#{CGI.escape(story.url)}"
begin
s = Sponge.new

View File

@ -78,18 +78,15 @@ Story.where("id > ? AND is_expired = ?", last_story_id, false).order(:id).each d
end
domain = Rails.application.domain
list = "#{Rails.application.shortname}-#{u.mailing_list_token}@" <<
Rails.application.domain
list = "#{Rails.application.shortname}-#{u.mailing_list_token}@#{ails.application.domain}"
IO.popen([{}, "/usr/sbin/sendmail", "-i", "-f", "nobody@#{Rails.application.domain}", u.email], "w") do |mail|
mail.puts "From: #{s.user.username} <#{s.user.username}@" <<
"#{Rails.application.domain}>"
mail.puts "From: #{s.user.username} <#{s.user.username}@#{Rails.application.domain}>"
mail.puts "Reply-To: #{list}"
mail.puts "To: #{list}"
mail.puts "X-BeenThere: #{list}"
mail.puts "List-Id: #{Rails.application.name} <#{list}>"
mail.puts "List-Unsubscribe: <" <<
"#{Rails.application.root_url}settings>"
mail.puts "List-Unsubscribe: <#{Rails.application.root_url}settings>"
mail.puts "Precedence: list"
mail.puts "MIME-Version: 1.0"
mail.puts "Content-Type: text/plain; charset=\"utf-8\""
@ -160,8 +157,7 @@ last_comment_id, false, false).order(:id).each do |c|
end
domain = Rails.application.domain
list = "#{Rails.application.shortname}-#{u.mailing_list_token}@" <<
Rails.application.domain
list = "#{Rails.application.shortname}-#{u.mailing_list_token}@#{Rails.application.domain}"
IO.popen([{}, "/usr/sbin/sendmail", "-i", "-f", "nobody@#{domain}", u.email], "w") do |mail|
from = "From: \"#{c.user.username}"
@ -174,8 +170,7 @@ last_comment_id, false, false).order(:id).each do |c|
mail.puts "Reply-To: #{list}"
mail.puts "To: #{list}"
mail.puts "List-Id: #{Rails.application.name} <#{list}>"
mail.puts "List-Unsubscribe: <" <<
"#{Rails.application.root_url}settings>"
mail.puts "List-Unsubscribe: <#{Rails.application.root_url}settings>"
mail.puts "Precedence: list"
mail.puts "MIME-Version: 1.0"
mail.puts "Content-Type: text/plain; charset=\"utf-8\""

View File

@ -24,17 +24,21 @@ StoriesPaginator.new(StoryRepository.new.hottest).get.first
via = ""
if s.user.twitter_username.present?
via = "\n" + (s.user_is_author? ? "by" : "via") +
" @#{s.user.twitter_username}"
via = "\n" +
(s.user_is_author? ? "by" : "via") +
" @#{s.user.twitter_username}"
end
tco_status = via + "\n" +
("X" * Twitter::TCO_LEN) + tags +
(s.url.present?? "\n" + ("X" * Twitter::TCO_LEN) : "")
tco_status = via +
"\n" +
("X" * Twitter::TCO_LEN) + tags +
(s.url.present? ? "\n" + ("X" * Twitter::TCO_LEN) : "")
status = via + "\n" +
s.short_id_url + tags +
(s.url.present?? "\n" + s.url : "")
status = via +
"\n" +
s.short_id_url +
tags +
(s.url.present? ? "\n" + s.url : "")
left_len = Twitter::MAX_TWEET_LEN - tco_status.length
@ -71,14 +75,12 @@ StoriesPaginator.new(StoryRepository.new.hottest).get.first
elsif res["errors"].select {|e| e["code"] == 226 || e["code"] == 186 }.any?
# twitter is rejecting the content of this message, skip it
s.update_column("twitter_id", 0)
puts "skipping: failed posting story #{s.id} (#{status.inspect}): " +
"#{res.inspect}\n"
puts "skipping: failed posting story #{s.id} (#{status.inspect}): #{res.inspect}\n"
else
raise
end
rescue => e
puts "failed posting story #{s.id} (#{status.inspect}): #{e.inspect}\n" +
"#{res.inspect}"
puts "failed posting story #{s.id} (#{status.inspect}): #{e.inspect}\n#{res.inspect}"
exit
end
end