idecnode/pkg/model/message.go

56 lines
978 B
Go
Raw Normal View History

2024-10-20 03:39:07 +03:00
package model
import (
"fmt"
"strconv"
"strings"
"time"
)
type Message struct {
2024-10-29 01:21:05 +03:00
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"`
2024-10-20 03:39:07 +03:00
}
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")
}