aboutsummaryrefslogtreecommitdiff
path: root/xmpp
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2023-06-27 16:14:35 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2023-06-27 16:14:35 +0300
commitb5920822c4489897248b770cf7e0e4324b84db89 (patch)
treec40afc9f8423d022199b27457e95e170522d6c4d /xmpp
parent739fc4110a9c12aa51cbd6361e5c4398c8ed7ff8 (diff)
Send nick in messages (specially für Sava, but nahuj nado)message-nick
Diffstat (limited to 'xmpp')
-rw-r--r--xmpp/extensions/extensions.go14
-rw-r--r--xmpp/gateway/gateway.go21
2 files changed, 23 insertions, 12 deletions
diff --git a/xmpp/extensions/extensions.go b/xmpp/extensions/extensions.go
index 2d547af..dd90e35 100644
--- a/xmpp/extensions/extensions.go
+++ b/xmpp/extensions/extensions.go
@@ -7,8 +7,8 @@ import (
"gosrc.io/xmpp/stanza"
)
-// PresenceNickExtension is from XEP-0172
-type PresenceNickExtension struct {
+// NickExtension is from XEP-0172
+type NickExtension struct {
XMLName xml.Name `xml:"http://jabber.org/protocol/nick nick"`
Text string `xml:",chardata"`
}
@@ -187,7 +187,7 @@ type Replace struct {
}
// Namespace is a namespace!
-func (c PresenceNickExtension) Namespace() string {
+func (c NickExtension) Namespace() string {
return c.XMLName.Space
}
@@ -259,7 +259,13 @@ func init() {
stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{
"http://jabber.org/protocol/nick",
"nick",
- }, PresenceNickExtension{})
+ }, NickExtension{})
+
+ // message nick
+ stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
+ "http://jabber.org/protocol/nick",
+ "nick",
+ }, NickExtension{})
// presence vcard update
stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{
diff --git a/xmpp/gateway/gateway.go b/xmpp/gateway/gateway.go
index 29c8a07..5761c84 100644
--- a/xmpp/gateway/gateway.go
+++ b/xmpp/gateway/gateway.go
@@ -42,26 +42,26 @@ var DirtySessions = false
var MessageOutgoingPermission = false
// SendMessage creates and sends a message stanza
-func SendMessage(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, isOutgoing bool) {
- sendMessageWrapper(to, from, body, id, component, reply, "", isOutgoing)
+func SendMessage(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, isOutgoing bool, nick string) {
+ sendMessageWrapper(to, from, body, id, component, reply, "", isOutgoing, nick)
}
// 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, "", 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, "", 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, isOutgoing bool) {
- sendMessageWrapper(to, from, body, id, component, reply, oob, isOutgoing)
+func SendMessageWithOOB(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isOutgoing bool, nick string) {
+ sendMessageWrapper(to, from, body, id, component, reply, oob, isOutgoing, nick)
}
-func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isOutgoing bool) {
+func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, oob string, isOutgoing bool, nick string) {
toJid, err := stanza.NewJid(to)
if err != nil {
log.WithFields(log.Fields{
@@ -119,6 +119,11 @@ func sendMessageWrapper(to string, from string, body string, id string, componen
message.Extensions = append(message.Extensions, extensions.NewReplyFallback(reply.Start, reply.End))
}
}
+ if nick != "" {
+ message.Extensions = append(message.Extensions, extensions.NickExtension{
+ Text: nick,
+ })
+ }
if isOutgoing {
carbonMessage := extensions.ClientMessage{
@@ -269,7 +274,7 @@ func newPresence(bareJid string, to string, args ...args.V) stanza.Presence {
if SPNickname.IsSet(args) {
nickname := SPNickname.Get(args)
if nickname != "" {
- presence.Extensions = append(presence.Extensions, extensions.PresenceNickExtension{
+ presence.Extensions = append(presence.Extensions, extensions.NickExtension{
Text: nickname,
})
}