2023-06-16 23:35:41 -07:00
|
|
|
package model
|
|
|
|
|
|
2023-06-23 00:32:17 -07:00
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
|
)
|
2023-06-16 23:35:41 -07:00
|
|
|
|
|
|
|
|
type Conversation struct {
|
|
|
|
|
Date time.Time `json:"date"`
|
|
|
|
|
Participants []string `json:"participantDisplayNames"`
|
2023-06-18 13:12:06 -07:00
|
|
|
DisplayName *string `json:"displayName"` // Optional
|
2023-06-16 23:35:41 -07:00
|
|
|
UnreadCount int `json:"unreadCount"`
|
|
|
|
|
LastMessagePreview string `json:"lastMessagePreview"`
|
|
|
|
|
Guid string `json:"guid"`
|
|
|
|
|
}
|
2023-06-23 00:32:17 -07:00
|
|
|
|
|
|
|
|
func (c *Conversation) GetDisplayName() string {
|
|
|
|
|
if c.DisplayName == nil {
|
|
|
|
|
return strings.Join(c.Participants, ",")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return *c.DisplayName
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c Conversation) MarshalZerologObject(e *zerolog.Event) {
|
|
|
|
|
e.Str("guid", c.Guid)
|
|
|
|
|
e.Time("date", c.Date)
|
|
|
|
|
e.Int("unreadCount", c.UnreadCount)
|
|
|
|
|
e.Str("lastMessagePreview", c.LastMessagePreview)
|
|
|
|
|
e.Strs("participants", c.Participants)
|
|
|
|
|
if c.DisplayName != nil {
|
|
|
|
|
e.Str("displayName", *c.DisplayName)
|
|
|
|
|
}
|
|
|
|
|
}
|