-
Notifications
You must be signed in to change notification settings - Fork 23
/
attendees.go
115 lines (91 loc) · 2.5 KB
/
attendees.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package exchange
import (
"fmt"
"github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/alcionai/corso/src/internal/common/ptr"
)
type attendee struct {
name string
email string
response string
}
// FormatAttendees returns string representation of an attendee
// Return Format: - Name <email@example.com>, Accepted | Declined | Tentative | No Response
func FormatAttendees(event models.Eventable, isHTML bool) string {
var (
failed int
response = event.GetAttendees()
required = make([]attendee, 0)
optional = make([]attendee, 0)
resource = make([]attendee, 0)
)
for _, entry := range response {
if guardCheckForAttendee(entry) {
failed++
continue
}
temp := attendee{
name: ptr.Val(entry.GetEmailAddress().GetName()),
email: ptr.Val(entry.GetEmailAddress().GetAddress()),
response: entry.GetStatus().GetResponse().String(),
}
switch ptr.Val(entry.GetTypeEscaped()) {
case models.REQUIRED_ATTENDEETYPE:
required = append(required, temp)
case models.OPTIONAL_ATTENDEETYPE:
optional = append(optional, temp)
case models.RESOURCE_ATTENDEETYPE:
resource = append(resource, temp)
}
}
req := attendeeListToString(required, "Required", isHTML)
opt := attendeeListToString(optional, "Optional", isHTML)
res := attendeeListToString(resource, "Resource", isHTML)
return req + opt + res
}
func attendeeListToString(attendList []attendee, heading string, isHTML bool) string {
var (
message string
lineBreak string
)
if isHTML {
lineBreak = "<br>"
} else {
lineBreak = "\n"
}
if len(attendList) > 0 {
message = heading + ":" + lineBreak
for _, resource := range attendList {
message += "- " + resource.String(isHTML) + " " + lineBreak
}
message += lineBreak + lineBreak
}
return message
}
func guardCheckForAttendee(attendee models.Attendeeable) bool {
if attendee.GetTypeEscaped() == nil ||
attendee.GetStatus() == nil {
return true
}
if attendee.GetStatus().GetResponse() == nil {
return true
}
if attendee.GetEmailAddress() == nil {
return true
}
if attendee.GetEmailAddress().GetName() == nil ||
attendee.GetEmailAddress().GetAddress() == nil {
return true
}
return false
}
// String function to return struct representation of attendee
func (at *attendee) String(isHTML bool) string {
var contents string
if isHTML {
contents = fmt.Sprintf("%s <%s>, %s", at.name, at.email, at.response)
} else {
contents = fmt.Sprintf("%s <%s>, %s", at.name, at.email, at.response)
}
return contents
}