From a729b33ea970a866fd4caaebf7c25c306035b07b Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 15 May 2018 11:31:50 -0700 Subject: [PATCH] Closes #41. Add option to display user's calendar response status --- gcal/widget.go | 33 ++++++++++++++++++++++++++++++++- opsgenie/widget.go | 4 ++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/gcal/widget.go b/gcal/widget.go index e1476aca..2a1cbc5a 100644 --- a/gcal/widget.go +++ b/gcal/widget.go @@ -79,8 +79,9 @@ func (widget *Widget) contentFrom(events *calendar.Events) string { conflict := widget.conflicts(event, events) str = str + fmt.Sprintf( - "%s [%s]%s[white]\n %s[%s]%s %s[white]\n\n", + "%s %s[%s]%s[white]\n %s[%s]%s %s[white]\n\n", widget.dayDivider(event, prevEvent), + widget.responseIcon(event), widget.titleColor(event), widget.eventSummary(event, conflict), widget.location(event), @@ -193,6 +194,36 @@ func (widget *Widget) location(event *calendar.Event) string { ) } +func (widget *Widget) responseIcon(event *calendar.Event) string { + if false == Config.UBool("wtf.mods.gcal.displayResponseStatus", true) { + return "" + } + + response := "" + + for _, attendee := range event.Attendees { + if attendee.Email == Config.UString("wtf.mods.gcal.email") { + response = attendee.ResponseStatus + break + } + } + + icon := "[gray]" + + switch response { + case "accepted": + icon = icon + "✔︎ " + case "declined": + icon = icon + "✘ " + case "needsAction": + icon = icon + "? " + default: + icon = icon + "" + } + + return icon +} + // until returns the number of hours or days until the event // If the event is in the past, returns nil func (widget *Widget) until(event *calendar.Event) string { diff --git a/opsgenie/widget.go b/opsgenie/widget.go index ecfbee0a..8cba1dd2 100644 --- a/opsgenie/widget.go +++ b/opsgenie/widget.go @@ -53,10 +53,10 @@ func (widget *Widget) Refresh() { func (widget *Widget) contentFrom(onCallResponse *OnCallResponse) string { str := "" - hideEmpty := Config.UBool("wtf.mods.opsgenie.hideEmpty", false) + displayEmpty := Config.UBool("wtf.mods.opsgenie.displayEmpty", true) for _, data := range onCallResponse.OnCallData { - if (len(data.Recipients) == 0) && (hideEmpty == true) { + if (len(data.Recipients) == 0) && (displayEmpty == false) { continue }