all repos — underbbs @ 2976d438d90bea2beb4e67272fd628ff163459f2

decentralized social media client

models/msg.go (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package models

import (
	"encoding/json"
)

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"`
	Created int64 `json:"created"`
	Updated *int64 `json:"updated,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"`
	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"`
	Created   int64 `json:"created"`
	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
}