bsw@286: function send_notification(event)
bsw@286:
bsw@286: local url
bsw@286:
bsw@286: local body = ""
bsw@286:
bsw@286: body = body .. _(" Unit: #{name}\n", { name = event.issue.area.unit.name })
bsw@286: body = body .. _(" Area: #{name}\n", { name = event.issue.area.name })
bsw@286: body = body .. _(" Issue: ##{id}\n", { id = event.issue_id })
bsw@286: body = body .. _(" Policy: #{phase}\n", { phase = event.issue.policy.name })
bsw@286: body = body .. _(" Phase: #{phase}\n\n", { phase = event.state })
bsw@286: body = body .. _(" Event: #{event}\n\n", { event = event.event })
bsw@286:
bsw@286: if event.initiative_id then
bsw@286: url = request.get_absolute_baseurl() .. "initiative/show/" .. event.initiative_id .. ".html"
bsw@286: elseif event.suggestion_id then
bsw@286: url = request.get_absolute_baseurl() .. "suggestion/show/" .. event.suggestion_id .. ".html"
bsw@286: else
bsw@286: url = request.get_absolute_baseurl() .. "issue/show/" .. event.issue_id .. ".html"
bsw@286: end
bsw@286:
bsw@286: body = body .. _(" URL: #{url}\n\n", { url = url })
bsw@286:
bsw@286: if event.initiative_id then
bsw@286: local initiative = Initiative:by_id(event.initiative_id)
bsw@286: body = body .. _("i#{id}: #{name}\n\n", { id = initiative.id, name = initiative.name })
bsw@286: else
bsw@286: local initiative_count = Initiative:new_selector()
bsw@286: :add_where{ "initiative.issue_id = ?", event.issue_id }
bsw@286: :count()
bsw@286: local initiatives = Initiative:new_selector()
bsw@286: :add_where{ "initiative.issue_id = ?", event.issue_id }
bsw@286: :add_order_by("initiative.supporter_count DESC")
bsw@286: :limit(3)
bsw@286: :exec()
bsw@286: for i, initiative in ipairs(initiatives) do
bsw@286: body = body .. _("i#{id}: #{name}\n", { id = initiative.id, name = initiative.name })
bsw@286: end
bsw@286: if initiative_count - 3 > 0 then
bsw@286: body = body .. _("and #{count} more initiatives\n", { count = initiative_count })
bsw@286: end
bsw@286: body = body .. "\n"
bsw@286: end
bsw@286:
bsw@286: if event.suggestion_id then
bsw@286: local suggestion = Suggestion:by_id(event.suggestion_id)
bsw@286: body = body .. _("#{name}\n\n", { name = suggestion.name })
bsw@286: end
bsw@286:
bsw@286: slot.put("
", encode.html_newlines(body), "
")
bsw@286: slot.put("
")
bsw@286: end
bsw@286:
bsw@286:
bsw@286:
bsw@286: slot.put_into("title", _"Notification settings")
bsw@286:
bsw@286: slot.select("actions", function()
bsw@286: ui.link{
bsw@286: content = function()
bsw@286: ui.image{ static = "icons/16/cancel.png" }
bsw@286: slot.put(_"Cancel")
bsw@286: end,
bsw@286: module = "member",
bsw@286: view = "settings"
bsw@286: }
bsw@286: end)
bsw@286:
bsw@286:
bsw@286: util.help("member.settings.notification", _"Notification settings")
bsw@286:
bsw@286: ui.form{
bsw@286: attr = { class = "vertical" },
bsw@286: module = "member",
bsw@286: action = "update_notification",
bsw@286: routing = {
bsw@286: ok = {
bsw@286: mode = "redirect",
bsw@286: module = "index",
bsw@286: view = "index"
bsw@286: }
bsw@286: },
bsw@286: content = function()
bsw@286: ui.tag{ tag = "p", _"Send me notifications about issues in following phases:" }
bsw@286:
bsw@286: ui.container{ content = function()
bsw@286: ui.tag{
bsw@286: tag = "input",
bsw@286: attr = { type = "radio", name = "notification_level", value = "voting" }
bsw@286: }
bsw@286: ui.tag{ content = _"Voting phase" }
bsw@286: ui.tag{ tag = "ul", content = function()
bsw@286: ui.tag{ tag = "li", content = _"Voting of an issue in one of my areas or I'm interested in starts" }
bsw@286: end }
bsw@286: end }
bsw@286:
bsw@286: ui.container{ content = function()
bsw@286: ui.tag{
bsw@286: tag = "input",
bsw@286: attr = { type = "radio", name = "notification_level", value = "frozen" }
bsw@286: }
bsw@286: ui.tag{ content = _"Frozen and voting phase" }
bsw@286: ui.tag{ tag = "ul", content = function()
bsw@286: ui.tag{ tag = "li", content = _"An issue in one of my areas or I'm interested in enters phase 'frozen'" }
bsw@286: ui.tag{ tag = "li", content = _"A new initiative is created in an issue I'm interested in" }
bsw@286: ui.tag{ tag = "li", content = _"Voting of an issue in one of my areas or I'm interested in starts" }
bsw@286: end }
bsw@286: end }
bsw@286:
bsw@286: ui.container{ content = function()
bsw@286: ui.tag{
bsw@286: tag = "input",
bsw@286: attr = { type = "radio", name = "notification_level", value = "discussion" }
bsw@286: }
bsw@286: ui.tag{ content = _"Discussion, frozen and voting phase" }
bsw@286: ui.tag{ tag = "ul", content = function()
bsw@286: ui.tag{ tag = "li", content = _"An issue in one of my areas or I'm interested in enters phase 'discussion'" }
bsw@286: ui.tag{ tag = "li", content = _"A new initiative is created in an issue I'm interested in" }
bsw@286: ui.tag{ tag = "li", content = _"The draft of an initiative I'm supporting is updated" }
bsw@286: ui.tag{ tag = "li", content = _"An initiative I was supporting is revoked" }
bsw@286: ui.tag{ tag = "li", content = _"A new suggestion is created in an initiative I'm supporting" }
bsw@286: ui.tag{ tag = "li", content = _"An issue in one of my areas or I'm interested in enters phase 'frozen'" }
bsw@286: ui.tag{ tag = "li", content = _"Voting of an issue in one of my areas or I'm interested in starts" }
bsw@286: end }
bsw@286: end }
bsw@286:
bsw@286: ui.container{ content = function()
bsw@286: ui.tag{
bsw@286: tag = "input",
bsw@286: attr = { type = "radio", name = "notification_level", value = "any" }
bsw@286: }
bsw@286: ui.tag{ content = _"Any phase" }
bsw@286: ui.tag{ tag = "ul", content = function()
bsw@286: ui.tag{ tag = "li", content = _"A new issue is created in one of my areas" }
bsw@286: ui.tag{ tag = "li", content = _"An issue in one of my areas or i'm interested in enters phase 'discussion'" }
bsw@286: ui.tag{ tag = "li", content = _"A new initiative is created in an issue I'm interested in" }
bsw@286: ui.tag{ tag = "li", content = _"The draft of an initiative I'm supporting is updated" }
bsw@286: ui.tag{ tag = "li", content = _"An initiative I was supporting is revoked" }
bsw@286: ui.tag{ tag = "li", content = _"A new suggestion is created in an initiative I'm supporting" }
bsw@286: ui.tag{ tag = "li", content = _"An issue in one of my areas or I'm interested in enters phase 'frozen'" }
bsw@286: ui.tag{ tag = "li", content = _"Voting of an issue in one of my areas or I'm interested in starts" }
bsw@286: end }
bsw@286: end }
bsw@286:
bsw@286: ui.container{ content = function()
bsw@286: ui.tag{
bsw@286: tag = "input",
bsw@286: attr = { type = "radio", name = "notification_level", value = "none" }
bsw@286: }
bsw@286: ui.tag{ content = _"No notifications at all" }
bsw@286: end }
bsw@286:
bsw@286:
bsw@286:
bsw@286: ui.submit{ value = _"Change display settings" }
bsw@286: end
bsw@286: }
bsw@286:
bsw@286: local last_id = 6000;
bsw@286:
bsw@286: while last_id < 6050 do
bsw@286:
bsw@286: local event = Event:new_selector()
bsw@286: :add_where{ "event.id > ?", last_id }
bsw@286: :add_order_by("event.id")
bsw@286: :limit(1)
bsw@286: :optional_object_mode()
bsw@286: :exec()
bsw@286:
bsw@286: last_id = nil
bsw@286: if event then
bsw@286: last_id = event.id
bsw@286: local members_to_notify = Member:new_selector()
bsw@286: :join("event_seen_by_member", nil, { "event_seen_by_member.seen_by_member_id = member.id AND event_seen_by_member.notify_level <= member.notify_level AND event_seen_by_member.id = ?", event.id } )
bsw@286: :add_where("member.activated NOTNULL AND member.notify_email NOTNULL")
bsw@286: :exec()
bsw@286: ui.container{ content = _("Event #{id} -> #{num} members", { id = event.id, num = #members_to_notify }) }
bsw@286:
bsw@286: send_notification(event)
bsw@286:
bsw@286: end
bsw@286: end
bsw@286:
bsw@286:
bsw@286: -- select event.id, event.occurrence, membership.member_id NOTNULL as membership, interest.member_id NOTNULL as interest, supporter.member_id NOTNULL as supporter, event.event, event.state, issue.id, initiative.name FROM event JOIN issue ON issue.id = event.issue_id LEFT JOIN membership ON membership.area_id = issue.area_id AND membership.member_id = 41 LEFT JOIN interest ON interest.issue_id = issue.id AND interest.member_id = 41 LEFT JOIN initiative ON initiative.id = event.initiative_id LEFT JOIN supporter ON supporter.initiative_id = initiative.id AND supporter.member_id = 41 WHERE (((event.event = 'issue_state_changed' OR event.event = 'initiative_created_in_new_issue') AND membership.member_id NOTNULL OR interest.member_id NOTNULL) OR (event.event = 'initiative_created_in_existing_issue' AND interest.member_id NOTNULL) OR ((event.event = 'initiative_revoked' OR event.event = 'new_draft_created' OR event.event = 'suggestion_created') AND supporter.member_id NOTNULL)) AND event.id > 7000 ORDER by event.id ASC LIMIT 1;