underbbs/models/msg.go

66 lines
1.5 KiB
Go
Raw Normal View History

2024-05-10 04:14:40 +00:00
package models
import (
2024-05-19 20:42:28 +00:00
"encoding/json"
2024-05-10 04:14:40 +00:00
)
2024-06-30 00:18:31 +00:00
type Datagram struct {
2024-07-07 20:54:33 +00:00
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"`
Created int64 `json:"created"`
Updated *int64 `json:"updated,omitempty"`
2024-06-30 00:18:31 +00:00
}
2024-05-10 04:14:40 +00:00
type Message struct {
2024-06-30 00:18:31 +00:00
Datagram
2024-07-07 20:54:33 +00:00
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"`
Visibility string `json:"visibility"`
2024-08-31 17:01:31 +00:00
RenoteId *string `json:"renoteId,omitempty"`
2024-05-10 04:14:40 +00:00
}
type Author struct {
2024-06-30 00:18:31 +00:00
Datagram
2024-07-07 20:54:33 +00:00
Name string `json:"name"`
ProfileData interface{} `json:"profileData"`
2024-07-07 20:54:33 +00:00
ProfilePic string `json:"profilePic"`
Messages []string `json:"messages,omitempty"`
2024-05-10 04:14:40 +00:00
}
type Attachment struct {
Src string `json:"src"`
ThumbSrc string `json:"thumbSrc"`
Desc string `json:"desc"`
Created int64 `json:"created"`
Size uint64 `json:"size"`
2024-05-10 04:14:40 +00:00
}
2024-05-19 20:42:28 +00:00
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
}