Support urn:xmpp:privilege:2
This commit is contained in:
parent
608f675512
commit
c03ccfdfb7
2
Makefile
2
Makefile
|
@ -2,7 +2,7 @@
|
|||
|
||||
COMMIT := $(shell git rev-parse --short HEAD)
|
||||
TD_COMMIT := "8517026415e75a8eec567774072cbbbbb52376c1"
|
||||
VERSION := "v1.7.3"
|
||||
VERSION := "v1.7.4"
|
||||
MAKEOPTS := "-j4"
|
||||
|
||||
all:
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
goxmpp "gosrc.io/xmpp"
|
||||
)
|
||||
|
||||
var version string = "1.7.3"
|
||||
var version string = "1.7.4"
|
||||
var commit string
|
||||
|
||||
var sm *goxmpp.StreamManager
|
||||
|
|
|
@ -384,7 +384,7 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) string
|
|||
}
|
||||
case "config":
|
||||
if len(args) > 1 {
|
||||
if !gateway.MessageOutgoingPermission && args[0] == "carbons" && args[1] == "true" {
|
||||
if gateway.MessageOutgoingPermissionVersion == 0 && args[0] == "carbons" && args[1] == "true" {
|
||||
return "The server did not allow to enable carbons"
|
||||
}
|
||||
|
||||
|
|
|
@ -842,7 +842,7 @@ func (c *Client) messageToPrefix(message *client.Message, previewString string,
|
|||
prefix := []string{}
|
||||
// message direction
|
||||
var directionChar string
|
||||
if !isPM || !gateway.MessageOutgoingPermission || !c.Session.Carbons {
|
||||
if !isPM || gateway.MessageOutgoingPermissionVersion == 0 || !c.Session.Carbons {
|
||||
if c.Session.AsciiArrows {
|
||||
if message.IsOutgoing {
|
||||
directionChar = "> "
|
||||
|
@ -914,7 +914,7 @@ func (c *Client) ensureDownloadFile(file *client.File) *client.File {
|
|||
func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
|
||||
var isPM bool
|
||||
var err error
|
||||
if gateway.MessageOutgoingPermission && c.Session.Carbons {
|
||||
if gateway.MessageOutgoingPermissionVersion > 0 && c.Session.Carbons {
|
||||
isPM, err = c.IsPM(chatId)
|
||||
if err != nil {
|
||||
log.Errorf("Could not determine if chat is PM: %v", err)
|
||||
|
|
|
@ -154,12 +154,19 @@ type CarbonSent struct {
|
|||
}
|
||||
|
||||
// ComponentPrivilege is from XEP-0356
|
||||
type ComponentPrivilege struct {
|
||||
type ComponentPrivilege1 struct {
|
||||
XMLName xml.Name `xml:"urn:xmpp:privilege:1 privilege"`
|
||||
Perms []ComponentPerm `xml:"perm"`
|
||||
Forwarded stanza.Forwarded `xml:"urn:xmpp:forward:0 forwarded"`
|
||||
}
|
||||
|
||||
// ComponentPrivilege is from XEP-0356
|
||||
type ComponentPrivilege2 struct {
|
||||
XMLName xml.Name `xml:"urn:xmpp:privilege:2 privilege"`
|
||||
Perms []ComponentPerm `xml:"perm"`
|
||||
Forwarded stanza.Forwarded `xml:"urn:xmpp:forward:0 forwarded"`
|
||||
}
|
||||
|
||||
// ComponentPerm is from XEP-0356
|
||||
type ComponentPerm struct {
|
||||
XMLName xml.Name `xml:"perm"`
|
||||
|
@ -227,7 +234,12 @@ func (c CarbonSent) Namespace() string {
|
|||
}
|
||||
|
||||
// Namespace is a namespace!
|
||||
func (c ComponentPrivilege) Namespace() string {
|
||||
func (c ComponentPrivilege1) Namespace() string {
|
||||
return c.XMLName.Space
|
||||
}
|
||||
|
||||
// Namespace is a namespace!
|
||||
func (c ComponentPrivilege2) Namespace() string {
|
||||
return c.XMLName.Space
|
||||
}
|
||||
|
||||
|
@ -297,11 +309,17 @@ func init() {
|
|||
"sent",
|
||||
}, CarbonSent{})
|
||||
|
||||
// component privilege
|
||||
// component privilege v1
|
||||
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
|
||||
"urn:xmpp:privilege:1",
|
||||
"privilege",
|
||||
}, ComponentPrivilege{})
|
||||
}, ComponentPrivilege1{})
|
||||
|
||||
// component privilege v2
|
||||
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
|
||||
"urn:xmpp:privilege:2",
|
||||
"privilege",
|
||||
}, ComponentPrivilege2{})
|
||||
|
||||
// message edit
|
||||
stanza.TypeRegistry.MapExtension(stanza.PKTMessage, xml.Name{
|
||||
|
|
|
@ -38,8 +38,8 @@ var IdsDB badger.IdsDB
|
|||
// were changed and need to be re-flushed to the YamlDB
|
||||
var DirtySessions = false
|
||||
|
||||
// MessageOutgoingPermission allows to fake outgoing messages by foreign JIDs
|
||||
var MessageOutgoingPermission = false
|
||||
// MessageOutgoingPermissionVersion contains a XEP-0356 version to fake outgoing messages by foreign JIDs
|
||||
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, isCarbon bool) {
|
||||
|
@ -142,11 +142,19 @@ func sendMessageWrapper(to string, from string, body string, id string, componen
|
|||
To: toJid.Domain,
|
||||
},
|
||||
}
|
||||
privilegeMessage.Extensions = append(privilegeMessage.Extensions, extensions.ComponentPrivilege{
|
||||
Forwarded: stanza.Forwarded{
|
||||
Stanza: carbonMessage,
|
||||
},
|
||||
})
|
||||
if MessageOutgoingPermissionVersion == 2 {
|
||||
privilegeMessage.Extensions = append(privilegeMessage.Extensions, extensions.ComponentPrivilege2{
|
||||
Forwarded: stanza.Forwarded{
|
||||
Stanza: carbonMessage,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
privilegeMessage.Extensions = append(privilegeMessage.Extensions, extensions.ComponentPrivilege1{
|
||||
Forwarded: stanza.Forwarded{
|
||||
Stanza: carbonMessage,
|
||||
},
|
||||
})
|
||||
}
|
||||
sendMessage(&privilegeMessage, component)
|
||||
} else {
|
||||
sendMessage(&message, component)
|
||||
|
|
|
@ -209,14 +209,25 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
|
|||
}
|
||||
|
||||
if msg.Body == "" {
|
||||
var privilege extensions.ComponentPrivilege
|
||||
if ok := msg.Get(&privilege); ok {
|
||||
log.Debugf("privilege: %#v", privilege)
|
||||
var privilege1 extensions.ComponentPrivilege1
|
||||
if ok := msg.Get(&privilege1); ok {
|
||||
log.Debugf("privilege1: %#v", privilege1)
|
||||
}
|
||||
|
||||
for _, perm := range privilege.Perms {
|
||||
for _, perm := range privilege1.Perms {
|
||||
if perm.Access == "message" && perm.Type == "outgoing" {
|
||||
gateway.MessageOutgoingPermission = true
|
||||
gateway.MessageOutgoingPermissionVersion = 1
|
||||
}
|
||||
}
|
||||
|
||||
var privilege2 extensions.ComponentPrivilege2
|
||||
if ok := msg.Get(&privilege2); ok {
|
||||
log.Debugf("privilege2: %#v", privilege2)
|
||||
}
|
||||
|
||||
for _, perm := range privilege2.Perms {
|
||||
if perm.Access == "message" && perm.Type == "outgoing" {
|
||||
gateway.MessageOutgoingPermissionVersion = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue