underbbs/models/msg.go

65 lines
1.5 KiB
Go

package models
import (
"encoding/json"
"time"
)
type Datagram struct {
Id string `json:"id"`
Uri string `json:"uri"`
Protocol string `json:"protocol"`
Adapter string `json:"adapter"`
Type string `json:"type"`
Target *string `json:"target,omitempty"`
}
type Message struct {
Datagram
Author string `json:"author"`
Content string `json:"content"`
Attachments []Attachment `json:"attachments"`
ReplyTo *string `json:"replyTo"`
Replies []string `json:"replies"`
ReplyCount int `json:"replyCount"`
Mentions []string `json:"mentions"`
Created time.Time `json:"created"`
Edited *time.Time `json:"edited,omitempty"`
Visibility string `json:"visibility"`
}
type Author struct {
Datagram
Name string `json:"name"`
ProfileData interface{} `json:"profileData"`
ProfilePic string `json:"profilePic"`
Messages []string `json:"messages,omitempty"`
}
type Attachment struct {
Src string `json:"src"`
ThumbSrc string `json:"thumbSrc"`
Desc string `json:"desc"`
CreatedAt time.Time `json:"createdAt"`
Size uint64 `json:"size"`
}
type SocketData interface {
ToDatagram() []byte
}
func (self Message) ToDatagram() []byte {
data, err := json.Marshal(self)
if err != nil {
panic(err.Error())
}
return data
}
func (self Author) ToDatagram() []byte {
data, err := json.Marshal(self)
if err != nil {
panic(err.Error())
}
return data
}