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
17401cb9
Commit
17401cb9
authored
Sep 12, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improvements to automatic nick registrations
Also expand and fix the associated test.
parent
6457bc76
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
41 deletions
+34
-41
spec/room_registration.js
spec/room_registration.js
+25
-38
src/converse-muc.js
src/converse-muc.js
+9
-3
No files found.
spec/room_registration.js
View file @
17401cb9
...
...
@@ -4,6 +4,7 @@
const
_
=
converse
.
env
.
_
,
$iq
=
converse
.
env
.
$iq
,
Strophe
=
converse
.
env
.
Strophe
,
sizzle
=
converse
.
env
.
sizzle
,
u
=
converse
.
env
.
utils
;
describe
(
"
Chatrooms
"
,
function
()
{
...
...
@@ -18,58 +19,44 @@
const
room_jid
=
'
coven@chat.shakespeare.lit
'
;
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
coven
'
,
'
chat.shakespeare.lit
'
,
'
romeo
'
)
.
then
(()
=>
{
return
test_utils
.
waitUntil
(()
=>
_
.
get
(
_
.
filter
(
_converse
.
connection
.
IQ_stanzas
,
iq
=>
iq
.
nodeTree
.
querySelector
(
`iq[to="coven@chat.shakespeare.lit"] query[xmlns="http://jabber.org/protocol/disco#info"]`
)
).
pop
(),
'
nodeTree
'
));
}).
then
(
stanza
=>
{
view
=
_converse
.
chatboxviews
.
get
(
'
coven@chat.shakespeare.lit
'
);
spyOn
(
view
.
model
,
'
parseRoomFeatures
'
).
and
.
callThrough
();
const
features_stanza
=
$iq
({
'
from
'
:
room_jid
,
'
id
'
:
stanza
.
getAttribute
(
'
id
'
),
'
to
'
:
'
dummy@localhost/desktop
'
,
'
type
'
:
'
result
'
})
.
c
(
'
query
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/disco#info
'
})
.
c
(
'
identity
'
,
{
'
category
'
:
'
conference
'
,
'
name
'
:
'
A Dark Cave
'
,
'
type
'
:
'
text
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
http://jabber.org/protocol/muc
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
jabber:iq:register
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_passwordprotected
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_hidden
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_temporary
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_open
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_unmoderated
'
}).
up
()
.
c
(
'
feature
'
,
{
'
var
'
:
'
muc_nonanonymous
'
});
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
features_stanza
));
return
test_utils
.
waitUntil
(()
=>
view
.
model
.
parseRoomFeatures
.
calls
.
count
(),
300
)
}).
then
(()
=>
{
return
test_utils
.
waitUntil
(()
=>
_
.
get
(
_
.
filter
(
_converse
.
connection
.
IQ_stanzas
,
iq
=>
iq
.
nodeTree
.
querySelector
(
`iq[to="coven@chat.shakespeare.lit"] query[xmlns="jabber:iq:register"]`
)
iq
=>
sizzle
(
`iq[to="coven@chat.shakespeare.lit"][type="get"] query[xmlns="jabber:iq:register"]`
,
iq
.
nodeTree
).
length
).
pop
(),
'
nodeTree
'
));
}).
then
(
stanza
=>
{
expect
(
stanza
.
outerHTML
)
.
toBe
(
`<iq
from="dummy@localhost" to="coven@chat.shakespeare.lit
" `
+
.
toBe
(
`<iq
to="coven@chat.shakespeare.lit" from="dummy@localhost/resource
" `
+
`type="get" xmlns="jabber:client" id="
${
stanza
.
getAttribute
(
'
id
'
)}
">`
+
`<query xmlns="jabber:iq:register"/></iq>`
);
// Room does not exist
view
=
_converse
.
chatboxviews
.
get
(
room_jid
);
const
result
=
$iq
({
'
from
'
:
view
.
model
.
get
(
'
jid
'
),
'
id
'
:
stanza
.
getAttribute
(
'
id
'
),
'
to
'
:
_converse
.
bare_jid
,
'
type
'
:
'
error
'
,
}).
c
(
'
error
'
,
{
'
type
'
:
"
cancel
"
})
.
c
(
'
item-not-found
'
,
{
'
xmlns
'
:
"
urn:ietf:params:xml:ns:xmpp-stanzas
"
})
'
type
'
:
'
result
'
,
}).
c
(
'
query
'
,
{
'
type
'
:
'
jabber:iq:register
'
})
.
c
(
'
x
'
,
{
'
xmlns
'
:
'
jabber:x:data
'
,
'
type
'
:
'
form
'
})
.
c
(
'
field
'
,
{
'
label
'
:
'
Desired Nickname
'
,
'
type
'
:
'
text-single
'
,
'
var
'
:
'
muc#register_roomnick
'
}).
c
(
'
required
'
);
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
result
));
return
test_utils
.
waitUntil
(()
=>
_
.
get
(
_
.
filter
(
_converse
.
connection
.
IQ_stanzas
,
iq
=>
sizzle
(
`iq[to="coven@chat.shakespeare.lit"][type="set"] query[xmlns="jabber:iq:register"]`
,
iq
.
nodeTree
).
length
).
pop
(),
'
nodeTree
'
));
}).
then
(
stanza
=>
{
expect
(
stanza
.
outerHTML
).
toBe
(
`<iq to="coven@chat.shakespeare.lit" from="dummy@localhost/resource" type="set" xmlns="jabber:client" id="
${
stanza
.
getAttribute
(
'
id
'
)}
">`
+
`<query xmlns="jabber:iq:register">`
+
`<x xmlns="jabber:x:data" type="submit">`
+
`<field var="FORM_TYPE"><value>http://jabber.org/protocol/muc#register</value></field>`
+
`<field var="muc#register_roomnick"><value>romeo</value></field>`
+
`</x>`
+
`</query>`
+
`</iq>`
);
done
();
}).
catch
(
_
.
partial
(
_converse
.
log
,
_
,
Strophe
.
LogLevel
.
FATAL
));
}));
...
...
src/converse-muc.js
View file @
17401cb9
...
...
@@ -810,11 +810,12 @@
},
async
registerNickname
()
{
let
iq
;
try
{
await
_converse
.
api
.
sendIQ
(
iq
=
await
_converse
.
api
.
sendIQ
(
$iq
({
'
from
'
:
_converse
.
bare_jid
,
'
to
'
:
this
.
get
(
'
jid
'
),
'
from
'
:
_converse
.
connection
.
jid
,
'
type
'
:
'
get
'
}).
c
(
'
query
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
MUC_REGISTER
})
);
...
...
@@ -826,10 +827,15 @@
}
return
_converse
.
log
(
e
,
Strophe
.
LogLevel
.
ERROR
);
}
const
required_fields
=
_
.
map
(
sizzle
(
'
field required
'
,
iq
),
'
parentElement
'
);
if
(
required_fields
.
length
>
1
||
required_fields
[
0
].
getAttribute
(
'
var
'
)
!==
'
muc#register_roomnick
'
)
{
return
_converse
.
log
(
`Can't register the user register in the groupchat
${
this
.
get
(
'
jid
'
)}
due to the required fields`
);
}
try
{
await
_converse
.
api
.
sendIQ
(
$iq
({
'
from
'
:
_converse
.
bare_jid
,
'
to
'
:
this
.
get
(
'
jid
'
),
'
from
'
:
_converse
.
connection
.
jid
,
'
type
'
:
'
set
'
}).
c
(
'
query
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
MUC_REGISTER
})
.
c
(
'
x
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
XFORM
,
'
type
'
:
'
submit
'
})
...
...
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