Skip to content

Commit

Permalink
Fix JSON containers with pubsub
Browse files Browse the repository at this point in the history
Closes #402
  • Loading branch information
legastero committed Nov 15, 2019
1 parent 2ae3e2e commit 90b6635
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/Supported_XEP_Formats.md
Expand Up @@ -90,7 +90,7 @@
| [XEP-0320](https://xmpp.org/extensions/xep-0320.html) | Use of DTLS-SRTP in Jingle Sessions | 0.3.1 | [Source](../src/protocol/xep0320.ts) | |
| [XEP-0333](https://xmpp.org/extensions/xep-0333.html) | Chat Markers | 0.3.0 | [Source](../src/protocol/xep0333.ts) | [Test Cases](../test/protocol-cases/xep0333) |
| [XEP-0334](https://xmpp.org/extensions/xep-0334.html) | Message Processing Hints | 0.3.0 | [Source](../src/protocol/xep0334.ts) | [Test Cases](../test/protocol-cases/xep0334) |
| [XEP-0335](https://xmpp.org/extensions/xep-0335.html) | JSON Containers | 0.1 | [Source](../src/protocol/xep0335.ts) | |
| [XEP-0335](https://xmpp.org/extensions/xep-0335.html) | JSON Containers | 0.1 | [Source](../src/protocol/xep0335.ts) | [Test Cases](../test/protocol-cases/xep0335) |
| [XEP-0339](https://xmpp.org/extensions/xep-0339.html) | Source-Specific Media Attributes in Jingle | 0.1 | [Source](../src/protocol/xep0167.ts) | [Test Cases](../test/protocol-cases/xep0167) |
| [XEP-0350](https://xmpp.org/extensions/xep-0350.html) | Data Forms Geolocation Element | 0.2 | [Source](../src/protocol/xep0080.ts) | |
| [XEP-0352](https://xmpp.org/extensions/xep-0352.html) | Client State Indication | 0.2.1 | [Source](../src/protocol/xep0352.ts) | |
Expand Down
10 changes: 8 additions & 2 deletions src/protocol/xep0335.ts
Expand Up @@ -5,7 +5,13 @@
// Version: 0.1 (2013-10-25)
// ====================================================================

import { childJSON, DefinitionOptions, extendMessage, pubsubItemContentAliases } from '../jxt';
import {
childJSON,
DefinitionOptions,
extendMessage,
pubsubItemContentAliases,
textJSON
} from '../jxt';
import { NS_JSON_0 } from '../Namespaces';

import { PubsubItemContent } from './';
Expand All @@ -29,7 +35,7 @@ const Protocol: DefinitionOptions[] = [
aliases: pubsubItemContentAliases(),
element: 'json',
fields: {
json: childJSON(NS_JSON_0, 'json')
json: textJSON()
},
namespace: NS_JSON_0,
type: NS_JSON_0
Expand Down
14 changes: 14 additions & 0 deletions test/protocol-cases/xep0335/message.json
@@ -0,0 +1,14 @@
[
"message",
{
"from": "pubsub.shakespeare.lit",
"to": "francisco@denmark.lit",
"id": "foo",
"lang": "",
"json": {
"name": "romeo",
"age": "421",
"status": "single"
}
}
]
3 changes: 3 additions & 0 deletions test/protocol-cases/xep0335/message.xml
@@ -0,0 +1,3 @@
<message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo'>
<json xmlns="urn:xmpp:json:0">{"name":"romeo","age":"421","status":"single"}</json>
</message>
55 changes: 55 additions & 0 deletions test/protocol-cases/xep0335/pubsub-event.json
@@ -0,0 +1,55 @@
[
"message",
{
"from": "pubsub.shakespeare.lit",
"id": "foo",
"lang": "",
"pubsub": {
"context": "event",
"items": {
"node": "princely_musings",
"published": [
{
"content": {
"itemType": "urn:xmpp:json:0",
"json": {
"age": "421",
"name": "romeo",
"status": "single"
}
},
"id": "ae890ac52d0df67ed7cfdf51b644e901"
}
]
}
},
"to": "francisco@denmark.lit"
},
{
"from": "pubsub.shakespeare.lit",
"id": "foo",
"lang": "",
"pubsub": {
"context": "event",
"eventType": "items",
"items": {
"node": "princely_musings",
"published": [
{
"content": {
"itemType": "urn:xmpp:json:0",
"json": {
"age": "421",
"name": "romeo",
"status": "single"
}
},
"id": "ae890ac52d0df67ed7cfdf51b644e901"
}
],
"retracted": []
}
},
"to": "francisco@denmark.lit"
}
]
9 changes: 9 additions & 0 deletions test/protocol-cases/xep0335/pubsub-event.xml
@@ -0,0 +1,9 @@
<message from='pubsub.shakespeare.lit' to='francisco@denmark.lit' id='foo'>
<event xmlns='http://jabber.org/protocol/pubsub#event'>
<items node='princely_musings'>
<item id='ae890ac52d0df67ed7cfdf51b644e901'>
<json xmlns="urn:xmpp:json:0">{"age":"421","name":"romeo","status":"single"}</json>
</item>
</items>
</event>
</message>

0 comments on commit 90b6635

Please sign in to comment.