summaryrefslogtreecommitdiff
path: root/app/controllers/trigger_controller.rb
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-03-27 12:15:40 +0100
committerPeter Kozak <spag@golwen.net>2013-03-27 12:15:40 +0100
commitbb6e8f24515c056347c6444668c0cb636b799815 (patch)
tree5f0c79d237fc8da9e339a9294aa1b99fd6437524 /app/controllers/trigger_controller.rb
parent15d961291513ec240f683552f5b547df443beed9 (diff)
trigger controller fixed
Diffstat (limited to 'app/controllers/trigger_controller.rb')
-rw-r--r--app/controllers/trigger_controller.rb55
1 files changed, 25 insertions, 30 deletions
diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb
index 6b58d6a..3dbb2a5 100644
--- a/app/controllers/trigger_controller.rb
+++ b/app/controllers/trigger_controller.rb
@@ -1,49 +1,44 @@
class TriggerController < ApplicationController
def voicemail
- if !params[:sip_account_id].blank?
- sip_account = SipAccount.where(:id => params[:sip_account_id].to_i).first
- if sip_account
- sip_account.voicemail_messages.where(:notification => nil).each do |message|
- message.notification = false
- message.save
- if !File.exists?( message.file_path )
- next
+ if !params[:voicemail_account_id].blank?
+ voicemail_account = VoicemailAccount.where(:id => params[:voicemail_account_id].to_i).first
+ if voicemail_account
+ voicemail_messages = voicemail_account.voicemail_messages.where(:notification => nil)
+ if voicemail_messages.count > 0
+ if voicemail_account.voicemail_accountable.class == User
+ user = voicemail_account.voicemail_accountable
+ elsif voicemail_account.voicemail_accountable.class == SipAccount && voicemail_account.voicemail_accountable.sip_accountable.class == User
+ user = voicemail_account.voicemail_accountable = voicemail_account.voicemail_accountable.sip_accountable
end
- user = sip_account.sip_accountable
- if user.class != User
- next
+ if user
+ PrivatePub.publish_to("/users/#{user.id}/messages/new", "$('#new_voicemail_or_fax_indicator').hide('fast').show('slow');")
+ PrivatePub.publish_to("/users/#{user.id}/messages/new", "document.title = '* ' + document.title.replace( '* ' , '');")
end
+ end
- # Indicate a new voicemail in the navigation bar.
- #
- PrivatePub.publish_to("/users/#{user.id}/messages/new", "$('#new_voicemail_or_fax_indicator').hide('fast').show('slow');")
- PrivatePub.publish_to("/users/#{user.id}/messages/new", "document.title = '* ' + document.title.replace( '* ' , '');")
+ email = voicemail_account.notify_to
- if user.email.blank?
- next
- end
-
- voicemail_settings = sip_account.voicemail_setting
- if !voicemail_settings
- voicemail_settings = VoicemailSetting.new(:notify => user.send_voicemail_as_email_attachment, :attachment => user.send_voicemail_as_email_attachment, :mark_read => user.send_voicemail_as_email_attachment)
- end
+ if !email.blank?
+ voicemail_messages.each do |message|
+ message.notification = false
+ message.save
+ if !File.exists?( message.file_path )
+ next
+ end
+ message.notification = true
- message.notification = voicemail_settings.notify
- if voicemail_settings.notify
- if Notifications.new_voicemail(message, voicemail_settings.attachment).deliver
- if voicemail_settings.purge
+ if Notifications.new_voicemail(message, voicemail_account, email, voicemail_account.notification_setting('attachment')).deliver
+ if voicemail_account.notification_setting('purge')
message.delete
next
end
message.save
- if voicemail_settings.mark_read
+ if voicemail_account.notification_setting('mark_read')
message.mark_read
end
end
- else
- message.save
end
end