FIX: an image can be shown twice in summary emails

This commit is contained in:
Neil Lalonde 2017-01-09 13:27:27 -05:00
parent 64652f98ab
commit d9146de080
2 changed files with 22 additions and 14 deletions

View File

@ -3,6 +3,7 @@ require_dependency 'email/message_builder'
require_dependency 'age_words' require_dependency 'age_words'
class UserNotifications < ActionMailer::Base class UserNotifications < ActionMailer::Base
include UserNotificationsHelper
helper :application helper :application
default charset: 'UTF-8' default charset: 'UTF-8'
@ -106,6 +107,8 @@ class UserNotifications < ActionMailer::Base
end end
@popular_topics = topics_for_digest[0,SiteSetting.digest_topics] @popular_topics = topics_for_digest[0,SiteSetting.digest_topics]
if @popular_topics.present?
@other_new_for_you = topics_for_digest.size > SiteSetting.digest_topics ? topics_for_digest[SiteSetting.digest_topics..-1] : [] @other_new_for_you = topics_for_digest.size > SiteSetting.digest_topics ? topics_for_digest[SiteSetting.digest_topics..-1] : []
@popular_posts = if SiteSetting.digest_posts > 0 @popular_posts = if SiteSetting.digest_posts > 0
@ -119,7 +122,12 @@ class UserNotifications < ActionMailer::Base
[] []
end end
if @popular_topics.present? @excerpts = {}
@popular_topics.map do |t|
@excerpts[t.first_post.id] = email_excerpt(t.first_post.cooked) if t.first_post.present?
end
# Try to find 3 interesting stats for the top of the digest # Try to find 3 interesting stats for the top of the digest
new_topics_count = Topic.new_since_last_seen(user, min_date).count new_topics_count = Topic.new_since_last_seen(user, min_date).count

View File

@ -149,7 +149,7 @@ body, table, td, th, h1, h2, h3 {font-family: Helvetica, Arial, sans-serif !impo
<p style="color:inherit;font-size:14px;font-weight:400;line-height:1.3;margin:0 0 8px 0;padding:0;word-wrap:normal;"><%= t.user.username -%></p> <p style="color:inherit;font-size:14px;font-weight:400;line-height:1.3;margin:0 0 8px 0;padding:0;word-wrap:normal;"><%= t.user.username -%></p>
<% end %> <% end %>
</td> </td>
<%- if show_image_with_url(t.image_url) && t.featured_link.nil? -%> <%- if show_image_with_url(t.image_url) && t.featured_link.nil? && !(@excerpts[t.first_post&.id]||"").include?(t.image_url) -%>
<td style="margin:0;padding:0 16px 0 8px;text-align:right;" align="right"> <td style="margin:0;padding:0 16px 0 8px;text-align:right;" align="right">
<img src="<%= url_for_email(t.image_url) -%>" height="64" style="margin:auto;max-height:64px;max-width:100%;outline:0;text-align:right;text-decoration:none;"> <img src="<%= url_for_email(t.image_url) -%>" height="64" style="margin:auto;max-height:64px;max-width:100%;outline:0;text-align:right;text-decoration:none;">
</td> </td>
@ -163,7 +163,7 @@ body, table, td, th, h1, h2, h3 {font-family: Helvetica, Arial, sans-serif !impo
<tbody> <tbody>
<tr> <tr>
<td class="post-excerpt" style="color:#0a0a0a;font-size:14px;padding:0 16px 0 16px;text-align:left;width:100%;font-weight:normal;"> <td class="post-excerpt" style="color:#0a0a0a;font-size:14px;padding:0 16px 0 16px;text-align:left;width:100%;font-weight:normal;">
<%= email_excerpt(t.first_post.cooked) %> <%= @excerpts[t.first_post.id] %>
</td> </td>
</tr> </tr>
</tbody> </tbody>