Skip to content

Commit fa95dda

Browse files
committed
Django settings separed from conversejs settings &
Not adding the XML declaration line as it's optional on most bosh servers and not accepted by some of them.
1 parent 1610019 commit fa95dda

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

conversejs/boshclient.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from xml.etree import ElementTree as ET
1616

1717
from puresasl.client import SASLClient
18-
from .conf import get_conversejs_settings
1918

2019

2120
try: # Python 2.7+
@@ -69,10 +68,6 @@ def __init__(self, jid, password, bosh_service):
6968

7069
self.server_auth = []
7170

72-
converse_settings = get_conversejs_settings()
73-
xml_encoding_line = converse_settings['CONVERSEJS_XML_ENCODING_LINE']
74-
self.xml_encoding_line = True if xml_encoding_line.lower() == 'true' else False
75-
7671
@property
7772
def connection(self):
7873
"""Returns an stablished connection"""
@@ -134,8 +129,7 @@ def get_body(self, sid_request=False):
134129
def send_request(self, xml_stanza):
135130
ElementType = getattr(ET, '_Element', ET.Element)
136131
if isinstance(xml_stanza, ElementType):
137-
xml_stanza = ET.tostring(xml_stanza) if not self.xml_encoding_line\
138-
else ET.tostring(xml_stanza, encoding='utf8')
132+
xml_stanza = ET.tostring(xml_stanza)
139133

140134
self.log.debug('XML_STANZA: %s', xml_stanza)
141135
self.log.debug('Sending the request')

conversejs/conf.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
from django.conf import settings
22

33

4+
# Django-conversejs settings
5+
CONVERSEJS_AUTO_REGISTER = getattr(settings, 'CONVERSEJS_AUTO_REGISTER', False)
6+
7+
48
def get_conversejs_settings():
9+
"""This helper function returns all the configuration needed by
10+
Converse.js frontend (javascript).
11+
12+
Configurations specific to django-conversejs should be added above.
13+
14+
"""
515
converse_settings = {
616
'CONVERSEJS_AUTO_LIST_ROOMS': False,
717
'CONVERSEJS_AUTO_SUBSCRIBE': False,
@@ -10,7 +20,6 @@ def get_conversejs_settings():
1020
'CONVERSEJS_PREBIND': True,
1121
'CONVERSEJS_SHOW_CONTROLBOX_BY_DEFAULT': False,
1222
'CONVERSEJS_XHR_USER_SEARCH': False,
13-
'CONVERSEJS_XML_ENCODING_LINE': True,
1423
'CONVERSEJS_DEBUG': settings.DEBUG,
1524
}
1625

@@ -23,3 +32,4 @@ def get_conversejs_settings():
2332
converse_settings[key] = conf
2433

2534
return converse_settings
35+

conversejs/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import uuid
33

4-
from .conf import get_conversejs_settings
4+
from .conf import get_conversejs_settings, CONVERSEJS_AUTO_REGISTER
55
from .models import XMPPAccount
66
from .boshclient import BOSHClient
77
from .register import register_account
@@ -18,7 +18,7 @@ def get_conversejs_context(context, xmpp_login=False):
1818
try:
1919
xmpp_account = XMPPAccount.objects.get(user=request.user.pk)
2020
except XMPPAccount.DoesNotExist:
21-
jid_domain = getattr(settings, 'CONVERSEJS_AUTO_REGISTER', False)
21+
jid_domain = CONVERSEJS_AUTO_REGISTER
2222
if not jid_domain:
2323
return context
2424

0 commit comments

Comments
 (0)