From eca0649c1e0a72fbea4899a295443eac69600bfd Mon Sep 17 00:00:00 2001 From: xengineering Date: Mon, 3 Jul 2023 20:49:19 +0200 Subject: Use xml.Encoder.EncodeElement() for presence This required the trick of defining an empty struct as `presence` type but works pretty well. For sending data EncodeElement instead of token handling should always work. Since it is simpler it should be used. --- xmpp/presence.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/xmpp/presence.go b/xmpp/presence.go index b6ea3b5..4adae6e 100644 --- a/xmpp/presence.go +++ b/xmpp/presence.go @@ -5,20 +5,17 @@ import ( "log" ) +type presence struct{} + func (s *session) sendPresence() { start := xml.StartElement{ xml.Name{"", "presence"}, []xml.Attr{}, } - end := start.End() - - tokens := [...]xml.Token{start, end} - for _, v := range tokens { - err := s.ed.encodeToken(v) - if err != nil { - log.Println("Could not encode presence!") - return - } + err := s.ed.tx.EncodeElement(presence{}, start) + if err != nil { + log.Println("Could not encode presence!") + return } } -- cgit v1.2.3-70-g09d2