This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
thrempp/component/send.go

36 lines
719 B
Go

package component
import (
"github.com/bdlm/log"
"gosrc.io/xmpp"
)
func (c *Config) sender(packets chan xmpp.Packet) {
for packet := range packets {
if p := c.send(packet); p != nil {
c.xmpp.Send(p)
}
}
}
func (c *Config) send(packet xmpp.Packet) xmpp.Packet {
logger := log.WithField("type", c.Type)
switch p := packet.(type) {
case xmpp.Message:
if p.PacketAttrs.From == "" {
p.PacketAttrs.From = c.Host
} else {
p.PacketAttrs.From += "@" + c.Host
}
logger.WithFields(map[string]interface{}{
"from": p.PacketAttrs.From,
"to": p.PacketAttrs.To,
"id": p.PacketAttrs.Id,
}).Debug(p.XMPPFormat())
return p
default:
log.Warn("ignoring packet:", packet)
return nil
}
}