From 87cc20c7b5632a4ed488af2ecf9fa7a5a846ee6e Mon Sep 17 00:00:00 2001 From: William Le Date: Wed, 20 Dec 2023 18:19:43 +0800 Subject: [PATCH] feat(placeos/room_booking_approval_alt1): customisable host notification defaults --- .../place/room_booking_approval_alternate.cr | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/place/room_booking_approval_alternate.cr b/drivers/place/room_booking_approval_alternate.cr index 80e163acc3..7af66b8df9 100644 --- a/drivers/place/room_booking_approval_alternate.cr +++ b/drivers/place/room_booking_approval_alternate.cr @@ -6,7 +6,12 @@ class Place::RoomBookingApprovalAltnerative < PlaceOS::Driver generic_name :RoomBookingApproval description %(Room Booking approval for events where the room has not responded) - default_settings({} of String => String) + default_settings({ + notify_host_on_accept: true, + notify_host_on_decline: true, + default_accept_message: "Request accepted", + default_decline_message: "Request not accepted" + }) accessor calendar : Calendar_1 @@ -14,6 +19,11 @@ class Place::RoomBookingApprovalAltnerative < PlaceOS::Driver getter building_id : String { get_building_id.not_nil! } getter systems : Hash(String, Array(String)) { get_systems_list.not_nil! } + @notify_host_on_accept : Bool = true + @notify_host_on_decline : Bool = true + @default_accept_message : String = "Request accepted" + @default_decline_message : String = "Request not accepted" + def on_load on_update end @@ -28,6 +38,12 @@ class Place::RoomBookingApprovalAltnerative < PlaceOS::Driver # The search schedule.every(5.minutes) { find_bookings_for_approval } + + @notify_host_on_accept = setting?(Bool, :notify_host_on_accept) || true + @notify_host_on_decline = setting?(Bool, :notify_host_on_decline) || true + @default_accept_message = setting?(String, :default_accept_message) || "Request accepted" + @default_decline_message = setting?(String, :default_decline_message) || "Request not accepted" + end # Finds the building ID for the current location services object @@ -65,12 +81,12 @@ class Place::RoomBookingApprovalAltnerative < PlaceOS::Driver self[:approval_required] = results end - def accept_event(calendar_id : String, event_id : String, user_id : String? = nil, notify : Bool = false, comment : String? = nil) - calendar.accept_event(calendar_id: calendar_id, event_id: event_id, user_id: user_id, notify: notify, comment: comment) + def accept_event(calendar_id : String, event_id : String, user_id : String? = nil, notify : Bool? = nil, comment : String? = nil) + calendar.accept_event(calendar_id: calendar_id, event_id: event_id, user_id: user_id, notify: notify || @notify_host_on_accept, comment: comment || @default_accept_message) end - def decline_event(calendar_id : String, event_id : String, user_id : String? = nil, notify : Bool = false, comment : String? = nil) - calendar.decline_event(calendar_id: calendar_id, event_id: event_id, user_id: user_id, notify: notify, comment: comment) + def decline_event(calendar_id : String, event_id : String, user_id : String? = nil, notify : Bool? = nil, comment : String? = nil) + calendar.decline_event(calendar_id: calendar_id, event_id: event_id, user_id: user_id, notify: notify || @notify_host_on_decline, comment: comment || @default_decline_message) end private def room_attendee(event : PlaceCalendar::Event)