aboutsummaryrefslogtreecommitdiff
path: root/xmpp
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2023-03-05 11:00:53 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2023-03-05 11:00:53 +0300
commit4a5b83dff5c568871d5624202e2ee27e5d0de242 (patch)
tree05360ccd21770b830c29ebaacf6ef00787ad1a68 /xmpp
parent6e32c62f8dac5ccc97dd0a6067965ba2689f3c86 (diff)
Show XEP-0461 replies from Telegram
Diffstat (limited to 'xmpp')
-rw-r--r--xmpp/extensions/extensions.go18
-rw-r--r--xmpp/gateway/gateway.go31
-rw-r--r--xmpp/handlers.go2
3 files changed, 45 insertions, 6 deletions
diff --git a/xmpp/extensions/extensions.go b/xmpp/extensions/extensions.go
index fac5e7b..ce27656 100644
--- a/xmpp/extensions/extensions.go
+++ b/xmpp/extensions/extensions.go
@@ -111,6 +111,13 @@ type IqVcardDesc struct {
Text string `xml:",chardata"`
}
+// Reply is from XEP-0461
+type Reply struct {
+ XMLName xml.Name `xml:"urn:xmpp:reply:0 reply"`
+ To string `xml:"to,attr"`
+ Id string `xml:"id,attr"`
+}
+
// Namespace is a namespace!
func (c PresenceNickExtension) Namespace() string {
return c.XMLName.Space
@@ -131,6 +138,11 @@ func (c IqVcardTemp) GetSet() *stanza.ResultSet {
return c.ResultSet
}
+// Namespace is a namespace!
+func (c Reply) Namespace() string {
+ return c.XMLName.Space
+}
+
func init() {
// presence nick
stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{
@@ -149,4 +161,10 @@ func init() {
"vcard-temp",
"vCard",
}, IqVcardTemp{})
+
+ // reply
+ stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
+ "urn:xmpp:reply:0",
+ "reply",
+ }, Reply{})
}
diff --git a/xmpp/gateway/gateway.go b/xmpp/gateway/gateway.go
index daa8f8a..d309ade 100644
--- a/xmpp/gateway/gateway.go
+++ b/xmpp/gateway/gateway.go
@@ -13,6 +13,11 @@ import (
"gosrc.io/xmpp/stanza"
)
+type Reply struct {
+ Author string
+ Id string
+}
+
const NSNick string = "http://jabber.org/protocol/nick"
// Queue stores presences to send later
@@ -27,16 +32,26 @@ var Jid *stanza.Jid
var DirtySessions = false
// SendMessage creates and sends a message stanza
-func SendMessage(to string, from string, body string, id string, component *xmpp.Component) {
- sendMessageWrapper(to, from, body, id, component, "")
+func SendMessage(to string, from string, body string, id string, component *xmpp.Component, reply *Reply) {
+ sendMessageWrapper(to, from, body, id, component, reply, "")
+}
+
+// SendServiceMessage creates and sends a simple message stanza from transport
+func SendServiceMessage(to string, body string, component *xmpp.Component) {
+ sendMessageWrapper(to, "", body, "", component, nil, "")
+}
+
+// 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, "")
}
// SendMessageWithOOB creates and sends a message stanza with OOB URL
-func SendMessageWithOOB(to string, from string, body string, id string, component *xmpp.Component, oob string) {
- sendMessageWrapper(to, from, body, id, component, oob)
+func SendMessageWithOOB(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string) {
+ sendMessageWrapper(to, from, body, id, component, reply, oob)
}
-func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, oob string) {
+func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string) {
componentJid := Jid.Full()
var logFrom string
@@ -69,6 +84,12 @@ func sendMessageWrapper(to string, from string, body string, id string, componen
URL: oob,
})
}
+ if reply != nil {
+ message.Extensions = append(message.Extensions, extensions.Reply{
+ To: reply.Author,
+ Id: reply.Id,
+ })
+ }
sendMessage(&message, component)
}
diff --git a/xmpp/handlers.go b/xmpp/handlers.go
index d83fef4..b023bc5 100644
--- a/xmpp/handlers.go
+++ b/xmpp/handlers.go
@@ -106,7 +106,7 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
if err == nil && toJid.Bare() == gatewayJid && (strings.HasPrefix(msg.Body, "/") || strings.HasPrefix(msg.Body, "!")) {
response := session.ProcessTransportCommand(msg.Body, resource)
if response != "" {
- gateway.SendMessage(msg.From, "", response, "", component)
+ gateway.SendServiceMessage(msg.From, response, component)
}
return
}