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

38 lines
753 B
Go
Raw Normal View History

2019-06-01 04:38:35 +02:00
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.sending(packet); p != nil {
2019-06-01 04:38:35 +02:00
c.xmpp.Send(p)
}
}
}
func (c *Config) sending(packet xmpp.Packet) xmpp.Packet {
2019-06-01 04:38:35 +02:00
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
}
2019-06-06 21:20:51 +02:00
if c.XMPPDebug {
2019-06-06 20:53:06 +02:00
logger.WithFields(map[string]interface{}{
"from": p.PacketAttrs.From,
"to": p.PacketAttrs.To,
"id": p.PacketAttrs.Id,
}).Debug(p.XMPPFormat())
}
2019-06-01 04:38:35 +02:00
return p
default:
log.Warn("ignoring packet:", packet)
return nil
}
}