aboutsummaryrefslogtreecommitdiff
path: root/xmpp/handlers.go
diff options
context:
space:
mode:
Diffstat (limited to 'xmpp/handlers.go')
-rw-r--r--xmpp/handlers.go43
1 files changed, 29 insertions, 14 deletions
diff --git a/xmpp/handlers.go b/xmpp/handlers.go
index 72b46eb..3ab79c7 100644
--- a/xmpp/handlers.go
+++ b/xmpp/handlers.go
@@ -123,6 +123,26 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
toID, ok := toToID(msg.To)
if ok {
+ toJid, err := stanza.NewJid(msg.To)
+ if err != nil {
+ log.Error("Invalid to JID!")
+ return
+ }
+
+ isGroupchat := msg.Type == "groupchat"
+
+ if session.Session.MUC && toJid.Resource != "" {
+ chat, _, err := session.GetContactByID(toID, nil)
+ if err == nil && session.IsGroup(chat) {
+ if isGroupchat {
+ gateway.SendErrorMessageWithBody(msg.From, msg.To, msg.Body, "", msg.Id, 400, true, component)
+ } else {
+ gateway.SendErrorMessage(msg.From, msg.To, "PMing room members is not supported, use the real JID", 406, true, component)
+ }
+ return
+ }
+ }
+
var reply extensions.Reply
var fallback extensions.Fallback
var replace extensions.Replace
@@ -134,7 +154,6 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
log.Debugf("replace: %#v", replace)
var replyId int64
- var err error
text := msg.Body
if len(reply.Id) > 0 {
chatId, msgId, err := gateway.IdsDB.GetByXmppId(session.Session.Login, bare, reply.Id)
@@ -194,7 +213,6 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
return
}
}
- isGroupchat := msg.Type == "groupchat"
session.SendMessageLock.Lock()
defer session.SendMessageLock.Unlock()
@@ -215,18 +233,15 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
}
// pong groupchat messages back
- if isGroupchat {
- toJid, err := stanza.NewJid(msg.To)
- if err == nil && toJid.Resource == "" {
- session.SendMessageToGateway(
- toID,
- tgMessage,
- msg.Id,
- false,
- msg.To + "/" + session.GetMUCNickname(session.GetSenderId(tgMessage)),
- []string{msg.From},
- )
- }
+ if isGroupchat && toJid.Resource == "" {
+ session.SendMessageToGateway(
+ toID,
+ tgMessage,
+ msg.Id,
+ false,
+ msg.To + "/" + session.GetMUCNickname(session.GetSenderId(tgMessage)),
+ []string{msg.From},
+ )
}
} else {
/*