summaryrefslogtreecommitdiff
path: root/chat/messages.go
blob: dbcd150498e69aff8a0c42953dc337c560621dd3 (plain)
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
package chat

import (
	"encoding/json"
)

// MsgType describes the purpose of a message
type MsgType int

const (
	MsgChat MsgType = iota // Default
	MsgJoin
	MsgLeave
)

func (mt MsgType) String() string {
	switch mt {
	case MsgChat:
		return "chat"
	case MsgJoin:
		return "join"
	case MsgLeave:
		return "leave"
	}

	return "???"
}

func (mt *MsgType) MarshalJSON() ([]byte, error) {
	return json.Marshal(mt.String())
}

// Message represents a message that can be sent to a buddy. The Text field has no meaning, if Type != MsgChat.
type Message struct {
	Type MsgType `json:"type"`
	User string  `json:"user"`
	Text string  `json:"text,omitempty"`
}