forked from mattermost/mattermost-plugin-mscalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_meeting_times.go
53 lines (44 loc) · 1.43 KB
/
find_meeting_times.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
// See License for license information.
package command
import (
"fmt"
"strings"
"github.com/firstfoundry/ff-mattermost-plugin-mscalendar/server/remote"
"github.com/firstfoundry/ff-mattermost-plugin-mscalendar/server/utils"
)
func (c *Command) findMeetings(parameters ...string) (string, bool, error) {
meetingParams := &remote.FindMeetingTimesParameters{}
var attendees []remote.Attendee
for a := range parameters {
s := strings.Split(parameters[a], ":")
t, email := s[0], s[1]
attendee := remote.Attendee{
Type: t,
EmailAddress: &remote.EmailAddress{
Address: email,
},
}
attendees = append(attendees, attendee)
}
meetingParams.Attendees = attendees
meetings, err := c.MSCalendar.FindMeetingTimes(c.user(), meetingParams)
if err != nil {
return "", false, err
}
timeZone, _ := c.MSCalendar.GetTimezone(c.user())
resp := ""
for _, m := range meetings.MeetingTimeSuggestions {
if timeZone != "" {
m.MeetingTimeSlot.Start = m.MeetingTimeSlot.Start.In(timeZone)
m.MeetingTimeSlot.End = m.MeetingTimeSlot.End.In(timeZone)
}
resp += utils.JSONBlock(renderMeetingTime(m))
}
return resp, false, nil
}
func renderMeetingTime(m *remote.MeetingTimeSuggestion) string {
start := m.MeetingTimeSlot.Start.PrettyString()
end := m.MeetingTimeSlot.End.PrettyString()
return fmt.Sprintf("%s - %s (%s)", start, end, m.MeetingTimeSlot.Start.TimeZone)
}