44 lines
902 B
Go
44 lines
902 B
Go
package internal
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type ChannelMessage struct {
|
|
ID int
|
|
Message string
|
|
Medias []ChannelMessageMedia
|
|
PublishAt time.Time
|
|
}
|
|
|
|
type ChannelMessageMedia struct {
|
|
Photo string
|
|
Video string
|
|
}
|
|
|
|
func NewChannelMessage(id, ts int) *ChannelMessage {
|
|
return &ChannelMessage{ID: id, PublishAt: time.Unix(int64(ts), 0)}
|
|
}
|
|
|
|
func (c *ChannelMessage) WithMessage(message string) *ChannelMessage {
|
|
c.Message = message
|
|
return c
|
|
}
|
|
|
|
func (c *ChannelMessage) WithPhoto(assetID int64, ext string) *ChannelMessage {
|
|
c.Medias = append(c.Medias, ChannelMessageMedia{Photo: fmt.Sprintf("%d.%s", assetID, ext)})
|
|
return c
|
|
}
|
|
|
|
func (c *ChannelMessage) WithVideo(video string) *ChannelMessage {
|
|
c.Medias = append(c.Medias, ChannelMessageMedia{Video: video})
|
|
return c
|
|
}
|
|
|
|
func (c *ChannelMessage) GetMedia() string {
|
|
b, _ := json.Marshal(c.Medias)
|
|
return string(b)
|
|
}
|