aboutsummaryrefslogtreecommitdiff
path: root/xmpp/gateway/gateway.go
diff options
context:
space:
mode:
authorBohdan Horbeshko <bodqhrohro@gmail.com>2023-09-28 20:14:17 +0300
committerBohdan Horbeshko <bodqhrohro@gmail.com>2023-09-28 20:14:17 +0300
commitcdaaa75c960c949a81114824b7f7b516d962ec68 (patch)
treed1c01e892f8a30cbbfb547c295265b0c3ead97ac /xmpp/gateway/gateway.go
parentb68c07025d1dd077c73ec3b4052ea453612e3e9c (diff)
Send last pinned message as subject on MUC join
Diffstat (limited to 'xmpp/gateway/gateway.go')
-rw-r--r--xmpp/gateway/gateway.go31
1 files changed, 20 insertions, 11 deletions
diff --git a/xmpp/gateway/gateway.go b/xmpp/gateway/gateway.go
index a831db6..89f1eb8 100644
--- a/xmpp/gateway/gateway.go
+++ b/xmpp/gateway/gateway.go
@@ -43,26 +43,31 @@ var DirtySessions = false
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, timestamp int64, isCarbon, isGroupchat bool, originalFrom string) {
- sendMessageWrapper(to, from, body, id, component, reply, timestamp, "", isCarbon, isGroupchat, originalFrom)
+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)
}
// SendServiceMessage creates and sends a simple message stanza from transport
-func SendServiceMessage(to string, body string, component *xmpp.Component) {
- sendMessageWrapper(to, "", body, "", component, nil, 0, "", false, false, "")
+func SendServiceMessage(to, body string, component *xmpp.Component) {
+ sendMessageWrapper(to, "", body, "", "", component, nil, 0, "", false, false, 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, 0, "", false, false, "")
+func SendTextMessage(to, from, body string, component *xmpp.Component) {
+ sendMessageWrapper(to, from, body, "", "", component, nil, 0, "", false, false, 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, timestamp int64, oob string, isCarbon bool, isGroupchat bool, originalFrom string) {
- sendMessageWrapper(to, from, body, id, component, reply, timestamp, oob, isCarbon, isGroupchat, originalFrom)
+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)
}
-func sendMessageWrapper(to string, from string, body string, id string, component *xmpp.Component, reply *Reply, timestamp int64, oob string, isCarbon bool, isGroupchat bool, originalFrom string) {
+// 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, "")
+}
+
+func sendMessageWrapper(to, from, body, subject, id string, component *xmpp.Component, reply *Reply, timestamp int64, oob string, isCarbon, isGroupchat, forceSubject bool, originalFrom string) {
toJid, err := stanza.NewJid(to)
if err != nil {
log.WithFields(log.Fields{
@@ -115,7 +120,8 @@ func sendMessageWrapper(to string, from string, body string, id string, componen
Type: messageType,
Id: id,
},
- Body: body,
+ Subject: subject,
+ Body: body,
}
if oob != "" {
@@ -132,7 +138,7 @@ func sendMessageWrapper(to string, from string, body string, id string, componen
message.Extensions = append(message.Extensions, extensions.NewReplyFallback(reply.Start, reply.End))
}
}
- if !isCarbon && toJid.Resource != "" {
+ if !isGroupchat && !isCarbon && toJid.Resource != "" {
message.Extensions = append(message.Extensions, stanza.HintNoCopy{})
}
if timestamp != 0 {
@@ -159,6 +165,9 @@ func sendMessageWrapper(to string, from string, body string, id string, componen
},
})
}
+ if subject == "" && forceSubject {
+ message.Extensions = append(message.Extensions, extensions.EmptySubject{})
+ }
if isCarbon {
carbonMessage := extensions.ClientMessage{