liquid_feedback_frontend
diff model/initiative_for_notification.lua @ 1252:659e3eda2fad
Minor fixes to new notification system
author | bsw |
---|---|
date | Sun Apr 17 16:02:26 2016 +0200 (2016-04-17) |
parents | 84f6e17c7ceb |
children | ae8e1dbb8de9 |
line diff
1.1 --- a/model/initiative_for_notification.lua Sun Apr 17 15:04:07 2016 +0200 1.2 +++ b/model/initiative_for_notification.lua Sun Apr 17 16:02:26 2016 +0200 1.3 @@ -15,14 +15,9 @@ 1.4 db:query("BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ") 1.5 1.6 local member = Member:by_id(member_id) 1.7 + 1.8 locale.set{ lang = member.lang or config.default_lang } 1.9 1.10 - io.stderr:write("Sending digest #" .. member.notification_counter .. " to " .. member.notify_email .. "\n") 1.11 - 1.12 - if not member.notify_email then 1.13 - return 1.14 - end 1.15 - 1.16 local selector = db:new_selector() 1.17 :add_field("*") 1.18 :from({ "get_initiatives_for_notification(?)", member_id }, "initiative_for_notification") 1.19 @@ -31,14 +26,23 @@ 1.20 :join("member", nil, "member.id = initiative_for_notification.recipient_id") 1.21 :add_order_by("md5(initiative_for_notification.recipient_id || '-' || member.notification_counter || '-' || issue.area_id)") 1.22 :add_order_by("md5(initiative_for_notification.recipient_id || '-' || member.notification_counter || '-' || issue.id)") 1.23 + 1.24 selector._class = self 1.25 1.26 local initiatives_for_notification = selector:exec() 1.27 1.28 - if #initiatives_for_notification < 1 then 1.29 + db:query("COMMIT") 1.30 + 1.31 + if not member.notify_email then 1.32 return 1.33 end 1.34 1.35 + if not #initiatives_for_notification > 0 then 1.36 + return 1.37 + end 1.38 + 1.39 + io.stderr:write("Sending digest #" .. member.notification_counter .. " to " .. member.notify_email .. "\n") 1.40 + 1.41 local initiatives = initiatives_for_notification:load("initiative") 1.42 local issues = initiatives:load("issue") 1.43 issues:load("area") 1.44 @@ -50,6 +54,9 @@ 1.45 local draft_count = 0 1.46 local suggestion_count = 0 1.47 1.48 + local draft_initiative 1.49 + local suggestion_initiative 1.50 + 1.51 local ms = {} 1.52 1.53 for i, entry in ipairs(initiatives_for_notification) do 1.54 @@ -82,25 +89,23 @@ 1.55 local source 1.56 if entry.supported then 1.57 source = _"has my support" 1.58 - local draft_info 1.59 if entry.new_draft then 1.60 - draft_info = _"draft updated" 1.61 + source = source .. ", " .. _"draft updated" 1.62 draft_count = draft_count + 1 1.63 + draft_initiative = initiative 1.64 end 1.65 - if draft_info then 1.66 - source = source .. ", " .. draft_info 1.67 - end 1.68 - local info 1.69 if entry.new_suggestion_count then 1.70 if entry.new_suggestion_count == 1 then 1.71 - info = _"new suggestion added" 1.72 + source = source .. ", " .. _"new suggestion added" 1.73 elseif entry.new_suggestion_count > 1 then 1.74 - info = _("#{count} suggestions added", { count = entry.new_suggestion_count }) 1.75 + source = source .. ", " .. _("#{count} suggestions added", { count = entry.new_suggestion_count }) 1.76 end 1.77 suggestion_count = suggestion_count + entry.new_suggestion_count 1.78 - end 1.79 - if info then 1.80 - source = source .. ", " .. info 1.81 + if suggestion_initiative and suggestion_initiative.id ~= initiative.id then 1.82 + suggestion_initiative = false 1.83 + elseif suggestion_initiative ~= false then 1.84 + suggestion_initiative = initiative 1.85 + end 1.86 end 1.87 elseif entry.featured then 1.88 source = _"featured" 1.89 @@ -122,7 +127,7 @@ 1.90 1.91 if draft_count > 0 then 1.92 if draft_count == 1 then 1.93 - info[#info+1] = _"draft updated for " .. initiatives_for_notification[1].initiative.display_name 1.94 + info[#info+1] = _"draft updated for " .. draft_initiative.display_name 1.95 else 1.96 info[#info+1] = _("drafts of #{draft_count} initiatives updated", { draft_count = draft_count }) 1.97 end 1.98 @@ -130,7 +135,9 @@ 1.99 1.100 if suggestion_count > 0 then 1.101 if suggestion_count == 1 then 1.102 - info[#info+1] = _"new suggestion for " .. initiatives_for_notification[1].initiative.display_name 1.103 + info[#info+1] = _"new suggestion for " .. suggestion_initiative.display_name 1.104 + elseif suggestion_initiative then 1.105 + info[#info+1] = _("#{count} suggestions added for #{initiative}", { count = suggestion_count, suggestion_initiative.display_name }) 1.106 else 1.107 info[#info+1] = _("#{count} suggestions added", { count = suggestion_count }) 1.108 end 1.109 @@ -143,7 +150,6 @@ 1.110 local subject = _("Digest #{id}: #{info}", { 1.111 id = member.notification_counter, info = table.concat(info, ", ") 1.112 }) 1.113 - 1.114 1.115 local template = config.notification_digest_template 1.116 1.117 @@ -162,8 +168,6 @@ 1.118 content = message 1.119 } 1.120 1.121 - db:query("COMMIT") 1.122 - 1.123 end 1.124 1.125 function InitiativeForNotification:notify_next_member()