summaryrefslogtreecommitdiff
path: root/pkg/model/message.go
blob: 3753419b4c3c4b52435e7c97c2cf59e9a0783671 (plain) (blame)
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
package model

import (
	"fmt"
	"strconv"
	"strings"
	"time"
)

type Message struct {
	ID       string    `json:"id"`
	RepTo    string    `json:"rep_to"`
	EchoArea string    `json:"echo_area"`
	Date     time.Time `json:"date"`
	From     string    `json:"from"`
	Addr     string    `json:"addr"`
	MsgTo    string    `json:"msg_to"`
	Subject  string    `json:"subject"`
	Message  string    `json:"message"`
}

func (m *Message) Bundle() string {
	tags := "ii/ok"
	if m.RepTo != "" {
		tags = "ii/ok/repto/" + m.RepTo
	}
	lines := []string{
		tags,
		m.EchoArea,
		strconv.Itoa(int(m.Date.Unix())),
		m.From,
		m.Addr,
		string(m.MsgTo),
		m.Subject,
		"",
		m.Message,
	}

	return strings.Join(lines, "\n")
}

func (m *Message) PointMessage() string {
	lines := []string{
		m.EchoArea,
		string(m.MsgTo),
		m.Subject,
		"",
	}
	if m.RepTo != "" {
		lines = append(lines, fmt.Sprintf("@repto:%s", m.RepTo))
	}
	lines = append(lines, m.Message)

	return strings.Join(lines, "\n")
}