|
|
|
@ -23,6 +23,17 @@ type Reply struct {
|
|
|
|
|
End uint64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MarkerType byte
|
|
|
|
|
const (
|
|
|
|
|
MarkerTypeReceived MarkerType = iota
|
|
|
|
|
MarkerTypeDisplayed
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type marker struct {
|
|
|
|
|
Type MarkerType
|
|
|
|
|
Id string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NSNick string = "http://jabber.org/protocol/nick"
|
|
|
|
|
|
|
|
|
|
// Queue stores presences to send later
|
|
|
|
@ -44,25 +55,33 @@ var MessageOutgoingPermissionVersion = 0
|
|
|
|
|
|
|
|
|
|
// SendMessage creates and sends a message stanza
|
|
|
|
|
func SendMessage(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, isCarbon bool) {
|
|
|
|
|
sendMessageWrapper(to, from, body, id, component, reply, "", isCarbon)
|
|
|
|
|
sendMessageWrapper(to, from, body, id, component, reply, nil, "", isCarbon)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SendServiceMessage creates and sends a simple message stanza from transport
|
|
|
|
|
func SendServiceMessage(to string, body string, component *xmpp.Component) {
|
|
|
|
|
sendMessageWrapper(to, "", body, "", component, nil, "", false)
|
|
|
|
|
sendMessageWrapper(to, "", body, "", component, nil, nil, "", false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SendTextMessage creates and sends a simple message stanza
|
|
|
|
|
func SendTextMessage(to string, from string, body string, component *xmpp.Component) {
|
|
|
|
|
sendMessageWrapper(to, from, body, "", component, nil, "", false)
|
|
|
|
|
sendMessageWrapper(to, from, body, "", component, nil, nil, "", false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SendMessageWithOOB creates and sends a message stanza with OOB URL
|
|
|
|
|
func SendMessageWithOOB(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isCarbon bool) {
|
|
|
|
|
sendMessageWrapper(to, from, body, id, component, reply, oob, isCarbon)
|
|
|
|
|
sendMessageWrapper(to, from, body, id, component, reply, nil, oob, isCarbon)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isCarbon bool) {
|
|
|
|
|
// SendMessageMarker creates and sends a message stanza with a XEP-0333 marker
|
|
|
|
|
func SendMessageMarker(to string, from string, component *xmpp.Component, markerType MarkerType, markerId string) {
|
|
|
|
|
sendMessageWrapper(to, from, "", "", component, nil, &marker{
|
|
|
|
|
Type: markerType,
|
|
|
|
|
Id: markerId,
|
|
|
|
|
}, "", false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, marker *marker, oob string, isCarbon bool) {
|
|
|
|
|
toJid, err := stanza.NewJid(to)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.WithFields(log.Fields{
|
|
|
|
@ -120,6 +139,13 @@ func sendMessageWrapper(to string, from string, body string, id string, componen
|
|
|
|
|
message.Extensions = append(message.Extensions, extensions.NewReplyFallback(reply.Start, reply.End))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if marker != nil {
|
|
|
|
|
if marker.Type == MarkerTypeReceived {
|
|
|
|
|
message.Extensions = append(message.Extensions, stanza.MarkReceived{ID: marker.Id})
|
|
|
|
|
} else if marker.Type == MarkerTypeDisplayed {
|
|
|
|
|
message.Extensions = append(message.Extensions, stanza.MarkDisplayed{ID: marker.Id})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !isCarbon && toJid.Resource != "" {
|
|
|
|
|
message.Extensions = append(message.Extensions, stanza.HintNoCopy{})
|
|
|
|
|
}
|
|
|
|
|