Skip to content
Snippets Groups Projects
Commit 9eb06684 authored by Teal's avatar Teal
Browse files

only notify for relevant stages

parent 2caf3d32
No related branches found
No related tags found
No related merge requests found
......@@ -13,20 +13,22 @@ class TelegramBotSubscriber
def handle_session_updated(event)
Rails.logger.info("session event #{event.inspect}")
model_name, action = event.name.split('.')
record = event.payload[:record]
session = event.payload[:record]
changes = event.payload[:changes]
return unless changes.any? do |attr, (from, to)|
%w[title language status starts_at ends_at stage_id].include? attr
end
return unless session.conference.relevant_stages.include? session.stage || changes["stage_id"].any? { |stage_id| session.conference.relevant_stages.include? Stage.find(stage_id) }
if changes["stage_id"]
changes["stage"] = [Stage.find(changes["stage_id"].first).name, Stage.find(changes["stage_id"].last).name]
changes.delete("stage_id")
end
message = "<b><a href=\"#{conference_session_url(record.conference, record, host: 'rescheduled.c3lingo.org', protocol: 'https')}\">Session #{record.title}</a> #{action}</b>\n" +
changes.map { |attr, (from, to)| "- #{attr}: #{from} -> #{to}" }.join("\n") + "\n#{conference_session_url(record.conference, record)}"
message = "<b><a href=\"#{conference_session_url(session.conference, session, host: 'rescheduled.c3lingo.org', protocol: 'https')}\">Session #{session.title}</a> #{action}</b>\n" +
changes.map { |attr, (from, to)| "- #{attr}: #{from} -> #{to}" }.join("\n") + "\n#{conference_session_url(session.conference, session)}"
TelegramGroupChatNotificationJob.perform_later(target: "-316096320", text: message, parse_mode: 'HTML')
# TelegramGroupChatNotificationJob.perform_later(target: "2192297", text: message, parse_mode: 'HTML')
......@@ -35,11 +37,13 @@ class TelegramBotSubscriber
def handle_session_speaker_event(event)
Rails.logger.info("session_speaker event #{event.inspect}")
model_name, action = event.name.split('.')
record = event.payload[:record]
session = record.session
session_speaker = event.payload[:record]
session = session_speaker.session
return unless session.conference.relevant_stages.include? session.stage
message = "<b><a href=\"#{conference_session_url(session.conference, session, host: 'rescheduled.c3lingo.org', protocol: 'https')}\">Session #{session.title}</a> Speaker Change</b>\n" +
"#{record.speaker.name} #{action == 'destroyed' ? 'removed' : 'added'}" + "\n#{conference_session_url(session.conference, session)}"
"#{session_speaker.speaker.name} #{action == 'destroyed' ? 'removed' : 'added'}" + "\n#{conference_session_url(session.conference, session)}"
TelegramGroupChatNotificationJob.perform_later(target: "-316096320", text: message, parse_mode: 'HTML')
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment