Add 'mock/' from commit '2041d3ce6377da091eca17cf9d8ad176a3024616'
git-subtree-dir: mock git-subtree-mainline:8216d7c706git-subtree-split:2041d3ce63
This commit is contained in:
73
mock/model/conversation.go
Normal file
73
mock/model/conversation.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
type Conversation struct {
|
||||
Date Date `json:"date"`
|
||||
Participants []string `json:"participantDisplayNames"`
|
||||
DisplayName *string `json:"displayName,omitempty"` // Optional
|
||||
UnreadCount int `json:"unreadCount"`
|
||||
LastMessagePreview string `json:"lastMessagePreview"`
|
||||
LastMessage Message `json:"lastMessage"`
|
||||
Guid string `json:"guid"`
|
||||
}
|
||||
|
||||
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", time.Time(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)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Conversation) Equal(o *Conversation) bool {
|
||||
if c.Guid != o.Guid {
|
||||
return false
|
||||
}
|
||||
|
||||
if !c.Date.Equal(o.Date) {
|
||||
return false
|
||||
}
|
||||
|
||||
if c.UnreadCount != o.UnreadCount {
|
||||
return false
|
||||
}
|
||||
|
||||
if c.LastMessagePreview != o.LastMessagePreview {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(c.Participants) != len(o.Participants) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i, p := range c.Participants {
|
||||
if p != o.Participants[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if c.DisplayName != nil && o.DisplayName != nil {
|
||||
if *c.DisplayName != *o.DisplayName {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user