From f066e785f9b445a5d59d4f72eca22659023fd907 Mon Sep 17 00:00:00 2001
From: Teal <git@teal.is>
Date: Sat, 25 May 2024 22:19:32 +0200
Subject: [PATCH] add html description to ical feed

---
 app/controllers/assignments_controller.rb |  3 ++-
 app/models/session.rb                     | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/app/controllers/assignments_controller.rb b/app/controllers/assignments_controller.rb
index e0ff578..78e5178 100644
--- a/app/controllers/assignments_controller.rb
+++ b/app/controllers/assignments_controller.rb
@@ -61,11 +61,12 @@ class AssignmentsController < ApplicationController
           event.dtstart = Icalendar::Values::DateTime.new(session.starts_at, tzid: session.starts_at.zone)
           event.dtend = Icalendar::Values::DateTime.new(session.ends_at, tzid: session.ends_at.zone)
           event.summary = session.title
-          event.description = session.description
+          event.description = helpers.strip_tags(session.description)
           event.location = [session.stage.name, session.conference.name].join(' @ ')
           event.created = Icalendar::Values::DateTime.new(session.created_at)
           event.last_modified = Icalendar::Values::DateTime.new(session.updated_at)
           event.uid = [session.conference.slug, session.ref_id].join('-')
+          event.append_custom_property("X-ALT-DESC;FMTTYPE=text/html", session.description) 
           calendar.add_event(event)
         end
 
diff --git a/app/models/session.rb b/app/models/session.rb
index 1a757bd..ffe1ab5 100644
--- a/app/models/session.rb
+++ b/app/models/session.rb
@@ -6,6 +6,8 @@ class Session < ApplicationRecord
 
   validates :ref_id, uniqueness: { scope: :conference_id }
 
+  after_update :notify_if_changed
+
   def to_param
     ref_id
   end
@@ -17,4 +19,12 @@ class Session < ApplicationRecord
   def ends_at
     super.in_time_zone(conference.time_zone)
   end
+
+  private
+
+  def notify_if_changed
+    if saved_changes.present?
+      ActiveSupport::Notifications.instrument("republica.import.session.updated", record: self, changes: saved_changes)
+    end
+  end
 end
-- 
GitLab