diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-09-19 15:32:52 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-09-19 15:32:52 +0000 |
commit | 16e09bfd774487d7b21e1b939f9b0321ad3a850a (patch) | |
tree | f1952dff78c37929699621a06a1de69adf3fda2c /app | |
parent | 9e7bce6a94626b4f96133bddc508192f2dfaff4f (diff) | |
download | redmine-16e09bfd774487d7b21e1b939f9b0321ad3a850a.tar.gz redmine-16e09bfd774487d7b21e1b939f9b0321ad3a850a.zip |
Adds watch/unwatch functionality at forum topic level (#1912).
Users who create/reply a topic are automatically added as watchers but are now able to unwatch the topic.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1878 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/messages_controller.rb | 2 | ||||
-rw-r--r-- | app/models/message.rb | 9 | ||||
-rw-r--r-- | app/models/message_observer.rb | 5 | ||||
-rw-r--r-- | app/views/messages/show.rhtml | 1 |
4 files changed, 14 insertions, 3 deletions
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 554279d21..79b4b616a 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -24,7 +24,7 @@ class MessagesController < ApplicationController verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show } verify :xhr => true, :only => :quote - + helper :watchers helper :attachments include AttachmentsHelper diff --git a/app/models/message.rb b/app/models/message.rb index 80df7a33a..f1cb2d0ba 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -33,11 +33,14 @@ class Message < ActiveRecord::Base {:id => o.parent_id, :anchor => "message-#{o.id}"})} acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]} + acts_as_watchable attr_protected :locked, :sticky validates_presence_of :subject, :content validates_length_of :subject, :maximum => 255 + after_create :add_author_as_watcher + def validate_on_create # Can not reply to a locked topic errors.add_to_base 'Topic is locked' if root.locked? && self != root @@ -68,4 +71,10 @@ class Message < ActiveRecord::Base def project board.project end + + private + + def add_author_as_watcher + Watcher.create(:watchable => self.root, :user => author) + end end diff --git a/app/models/message_observer.rb b/app/models/message_observer.rb index 043988172..d37b53813 100644 --- a/app/models/message_observer.rb +++ b/app/models/message_observer.rb @@ -17,8 +17,9 @@ class MessageObserver < ActiveRecord::Observer def after_create(message) - # send notification to the authors of the thread - recipients = ([message.root] + message.root.children).collect {|m| m.author.mail if m.author && m.author.active?} + recipients = [] + # send notification to the topic watchers + recipients += message.root.watcher_recipients # send notification to the board watchers recipients += message.board.watcher_recipients # send notification to project members who want to be notified diff --git a/app/views/messages/show.rhtml b/app/views/messages/show.rhtml index c24be7a21..31696d56d 100644 --- a/app/views/messages/show.rhtml +++ b/app/views/messages/show.rhtml @@ -2,6 +2,7 @@ link_to(h(@board.name), {:controller => 'boards', :action => 'show', :project_id => @project, :id => @board}) %> <div class="contextual"> + <%= watcher_tag(@topic, User.current) %> <%= link_to_remote_if_authorized l(:button_quote), { :url => {:action => 'quote', :id => @topic} }, :class => 'icon icon-comment' %> <%= link_to_if_authorized l(:button_edit), {:action => 'edit', :id => @topic}, :class => 'icon icon-edit' %> <%= link_to_if_authorized l(:button_delete), {:action => 'destroy', :id => @topic}, :method => :post, :confirm => l(:text_are_you_sure), :class => 'icon icon-del' %> |