-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GCAL] today/tomorrow commands with styling #273
Changes from 9 commits
3bc5846
92a91c1
6273977
002786c
ed9d16b
70c7917
18c6e37
c738f90
a35e3de
64e22f5
cfe4ba3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,11 @@ import ( | |
"fmt" | ||
"net/url" | ||
"sort" | ||
"strings" | ||
"time" | ||
|
||
"github.com/mattermost/mattermost-server/v6/model" | ||
|
||
"github.com/mattermost/mattermost-plugin-mscalendar/server/remote" | ||
) | ||
|
||
|
@@ -41,9 +44,48 @@ func RenderCalendarView(events []*remote.Event, timeZone string) (string, error) | |
return resp, nil | ||
} | ||
|
||
func RenderDaySummary(events []*remote.Event, timezone string) (string, []*model.SlackAttachment, error) { | ||
if len(events) == 0 { | ||
return "You have no events for that day", nil, nil | ||
} | ||
|
||
if timezone != "" { | ||
for _, e := range events { | ||
e.Start = e.Start.In(timezone) | ||
e.End = e.End.In(timezone) | ||
} | ||
} | ||
|
||
message := fmt.Sprintf("Agenda for %s.\nTimes are shown in %s", events[0].Start.Time().Format("Monday, 02 January"), events[0].Start.TimeZone) | ||
|
||
var attachments []*model.SlackAttachment | ||
for _, event := range events { | ||
var actions []*model.PostAction | ||
|
||
fields := []*model.SlackAttachmentField{} | ||
if event.Location != nil && event.Location.DisplayName != "" { | ||
fields = append(fields, &model.SlackAttachmentField{ | ||
Title: "Location", | ||
Value: event.Location.DisplayName, | ||
Short: true, | ||
}) | ||
} | ||
|
||
attachments = append(attachments, &model.SlackAttachment{ | ||
Title: event.Subject, | ||
// Text: event.BodyPreview, | ||
Text: fmt.Sprintf("(%s - %s)", event.Start.In(timezone).Time().Format(time.Kitchen), event.End.In(timezone).Time().Format(time.Kitchen)), | ||
Fields: fields, | ||
Actions: actions, | ||
}) | ||
} | ||
|
||
return message, attachments, nil | ||
} | ||
|
||
func renderTableHeader() string { | ||
return `| Time | Subject | | ||
| :--: | :-- |` | ||
return `| Time | Subject | | | ||
| :-- | :-- | :--` | ||
} | ||
|
||
func renderEvent(event *remote.Event, asRow bool, timeZone string) (string, error) { | ||
|
@@ -52,17 +94,26 @@ func renderEvent(event *remote.Event, asRow bool, timeZone string) (string, erro | |
|
||
format := "(%s - %s) [%s](%s)" | ||
if asRow { | ||
format = "| %s - %s | [%s](%s) |" | ||
format = "| %s - %s | [%s](%s) | %s |" | ||
} | ||
|
||
link, err := url.QueryUnescape(event.Weblink) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
var other string | ||
if event.Location != nil && isKnownMeetingURL(event.Location.DisplayName) { | ||
other = "[Join meeting](" + event.Location.DisplayName + ")" | ||
} | ||
|
||
subject := EnsureSubject(event.Subject) | ||
|
||
return fmt.Sprintf(format, start, end, subject, link), nil | ||
return fmt.Sprintf(format, start, end, subject, link, other), nil | ||
} | ||
|
||
func isKnownMeetingURL(location string) bool { | ||
return strings.Contains(location, "zoom.us/j/") || strings.Contains(location, "discord.gg") || strings.Contains(location, "meet.google.com") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neat 👍 Something comes to mind, that a customer may have other call-related domains, including Mattermost Calls. Maybe have this configurable in some way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I want to integrate calls too, but need to send the SITE_URL over to check the URL to do it properly, so it needs a bit more work. Also, Google sends |
||
} | ||
|
||
func groupEventsByDate(events []*remote.Event) [][]*remote.Event { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we add
(time.Hour*24)*4
here? Also do we need to take into account weekends (maybe that's the intention here)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no no no, I accidentaly commited that. Used to get the output of a specific day for a screenshot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though this begs the question, should we have a special case for weekends? Currently, the daily summary job avoids sending the summary on the weekend, so there is already some convention in the plugin to avoid weekends. Maybe the
tomorrow
command should do something similar?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't check that code, is it configurable? Does it take into consideration countries were weekends are longer/shorter/on different days?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the line that does this
mattermost-plugin-mscalendar/server/mscalendar/daily_summary.go
Line 270 in f226b5e
It's currently not configurable, but we can use
WorkingHours
to figure out the correct days if available for gcal:mattermost-plugin-mscalendar/server/remote/user.go
Lines 13 to 25 in 65b2e67