Send messages directly instead of using controller filter. Litte improvements to the messages lists.

This commit is contained in:
Benjamin Meichsner 2009-03-09 13:02:43 +01:00
parent de4f1d573b
commit dd940fb414
6 changed files with 20 additions and 10 deletions

View file

@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base
#before_filter :select_foodcoop
before_filter :authenticate, :store_controller
after_filter :send_email_messages, :remove_controller
after_filter :remove_controller
# sends a mail, when an error occurs
# see plugins/exception_notification
@ -145,11 +145,6 @@ class ApplicationController < ActionController::Base
def remove_controller
Thread.current[:application_controller] = nil
end
# Sends any pending emails that were created during this request.
def send_email_messages
call_rake :send_emails unless Message.pending.empty?
end
# Get supplier in nested resources
def find_supplier

View file

@ -14,6 +14,8 @@ class MessagesController < ApplicationController
def create
@message = @current_user.send_messages.new(params[:message])
if @message.save
#FIXME: Send Mails wit ID instead of using message.state ...
call_rake :send_emails
flash[:notice] = "Nachricht ist gespeichert und wird versendet."
redirect_to messages_path
else

View file

@ -12,6 +12,13 @@ module MessagesHelper
end
def format_subject(message, length)
truncate "<b>#{link_to(h(message.subject), message)}</b> <span style='color:grey'>#{h(message.body)}</span>", :length => length
if message.subject.length > length
subject = truncate(message.subject, :length => length)
body = ""
else
subject = message.subject
body = truncate(message.body, :length => length - subject.length)
end
"<b>#{link_to(h(subject), message)}</b> <span style='color:grey'>#{h(body)}</span>"
end
end

View file

@ -78,7 +78,11 @@ class Message < ActiveRecord::Base
for message in messages
for recipient in message.recipients
if recipient.settings['messages.sendAsEmail'] == "1" && !recipient.email.blank?
Mailer.deliver_message(message, recipient)
begin
Mailer.deliver_message(message, recipient)
rescue
logger.warn "Deliver failed for #{recipient.nick}: #{recipient.email}"
end
end
end
message.update_attribute(:email_state, 1)

View file

@ -35,7 +35,9 @@
.box_title
%h2 Neuste Nachrichten
.column_content
= render :partial => 'messages/messages', :locals => { :subject_length => 110 }
= render :partial => 'messages/messages', :locals => { :subject_length => 70 }
%br/
= link_to "Alle Nachrichten einsehen", messages_path
- if @ordergroup
// Ordergroup overview

View file

@ -3,4 +3,4 @@
%p= link_to('Neue Nachricht', :action => 'new')
#messages
= render :partial => 'messages', :locals => { :subject_length => 200 }
= render :partial => 'messages', :locals => { :subject_length => 130 }