Parties work now
This commit is contained in:
parent
1ebe963b2d
commit
c6fc106c4b
|
@ -3,6 +3,7 @@ package socket
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/beevik/etree"
|
"github.com/beevik/etree"
|
||||||
"github.com/ectrc/snow/aid"
|
"github.com/ectrc/snow/aid"
|
||||||
|
@ -35,8 +36,6 @@ func HandleNewJabberSocket(identifier string) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
aid.Print(string(message))
|
|
||||||
|
|
||||||
parsed := etree.NewDocument()
|
parsed := etree.NewDocument()
|
||||||
if err := parsed.ReadFromBytes(message); err != nil {
|
if err := parsed.ReadFromBytes(message); err != nil {
|
||||||
return
|
return
|
||||||
|
@ -100,13 +99,33 @@ func jabberIqGetHandler(socket *Socket[JabberData], parsed *etree.Document) erro
|
||||||
}
|
}
|
||||||
|
|
||||||
func jabberPresenceHandler(socket *Socket[JabberData], parsed *etree.Document) error {
|
func jabberPresenceHandler(socket *Socket[JabberData], parsed *etree.Document) error {
|
||||||
socket.Data.LastPresence = parsed.FindElement("/presence/status").Text()
|
status := parsed.FindElement("/presence/status")
|
||||||
|
if status == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
socket.Data.LastPresence = status.Text()
|
||||||
socket.JabberNotifyFriends()
|
socket.JabberNotifyFriends()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func jabberMessageHandler(socket *Socket[JabberData], parsed *etree.Document) error {
|
func jabberMessageHandler(socket *Socket[JabberData], parsed *etree.Document) error {
|
||||||
|
if parsed.FindElement("/message/body") == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
message := parsed.FindElement("/message")
|
||||||
|
target := message.SelectAttr("to").Value
|
||||||
|
parts := strings.Split(target, "@")
|
||||||
|
|
||||||
|
if len(parts) != 2 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if reciever, ok := JabberSockets.Get(parts[0]); ok {
|
||||||
|
reciever.Write([]byte(`<message xmlns="jabber:client" from="`+ socket.Data.JabberID +`" to="`+ target +`" id="`+ message.SelectAttr("id").Value +`">
|
||||||
|
<body>`+ message.FindElement("/message/body").Text() +`</body>
|
||||||
|
</message>`))
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user