Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
346baa68
Commit
346baa68
authored
May 03, 2019
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor room auto-configuration
parent
273b9584
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
141 additions
and
115 deletions
+141
-115
dist/converse.js
dist/converse.js
+48
-39
src/headless/converse-muc.js
src/headless/converse-muc.js
+45
-37
src/headless/dist/converse-headless.js
src/headless/dist/converse-headless.js
+48
-39
No files found.
dist/converse.js
View file @
346baa68
...
...
@@ -67514,50 +67514,59 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
});
},
autoConfigureChatRoom() {
/* Automatically configure groupchat based on this model's
* 'roomconfig' data.
*
* Returns a promise which resolves once a response IQ has
* been received.
*/
return new Promise((resolve, reject) => {
this.fetchRoomConfiguration().then(stanza => {
const configArray = [],
fields = stanza.querySelectorAll('field'),
config = this.get('roomconfig');
let count = fields.length;
_.each(fields, field => {
const fieldname = field.getAttribute('var').replace('muc#roomconfig_', ''),
type = field.getAttribute('type');
let value;
if (fieldname in config) {
switch (type) {
case 'boolean':
value = config[fieldname] ? 1 : 0;
break;
/**
* Given a <field> element, return a copy with a <value> child if
* we can find a value for it in this rooms config.
* @private
* @method _converse.ChatRoom#autoConfigureChatRoom
* @returns { Element }
*/
addFieldValue(field) {
const type = field.getAttribute('type');
const fieldname = field.getAttribute('var').replace('muc#roomconfig_', '');
const config = this.get('roomconfig');
case 'list-multi':
// TODO: we don't yet handle "list-multi" types
value = field.innerHTML;
break;
if (fieldname in config) {
let value;
default:
value = config[fieldname];
}
switch (type) {
case 'boolean':
value = config[fieldname] ? 1 : 0;
break;
field.innerHTML = $build('value').t(value);
}
case 'list-multi':
// TODO: we don't yet handle "list-multi" types
value = field.innerHTML;
break;
configArray.push(field);
default:
value = config[fieldname];
}
if (! --count) {
this.sendConfiguration(configArray, resolve, reject);
}
});
});
field.innerHTML = $build('value').t(value);
}
return field;
},
/**
* Automatically configure the groupchat based on this model's
* 'roomconfig' data.
* @private
* @method _converse.ChatRoom#autoConfigureChatRoom
* @returns { promise }
* Returns a promise which resolves once a response IQ has
* been received.
*/
autoConfigureChatRoom() {
return new Promise(async (resolve, reject) => {
const stanza = await this.fetchRoomConfiguration();
const fields = sizzle('field', stanza);
const configArray = fields.map(f => this.addFieldValue(f));
if (configArray.length) {
this.sendConfiguration(configArray, resolve, reject);
}
});
},
src/headless/converse-muc.js
View file @
346baa68
...
...
@@ -644,44 +644,52 @@ converse.plugins.add('converse-muc', {
});
},
/**
* Given a <field> element, return a copy with a <value> child if
* we can find a value for it in this rooms config.
* @private
* @method _converse.ChatRoom#autoConfigureChatRoom
* @returns { Element }
*/
addFieldValue
(
field
)
{
const
type
=
field
.
getAttribute
(
'
type
'
);
const
fieldname
=
field
.
getAttribute
(
'
var
'
).
replace
(
'
muc#roomconfig_
'
,
''
);
const
config
=
this
.
get
(
'
roomconfig
'
);
if
(
fieldname
in
config
)
{
let
value
;
switch
(
type
)
{
case
'
boolean
'
:
value
=
config
[
fieldname
]
?
1
:
0
;
break
;
case
'
list-multi
'
:
// TODO: we don't yet handle "list-multi" types
value
=
field
.
innerHTML
;
break
;
default
:
value
=
config
[
fieldname
];
}
field
.
innerHTML
=
$build
(
'
value
'
).
t
(
value
);
}
return
field
;
},
/**
* Automatically configure the groupchat based on this model's
* 'roomconfig' data.
* @private
* @method _converse.ChatRoom#autoConfigureChatRoom
* @returns { promise }
* Returns a promise which resolves once a response IQ has
* been received.
*/
autoConfigureChatRoom
()
{
/* Automatically configure groupchat based on this model's
* 'roomconfig' data.
*
* Returns a promise which resolves once a response IQ has
* been received.
*/
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
fetchRoomConfiguration
().
then
((
stanza
)
=>
{
const
configArray
=
[],
fields
=
stanza
.
querySelectorAll
(
'
field
'
),
config
=
this
.
get
(
'
roomconfig
'
);
let
count
=
fields
.
length
;
_
.
each
(
fields
,
(
field
)
=>
{
const
fieldname
=
field
.
getAttribute
(
'
var
'
).
replace
(
'
muc#roomconfig_
'
,
''
),
type
=
field
.
getAttribute
(
'
type
'
);
let
value
;
if
(
fieldname
in
config
)
{
switch
(
type
)
{
case
'
boolean
'
:
value
=
config
[
fieldname
]
?
1
:
0
;
break
;
case
'
list-multi
'
:
// TODO: we don't yet handle "list-multi" types
value
=
field
.
innerHTML
;
break
;
default
:
value
=
config
[
fieldname
];
}
field
.
innerHTML
=
$build
(
'
value
'
).
t
(
value
);
}
configArray
.
push
(
field
);
if
(
!--
count
)
{
this
.
sendConfiguration
(
configArray
,
resolve
,
reject
);
}
});
});
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
const
stanza
=
await
this
.
fetchRoomConfiguration
();
const
fields
=
sizzle
(
'
field
'
,
stanza
);
const
configArray
=
fields
.
map
(
f
=>
this
.
addFieldValue
(
f
))
if
(
configArray
.
length
)
{
this
.
sendConfiguration
(
configArray
,
resolve
,
reject
);
}
});
},
...
...
src/headless/dist/converse-headless.js
View file @
346baa68
...
...
@@ -45762,50 +45762,59 @@ _converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins.add('converse-muc
});
},
autoConfigureChatRoom() {
/* Automatically configure groupchat based on this model's
* 'roomconfig' data.
*
* Returns a promise which resolves once a response IQ has
* been received.
*/
return new Promise((resolve, reject) => {
this.fetchRoomConfiguration().then(stanza => {
const configArray = [],
fields = stanza.querySelectorAll('field'),
config = this.get('roomconfig');
let count = fields.length;
_.each(fields, field => {
const fieldname = field.getAttribute('var').replace('muc#roomconfig_', ''),
type = field.getAttribute('type');
let value;
if (fieldname in config) {
switch (type) {
case 'boolean':
value = config[fieldname] ? 1 : 0;
break;
/**
* Given a <field> element, return a copy with a <value> child if
* we can find a value for it in this rooms config.
* @private
* @method _converse.ChatRoom#autoConfigureChatRoom
* @returns { Element }
*/
addFieldValue(field) {
const type = field.getAttribute('type');
const fieldname = field.getAttribute('var').replace('muc#roomconfig_', '');
const config = this.get('roomconfig');
case 'list-multi':
// TODO: we don't yet handle "list-multi" types
value = field.innerHTML;
break;
if (fieldname in config) {
let value;
default:
value = config[fieldname];
}
switch (type) {
case 'boolean':
value = config[fieldname] ? 1 : 0;
break;
field.innerHTML = $build('value').t(value);
}
case 'list-multi':
// TODO: we don't yet handle "list-multi" types
value = field.innerHTML;
break;
configArray.push(field);
default:
value = config[fieldname];
}
if (! --count) {
this.sendConfiguration(configArray, resolve, reject);
}
});
});
field.innerHTML = $build('value').t(value);
}
return field;
},
/**
* Automatically configure the groupchat based on this model's
* 'roomconfig' data.
* @private
* @method _converse.ChatRoom#autoConfigureChatRoom
* @returns { promise }
* Returns a promise which resolves once a response IQ has
* been received.
*/
autoConfigureChatRoom() {
return new Promise(async (resolve, reject) => {
const stanza = await this.fetchRoomConfiguration();
const fields = sizzle('field', stanza);
const configArray = fields.map(f => this.addFieldValue(f));
if (configArray.length) {
this.sendConfiguration(configArray, resolve, reject);
}
});
},
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment