Added ticket.get_references, added also reverences header to notification emails.
This commit is contained in:
parent
504fa4e6c9
commit
742e117b0b
4 changed files with 52 additions and 21 deletions
|
@ -17,23 +17,6 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
|
|||
fail "Can't send email, no channel definde for email_address id '#{ticket.group.email_address_id}'"
|
||||
end
|
||||
|
||||
# get references headers
|
||||
references = []
|
||||
if record.in_reply_to
|
||||
references.push record.in_reply_to
|
||||
end
|
||||
|
||||
# add all other article message_ids
|
||||
Ticket::Article.where(ticket_id: record.ticket_id).each {|article|
|
||||
if article.in_reply_to && !article.in_reply_to.empty?
|
||||
references.push article.in_reply_to
|
||||
end
|
||||
next if !article.message_id
|
||||
next if !article.message_id.empty?
|
||||
next if article.id == @article_id
|
||||
references.push article.message_id
|
||||
}
|
||||
|
||||
channel = ticket.group.email_address.channel
|
||||
|
||||
# get linked channel and send
|
||||
|
@ -41,7 +24,7 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
|
|||
{
|
||||
message_id: record.message_id,
|
||||
in_reply_to: record.in_reply_to,
|
||||
references: references,
|
||||
references: ticket.get_references([record.message_id]),
|
||||
from: record.from,
|
||||
to: record.to,
|
||||
cc: record.cc,
|
||||
|
|
|
@ -164,7 +164,9 @@ class Observer::Ticket::Notification::BackgroundJob
|
|||
article: article,
|
||||
recipient: user,
|
||||
changes: changes,
|
||||
}
|
||||
},
|
||||
references: ticket.get_references,
|
||||
main_object: ticket,
|
||||
)
|
||||
Rails.logger.debug "sent ticket email notifiaction to agent (#{@p[:type]}/#{ticket.id}/#{user.email})"
|
||||
end
|
||||
|
|
|
@ -531,6 +531,42 @@ condition example
|
|||
[query, bind_params, tables]
|
||||
end
|
||||
|
||||
=begin
|
||||
|
||||
get all email references headers of a ticket, to exclude some, parse it as array into method
|
||||
|
||||
references = ticket.get_references
|
||||
|
||||
result
|
||||
|
||||
['message-id-1234', 'message-id-5678']
|
||||
|
||||
ignore references header(s)
|
||||
|
||||
references = ticket.get_references(['message-id-5678'])
|
||||
|
||||
result
|
||||
|
||||
['message-id-1234']
|
||||
|
||||
=end
|
||||
|
||||
def get_references(ignore = [])
|
||||
references = []
|
||||
Ticket::Article.select('in_reply_to, message_id').where(ticket_id: id).each {|article|
|
||||
if !article.in_reply_to.empty?
|
||||
references.push article.in_reply_to
|
||||
end
|
||||
next if !article.message_id
|
||||
next if article.message_id.empty?
|
||||
references.push article.message_id
|
||||
}
|
||||
ignore.each {|item|
|
||||
references.delete(item)
|
||||
}
|
||||
references
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_generate
|
||||
|
|
|
@ -96,10 +96,11 @@ module NotificationFactory
|
|||
=begin
|
||||
|
||||
success = NotificationFactory.send(
|
||||
recipient: User.find(123),
|
||||
recipient: User.find(123),
|
||||
subject: 'sime subject',
|
||||
body: 'some body',
|
||||
content_type: '', # optional, e. g. 'text/html'
|
||||
references: ['message-id123', 'message-id456'],
|
||||
)
|
||||
|
||||
=end
|
||||
|
@ -121,6 +122,7 @@ module NotificationFactory
|
|||
from: sender,
|
||||
to: data[:recipient][:email],
|
||||
subject: data[:subject],
|
||||
references: data[:references],
|
||||
body: data[:body],
|
||||
content_type: content_type,
|
||||
},
|
||||
|
@ -133,9 +135,11 @@ module NotificationFactory
|
|||
NotificationFactory.notification(
|
||||
template: 'password_reset',
|
||||
user: User.find(2),
|
||||
objects: {
|
||||
objects: {
|
||||
recipient: User.find(2),
|
||||
},
|
||||
main_object: ticket.find(123), # optional
|
||||
references: ['message-id123', 'message-id456'],
|
||||
)
|
||||
|
||||
=end
|
||||
|
@ -149,11 +153,17 @@ module NotificationFactory
|
|||
objects: data[:objects],
|
||||
)
|
||||
|
||||
# rebuild subject
|
||||
if data[:main_object] && data[:main_object].respond_to?(:subject_build)
|
||||
result[:subject] = data[:main_object].subject_build(result[:subject])
|
||||
end
|
||||
|
||||
NotificationFactory.send(
|
||||
recipient: data[:user],
|
||||
subject: result[:subject],
|
||||
body: result[:body],
|
||||
content_type: 'text/html',
|
||||
references: data[:references],
|
||||
)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue