diff options
Diffstat (limited to 'pkg/model/message.go')
-rw-r--r-- | pkg/model/message.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/pkg/model/message.go b/pkg/model/message.go new file mode 100644 index 0000000..3d15c46 --- /dev/null +++ b/pkg/model/message.go @@ -0,0 +1,55 @@ +package model + +import ( + "fmt" + "strconv" + "strings" + "time" +) + +type Message struct { + ID string + RepTo string + EchoArea string + Date time.Time + From string + Addr string + MsgTo string + Subject string + Message string +} + +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") +} |