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}'"
|
fail "Can't send email, no channel definde for email_address id '#{ticket.group.email_address_id}'"
|
||||||
end
|
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
|
channel = ticket.group.email_address.channel
|
||||||
|
|
||||||
# get linked channel and send
|
# get linked channel and send
|
||||||
|
@ -41,7 +24,7 @@ class Observer::Ticket::Article::CommunicateEmail::BackgroundJob
|
||||||
{
|
{
|
||||||
message_id: record.message_id,
|
message_id: record.message_id,
|
||||||
in_reply_to: record.in_reply_to,
|
in_reply_to: record.in_reply_to,
|
||||||
references: references,
|
references: ticket.get_references([record.message_id]),
|
||||||
from: record.from,
|
from: record.from,
|
||||||
to: record.to,
|
to: record.to,
|
||||||
cc: record.cc,
|
cc: record.cc,
|
||||||
|
|
|
@ -164,7 +164,9 @@ class Observer::Ticket::Notification::BackgroundJob
|
||||||
article: article,
|
article: article,
|
||||||
recipient: user,
|
recipient: user,
|
||||||
changes: changes,
|
changes: changes,
|
||||||
}
|
},
|
||||||
|
references: ticket.get_references,
|
||||||
|
main_object: ticket,
|
||||||
)
|
)
|
||||||
Rails.logger.debug "sent ticket email notifiaction to agent (#{@p[:type]}/#{ticket.id}/#{user.email})"
|
Rails.logger.debug "sent ticket email notifiaction to agent (#{@p[:type]}/#{ticket.id}/#{user.email})"
|
||||||
end
|
end
|
||||||
|
|
|
@ -531,6 +531,42 @@ condition example
|
||||||
[query, bind_params, tables]
|
[query, bind_params, tables]
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def check_generate
|
def check_generate
|
||||||
|
|
|
@ -96,10 +96,11 @@ module NotificationFactory
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
success = NotificationFactory.send(
|
success = NotificationFactory.send(
|
||||||
recipient: User.find(123),
|
recipient: User.find(123),
|
||||||
subject: 'sime subject',
|
subject: 'sime subject',
|
||||||
body: 'some body',
|
body: 'some body',
|
||||||
content_type: '', # optional, e. g. 'text/html'
|
content_type: '', # optional, e. g. 'text/html'
|
||||||
|
references: ['message-id123', 'message-id456'],
|
||||||
)
|
)
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
@ -121,6 +122,7 @@ module NotificationFactory
|
||||||
from: sender,
|
from: sender,
|
||||||
to: data[:recipient][:email],
|
to: data[:recipient][:email],
|
||||||
subject: data[:subject],
|
subject: data[:subject],
|
||||||
|
references: data[:references],
|
||||||
body: data[:body],
|
body: data[:body],
|
||||||
content_type: content_type,
|
content_type: content_type,
|
||||||
},
|
},
|
||||||
|
@ -133,9 +135,11 @@ module NotificationFactory
|
||||||
NotificationFactory.notification(
|
NotificationFactory.notification(
|
||||||
template: 'password_reset',
|
template: 'password_reset',
|
||||||
user: User.find(2),
|
user: User.find(2),
|
||||||
objects: {
|
objects: {
|
||||||
recipient: User.find(2),
|
recipient: User.find(2),
|
||||||
},
|
},
|
||||||
|
main_object: ticket.find(123), # optional
|
||||||
|
references: ['message-id123', 'message-id456'],
|
||||||
)
|
)
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
@ -149,11 +153,17 @@ module NotificationFactory
|
||||||
objects: data[:objects],
|
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(
|
NotificationFactory.send(
|
||||||
recipient: data[:user],
|
recipient: data[:user],
|
||||||
subject: result[:subject],
|
subject: result[:subject],
|
||||||
body: result[:body],
|
body: result[:body],
|
||||||
content_type: 'text/html',
|
content_type: 'text/html',
|
||||||
|
references: data[:references],
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue