Skip to content

Commit

Permalink
feat(placeos/room_booking_approval_alt1): customisable host notificat…
Browse files Browse the repository at this point in the history
…ion defaults
  • Loading branch information
w-le committed Dec 20, 2023
1 parent 0a95411 commit 87cc20c
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions drivers/place/room_booking_approval_alternate.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@ 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

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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 87cc20c

Please sign in to comment.