Skip to content

Commit

Permalink
basic comment notifications, new favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
jywarren committed Apr 5, 2013
1 parent 095eac5 commit 5669b31
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 11 deletions.
4 changes: 3 additions & 1 deletion app/controllers/comment_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ class CommentController < ApplicationController

before_filter :require_user, :only => [:create, :update, :delete]

# handle some errors!!!!!!
def create
@node = DrupalNode.find params[:id]
@comment = @node.comment({:uid => current_user.uid,:body => params[:body]})
@comment.notify(current_user)
flash[:notice] = "Comment posted."
# should implement ajax too
redirect_to "/"+@node.slug+"#last" # to last comment
Expand All @@ -15,7 +17,7 @@ def update
# should abstract ".comment" to ".body" for future migration to native db
@comment.comment = params[:body]
if @comment.save
@comment.notify
@comment.notify(current_user)
flash[:notice] = "Comment updated."
else
flash[:error] = "The comment could not be updated."
Expand Down
10 changes: 10 additions & 0 deletions app/mailers/comment_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CommentMailer < ActionMailer::Base
default from: "[email protected]"

def notify_of_comment(user,comment)
@comment = comment
@user = user
mail(:to => user.email, :subject => "New comment on '"+comment.node.title+"'")
end

end
20 changes: 15 additions & 5 deletions app/models/drupal_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ class DrupalComment < ActiveRecord::Base
self.table_name = 'comments'
self.primary_key = 'cid'

before_save :notify

def self.inheritance_column
"rails_type"
end
Expand Down Expand Up @@ -45,9 +43,21 @@ def parent
self.drupal_node
end

# run email/other notifications
def notify
# email all users in this thread
def node
self.drupal_node
end

# users who are involved in this comment thread
def thread_participants

end

# email all users in this thread
def notify(current_user)
uids = (self.parent.comments.collect(&:uid) + [self.parent.uid]).uniq!
DrupalUsers.find(:all, :conditions => ['uid IN (?)',uids]).each do |user|
CommentMailer.notify_of_comment(user,self).deliver if user.uid != current_user.uid && user.uid != self.uid
end
end

end
2 changes: 1 addition & 1 deletion app/models/drupal_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def comment(params)
c.format = 1
c.thread = thread
c.timestamp = DateTime.now.to_i
c.save!
c if c.save!
end

def new_revision(params)
Expand Down
8 changes: 8 additions & 0 deletions app/models/drupal_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ class DrupalUsers < ActiveRecord::Base
has_many :drupal_node, :foreign_key => 'uid'
has_many :drupal_profile_values, :foreign_key => 'uid'

# Rails-style adaptors:

def created_at
Time.at(self.created)
end

def email
self.mail
end

# End rails-style adaptors

def profile_values
self.drupal_profile_values
end
Expand Down
17 changes: 17 additions & 0 deletions app/views/comment_mailer/notify_of_comment.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Hi! There's been a response to a discussion you're involved in. Do NOT reply to this email; click this link to respond:

http://publiclaboratory.org<%= @comment.node.path %>#comment-<%= @comment.cid %>

===============================

<%= @comment.author.name %> (http://publiclab.org/profile/<%= @comment.author.name %>) wrote:

<%= @comment.comment %>

===============================

Reply at: http://publiclaboratory.org<%= @comment.node.path %>#comment-<%= @comment.cid %>

If you are using the new alpha site, you can visit: http://publiclab.org<%= @comment.node.path %>#c<%= @comment.cid %>

Report abuse to: [email protected]
11 changes: 8 additions & 3 deletions app/views/home/dashboard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
<h3>Dashboard: <small>Welcome, <%= current_user.username %>!</small></h3>

<ul class="nav nav-tabs">
<li class="active"><a rel="tooltip" title="Research notes for: <%= @user.tagnames.join(', ') %>" data-placement="bottom" href="#">Recent Activity</a></li>
<li class="active"><a rel="tooltip" title="Research notes for: <%= @user.tagnames.join(', ') %>" data-placement="bottom" href="#"><span class="hidden-phone">Recent </span>Activity</a></li>
<li><a href="/nearby"><i class="icon icon-globe"></i> Nearby</a></li>
<li><a href="/notes/author/<%= current_user.username %>"><i class="icon icon-folder-open"></i> Your work (<%= DrupalNode.count(:all,:conditions => {:type => "note", :status => 1, :uid => current_user.uid}) %>)</a></li>
<li><a href="#"><i class="icon-cog"></i></a></li>
<li><a href="/notes/author/<%= current_user.username %>">
<i class="icon icon-folder-open"></i>
Your work
<span class="hidden-phone">
(<%= DrupalNode.count(:all,:conditions => {:type => "note", :status => 1, :uid => current_user.uid}) %>)
</span>
</a></li>
</ul>

<%= render :partial => "notes/notes" %>
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Plots2::Application.routes.draw do
resources :rusers
resources :users
resources :user_sessions
resources :images

Expand All @@ -17,6 +16,8 @@
match 'users/list' => 'users#list'
match 'signup' => 'users#new'

resources :users

match 'wiki/:id' => 'wiki#show'
match 'wiki/revisions/:id' => 'wiki#revisions'
match 'wiki/edit/:id' => 'wiki#edit'
Expand Down
Binary file modified public/favicon.ico
Binary file not shown.
Binary file added public/favicon.ico.bkp
Binary file not shown.
Binary file added public/favicon.ico.nostripes
Binary file not shown.
7 changes: 7 additions & 0 deletions test/functional/comment_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class CommentMailerTest < ActionMailer::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 5669b31

Please sign in to comment.