mirror of
https://salsa.debian.org/mdosch/go-sendxmpp
synced 2024-11-12 13:10:25 +00:00
Move handrafting OOB messages in own function.
This commit is contained in:
parent
c0d7514674
commit
828ba165e9
@ -158,12 +158,26 @@ func readMessage(messageFilePath string) (string, error) {
|
||||
return output, err
|
||||
}
|
||||
|
||||
func oobMessage(recipient string, sender string, messageType string, url string) string {
|
||||
orgMessage := "<message to='" + recipient + "' from='" + sender
|
||||
if messageType == "groupchat" {
|
||||
orgMessage = orgMessage + "' type='groupchat' "
|
||||
}
|
||||
if messageType == "chat" {
|
||||
orgMessage = orgMessage + "' type='chat' "
|
||||
}
|
||||
orgMessage = orgMessage + "id ='" + getID() + "' xml:lang='en'><body>" + url +
|
||||
"</body><x xmlns='jabber:x:oob'><url>" + url + "</url></x></message>"
|
||||
println("OrgMessage: ", orgMessage)
|
||||
|
||||
return orgMessage
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
var (
|
||||
err error
|
||||
message, user, server, password, orgMessageStart string
|
||||
orgChatMessageEnd, orgGroupMessageEnd string
|
||||
err error
|
||||
message, user, server, password string
|
||||
)
|
||||
|
||||
// Define command line flags.
|
||||
@ -290,13 +304,6 @@ func main() {
|
||||
if *flagHttpUpload != "" {
|
||||
message = httpUpload(client, tlsConfig.ServerName,
|
||||
*flagHttpUpload)
|
||||
orgMessageStart = "<message to='"
|
||||
orgGroupMessageEnd = "' from ='" + client.JID() + "' type='groupchat' " +
|
||||
"xml:lang='en'><body>" + message + "</body><x xmlns='jabber:x:oob'>" +
|
||||
"<url>" + message + "</url></x></message>"
|
||||
orgChatMessageEnd = "' from ='" + client.JID() + "' type='chat' xml:lang='en'>" +
|
||||
"<body>" + message + "</body><x xmlns='jabber:x:oob'><url>" +
|
||||
message + "</url></x></message>"
|
||||
}
|
||||
|
||||
// Skip reading message if '-i' or '--interactive' is set to work with e.g. 'tail -f'.
|
||||
@ -359,8 +366,8 @@ func main() {
|
||||
// Send the message.
|
||||
for _, recipient := range recipients {
|
||||
if *flagHttpUpload != "" {
|
||||
_, err = client.SendOrg(orgMessageStart + recipient +
|
||||
orgGroupMessageEnd)
|
||||
_, err = client.SendOrg(oobMessage(recipient, client.JID(),
|
||||
"groupchat", message))
|
||||
} else {
|
||||
_, err = client.Send(xmpp.Chat{Remote: recipient,
|
||||
Type: "groupchat", Text: message})
|
||||
@ -404,8 +411,8 @@ func main() {
|
||||
} else {
|
||||
for _, recipient := range recipients {
|
||||
if *flagHttpUpload != "" {
|
||||
_, err = client.SendOrg(orgMessageStart + recipient +
|
||||
orgChatMessageEnd)
|
||||
_, err = client.SendOrg(oobMessage(recipient, client.JID(),
|
||||
"chat", message))
|
||||
} else {
|
||||
_, err = client.Send(xmpp.Chat{Remote: recipient, Type: "chat",
|
||||
Text: message})
|
||||
|
Loading…
Reference in New Issue
Block a user