From c6fc106c4b6247470497b68156df450e1c08f81c Mon Sep 17 00:00:00 2001 From: Eccentric Date: Wed, 31 Jan 2024 00:36:47 +0000 Subject: [PATCH] Parties work now --- socket/jabber.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/socket/jabber.go b/socket/jabber.go index 0f7fb6e..43214cf 100644 --- a/socket/jabber.go +++ b/socket/jabber.go @@ -3,6 +3,7 @@ package socket import ( "fmt" "reflect" + "strings" "github.com/beevik/etree" "github.com/ectrc/snow/aid" @@ -35,8 +36,6 @@ func HandleNewJabberSocket(identifier string) { break } - aid.Print(string(message)) - parsed := etree.NewDocument() if err := parsed.ReadFromBytes(message); err != nil { return @@ -100,13 +99,33 @@ func jabberIqGetHandler(socket *Socket[JabberData], parsed *etree.Document) erro } 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() return nil } 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.FindElement("/message/body").Text() +` + `)) + } return nil }