From 1f2f2bb1c5d252d244f8f4d2fa2237987e10f420 Mon Sep 17 00:00:00 2001 From: Ian Lamb Date: Fri, 15 Jan 2021 12:19:05 -0800 Subject: [PATCH 1/3] feat!: change msg subject and body to localizable structs --- stanza/message.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/stanza/message.go b/stanza/message.go index 35e44c1..cb5410b 100644 --- a/stanza/message.go +++ b/stanza/message.go @@ -8,13 +8,29 @@ import ( // ============================================================================ // Message Packet +// Subject is an element of a message +type Subject struct { + XMLName xml.Name `xml:"subject"` + + Content string `xml:",chardata,omitempty"` + Lang string `xml:"lang,attr,omitempty"` +} + +// Body is an element of a message +type Body struct { + XMLName xml.Name `xml:"body"` + + Content string `xml:",chardata,omitempty"` + Lang string `xml:"lang,attr,omitempty"` +} + // Message implements RFC 6120 - A.5 Client Namespace (a part) type Message struct { XMLName xml.Name `xml:"message"` Attrs - Subject string `xml:"subject,omitempty"` - Body string `xml:"body,omitempty"` + Subject []Subject `xml:"subject,omitempty"` + Body []Body `xml:"body,omitempty"` Thread string `xml:"thread,omitempty"` Error Err `xml:"error,omitempty"` Extensions []MsgExtension `xml:",omitempty"` From da90222053d4e0cd52a5fa756dd300908201b4b1 Mon Sep 17 00:00:00 2001 From: Derek Brown Date: Fri, 15 Jan 2021 17:14:34 -0500 Subject: [PATCH 2/3] fix: omitempty is not compatible with chardata xml encoding tag --- stanza/message.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stanza/message.go b/stanza/message.go index cb5410b..2a74a14 100644 --- a/stanza/message.go +++ b/stanza/message.go @@ -12,7 +12,7 @@ import ( type Subject struct { XMLName xml.Name `xml:"subject"` - Content string `xml:",chardata,omitempty"` + Content string `xml:",chardata"` Lang string `xml:"lang,attr,omitempty"` } @@ -20,7 +20,7 @@ type Subject struct { type Body struct { XMLName xml.Name `xml:"body"` - Content string `xml:",chardata,omitempty"` + Content string `xml:",chardata"` Lang string `xml:"lang,attr,omitempty"` } From cef045dc585e48d0d023674120fa1cf10d93fe40 Mon Sep 17 00:00:00 2001 From: Derek Brown Date: Mon, 18 Jan 2021 14:15:40 -0500 Subject: [PATCH 3/3] feat: refactor message body and subject structs as common LocalizedString --- stanza/message.go | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/stanza/message.go b/stanza/message.go index 2a74a14..954d515 100644 --- a/stanza/message.go +++ b/stanza/message.go @@ -8,18 +8,7 @@ import ( // ============================================================================ // Message Packet -// Subject is an element of a message -type Subject struct { - XMLName xml.Name `xml:"subject"` - - Content string `xml:",chardata"` - Lang string `xml:"lang,attr,omitempty"` -} - -// Body is an element of a message -type Body struct { - XMLName xml.Name `xml:"body"` - +type LocalizedString struct { Content string `xml:",chardata"` Lang string `xml:"lang,attr,omitempty"` } @@ -29,11 +18,11 @@ type Message struct { XMLName xml.Name `xml:"message"` Attrs - Subject []Subject `xml:"subject,omitempty"` - Body []Body `xml:"body,omitempty"` - Thread string `xml:"thread,omitempty"` - Error Err `xml:"error,omitempty"` - Extensions []MsgExtension `xml:",omitempty"` + Subject []LocalizedString `xml:"subject,omitempty"` + Body []LocalizedString `xml:"body,omitempty"` + Thread string `xml:"thread,omitempty"` + Error Err `xml:"error,omitempty"` + Extensions []MsgExtension `xml:",omitempty"` } func (Message) Name() string {