|
|
|
@ -44,30 +44,35 @@ var MessageOutgoingPermissionVersion = 0
|
|
|
|
|
|
|
|
|
|
// SendMessage creates and sends a message stanza
|
|
|
|
|
func SendMessage(to, from, body, id string, component *xmpp.Component, reply *Reply, timestamp int64, isCarbon, isGroupchat bool, originalFrom string) {
|
|
|
|
|
sendMessageWrapper(to, from, body, "", id, component, reply, timestamp, "", isCarbon, isGroupchat, false, originalFrom)
|
|
|
|
|
sendMessageWrapper(to, from, body, "", id, component, reply, timestamp, "", isCarbon, isGroupchat, false, originalFrom, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SendServiceMessage creates and sends a simple message stanza from transport
|
|
|
|
|
func SendServiceMessage(to, body string, component *xmpp.Component) {
|
|
|
|
|
sendMessageWrapper(to, "", body, "", "", component, nil, 0, "", false, false, false, "")
|
|
|
|
|
sendMessageWrapper(to, "", body, "", "", component, nil, 0, "", false, false, false, "", 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SendTextMessage creates and sends a simple message stanza
|
|
|
|
|
func SendTextMessage(to, from, body string, component *xmpp.Component) {
|
|
|
|
|
sendMessageWrapper(to, from, body, "", "", component, nil, 0, "", false, false, false, "")
|
|
|
|
|
sendMessageWrapper(to, from, body, "", "", component, nil, 0, "", false, false, false, "", 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SendErrorMessage creates and sends an error message stanza
|
|
|
|
|
func SendErrorMessage(to, from, text string, code int, isGroupchat bool, component *xmpp.Component) {
|
|
|
|
|
sendMessageWrapper(to, from, text, "", "", component, nil, 0, "", false, isGroupchat, false, "", code)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SendMessageWithOOB creates and sends a message stanza with OOB URL
|
|
|
|
|
func SendMessageWithOOB(to, from, body, id string, component *xmpp.Component, reply *Reply, timestamp int64, oob string, isCarbon, isGroupchat bool, originalFrom string) {
|
|
|
|
|
sendMessageWrapper(to, from, body, "", id, component, reply, timestamp, oob, isCarbon, isGroupchat, false, originalFrom)
|
|
|
|
|
sendMessageWrapper(to, from, body, "", id, component, reply, timestamp, oob, isCarbon, isGroupchat, false, originalFrom, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SendSubjectMessage creates and sends a MUC subject
|
|
|
|
|
func SendSubjectMessage(to, from, subject, id string, component *xmpp.Component, timestamp int64) {
|
|
|
|
|
sendMessageWrapper(to, from, "", subject, id, component, nil, timestamp, "", false, true, true, "")
|
|
|
|
|
sendMessageWrapper(to, from, "", subject, id, component, nil, timestamp, "", false, true, true, "", 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func sendMessageWrapper(to, from, body, subject, id string, component *xmpp.Component, reply *Reply, timestamp int64, oob string, isCarbon, isGroupchat, forceSubject bool, originalFrom string) {
|
|
|
|
|
func sendMessageWrapper(to, from, body, subject, id string, component *xmpp.Component, reply *Reply, timestamp int64, oob string, isCarbon, isGroupchat, forceSubject bool, originalFrom string, errorCode int) {
|
|
|
|
|
toJid, err := stanza.NewJid(to)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.WithFields(log.Fields{
|
|
|
|
@ -107,7 +112,9 @@ func sendMessageWrapper(to, from, body, subject, id string, component *xmpp.Comp
|
|
|
|
|
}).Warn("Got message")
|
|
|
|
|
|
|
|
|
|
var messageType stanza.StanzaType
|
|
|
|
|
if isGroupchat {
|
|
|
|
|
if errorCode != 0 {
|
|
|
|
|
messageType = stanza.MessageTypeError
|
|
|
|
|
} else if isGroupchat {
|
|
|
|
|
messageType = stanza.MessageTypeGroupchat
|
|
|
|
|
} else {
|
|
|
|
|
messageType = stanza.MessageTypeChat
|
|
|
|
@ -121,7 +128,29 @@ func sendMessageWrapper(to, from, body, subject, id string, component *xmpp.Comp
|
|
|
|
|
Id: id,
|
|
|
|
|
},
|
|
|
|
|
Subject: subject,
|
|
|
|
|
Body: body,
|
|
|
|
|
}
|
|
|
|
|
if errorCode == 0 {
|
|
|
|
|
message.Body = body
|
|
|
|
|
} else {
|
|
|
|
|
message.Error = stanza.Err{
|
|
|
|
|
Code: errorCode,
|
|
|
|
|
Text: body,
|
|
|
|
|
}
|
|
|
|
|
switch errorCode {
|
|
|
|
|
case 400:
|
|
|
|
|
message.Error.Type = stanza.ErrorTypeModify
|
|
|
|
|
message.Error.Reason = "bad-request"
|
|
|
|
|
case 404:
|
|
|
|
|
message.Error.Type = stanza.ErrorTypeCancel
|
|
|
|
|
message.Error.Reason = "item-not-found"
|
|
|
|
|
case 500:
|
|
|
|
|
message.Error.Type = stanza.ErrorTypeWait
|
|
|
|
|
message.Error.Reason = "internal-server-error"
|
|
|
|
|
default:
|
|
|
|
|
log.Error("Unknown error code, falling back with empty reason")
|
|
|
|
|
message.Error.Type = stanza.ErrorTypeCancel
|
|
|
|
|
message.Error.Reason = "undefined-condition"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if oob != "" {
|
|
|
|
|