Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add comment notifications and ability to toggle them as a pref

  • Loading branch information...
commit 93da5559d1849aadf14dd4cf3b373e353f369de9 1 parent 58f65f8
@rwdaigle authored
View
1  Gemfile
@@ -25,6 +25,7 @@ gem 'newrelic_rpm'
gem 'newrelic-faraday'
gem 'airbrake'
gem 'kanshi', :require => false
+gem 'pony'
gem 'jquery-rails'
gem 'haml-rails'
View
3  Gemfile.lock
@@ -117,6 +117,8 @@ GEM
pjax_rails (0.3.3)
jquery-rails
polyglot (0.3.3)
+ pony (1.4)
+ mail (> 2.0)
queue_classic (2.0.1)
pg (~> 0.14.0)
scrolls (~> 0.2.1)
@@ -201,6 +203,7 @@ DEPENDENCIES
omniauth-github
pg
pjax_rails
+ pony
queue_classic
rack-worker
rails (= 3.2.8)
View
5 app/assets/stylesheets/site.sass
@@ -8,6 +8,11 @@
color: #ccc
font-size: 12px
+ .notifications
+ margin-right: 15px
+ color: #ccc
+ font-size: 12px
+
#footer
position: absolute
bottom: 0px
View
9 app/controllers/users_controller.rb
@@ -0,0 +1,9 @@
+class UsersController < ApplicationController
+
+ before_filter :force_user_login
+
+ def toggle_notifications
+ current_user.toggle_notifications
+ redirect_to :back
+ end
+end
View
14 app/models/comment_notifier.rb
@@ -5,7 +5,19 @@ class << self
def gist_commented(gist_id)
gist = Gist.find(gist_id)
user = gist.user
- # Mail!
+ if(user.notify_comments?)
+ log({ns: self, fn: __method__, measure: true, at: 'sending-notification'}, gist, user)
+ Pony.mail(:to => user.gh_email, :subject => "\"#{gist.description}\" has a new comment", :body => <<-EOS)
+The extremely unsophisticated comment-detection algorithm at Gisted would like to let you know that you have a new comment on your "#{gist.description}" gist.
+
+View your gist's comments at #{gist.url}#comments
+
+---
+-Gisted (https://gistedapp.herokuapp.com/)
+
+If this email offends your delicate sensibilities, you can opt out by clikcing the "turn off comment notifications" link on the Gisted interface: https://gistedapp.herokuapp.com/ or by complaining directly to @rwdaigle.
+ EOS
+ end
end
end
end
View
1  app/models/gist.rb
@@ -161,6 +161,7 @@ def indexed_attributes
def check_for_new_comments
if(comment_count_changed?)
+ log({ns: self, fn: __method__, measure: true, at: 'comment-count-changed'}, self, user)
QC.enqueue("CommentNotifier.gist_commented", id) if comment_count.to_i > comment_count_was.to_i
end
end
View
5 app/models/user.rb
@@ -42,6 +42,11 @@ def refresh_index(user_id, all = false)
end
end
+ def toggle_notifications
+ log({ns: self.class, fn: __method__, measure: true, to: !notify_comments}, self)
+ update_attribute(:notify_comments, !notify_comments)
+ end
+
def indexed!
update_attribute(:last_indexed_at, Time.now)
end
View
5 app/views/layouts/application.html.haml
@@ -27,6 +27,11 @@
#profile
- if user_logged_in?
%span.last-edited= "Last known gist activity on #{current_user.last_gist_updated_at ? current_user.last_gist_updated_at.to_formatted_s(:short) : 'never'}"
+ %span.notifications
+ - if(current_user.notify_comments?)
+ = link_to("turn off comment notifications", toggle_notifications_users_path, :method => :post)
+ - else
+ = link_to("notify me of gist comments", toggle_notifications_users_path, :method => :post)
%span.logout= link_to("logout", logout_path)
#header
.container
View
12 config/initializers/pony.rb
@@ -0,0 +1,12 @@
+Pony.options = {
+ :from => 'notifications@gistedapp.herokuapp.com',
+ :via => :smtp,
+ :via_options => {
+ :address => ENV['MAILGUN_SMTP_SERVER'],
+ :port => ENV['MAILGUN_SMTP_PORT'],
+ :user_name => ENV['MAILGUN_SMTP_LOGIN'],
+ :password => ENV['MAILGUN_SMTP_PASSWORD'],
+ :authentication => :plain,
+ :domain => ENV['HOST']
+ }
+}
View
6 config/routes.rb
@@ -14,6 +14,12 @@
# Though this was an option at one time?
all = [:index, :show, :new, :create, :edit, :update, :destroy]
+ resources :users, :except => all do
+ collection do
+ post 'toggle_notifications'
+ end
+ end
+
resources :gists, :except => all do
collection do
post 'refresh'
View
12 db/migrate/20121206183232_add_comment_preference.rb
@@ -0,0 +1,12 @@
+class AddCommentPreference < ActiveRecord::Migration
+
+ def up
+ change_table :users do |t|
+ t.boolean :notify_comments, :default => false
+ end
+ end
+
+ def down
+ remove_column :users, :notify_comments
+ end
+end
View
3  db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121125001827) do
+ActiveRecord::Schema.define(:version => 20121206183232) do
create_table "gist_files", :force => true do |t|
t.integer "gist_id"
@@ -72,6 +72,7 @@
t.datetime "updated_at", :null => false
t.boolean "gh_auth_active", :default => true
t.datetime "last_indexed_at"
+ t.boolean "notify_comments", :default => true
end
add_index "users", ["gh_id"], :name => "index_users_on_gh_id"
Please sign in to comment.
Something went wrong with that request. Please try again.