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
15df9b86
Commit
15df9b86
authored
Aug 16, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inlcude references in the outgoing XMPP stanza
parent
3db66377
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
56 deletions
+125
-56
spec/messages.js
spec/messages.js
+110
-54
src/converse-chatboxes.js
src/converse-chatboxes.js
+15
-2
No files found.
spec/messages.js
View file @
15df9b86
...
...
@@ -269,7 +269,6 @@
}));
it
(
"
can be received out of order, and will still be displayed in the right order
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
...
...
@@ -1202,59 +1201,6 @@
});
}));
describe
(
"
in which someone is mentioned
"
,
function
()
{
it
(
"
includes XEP-0372 references to that person
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
lounge
'
,
'
localhost
'
,
'
tom
'
)
.
then
(()
=>
{
const
view
=
_converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
[
'
z3r0
'
,
'
mr.robot
'
,
'
gibson
'
,
'
sw0rdf1sh
'
].
forEach
((
nick
)
=>
{
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
$pres
({
'
to
'
:
'
tom@localhost/resource
'
,
'
from
'
:
`lounge@localhost/
${
nick
}
`
})
.
c
(
'
x
'
,
{
xmlns
:
Strophe
.
NS
.
MUC_USER
})
.
c
(
'
item
'
,
{
'
affiliation
'
:
'
none
'
,
'
jid
'
:
`
${
nick
}
@localhost/resource`
,
'
role
'
:
'
participant
'
})));
});
let
[
text
,
references
]
=
view
.
model
.
parseForReferences
(
'
hello z3r0
'
)
expect
(
references
.
length
).
toBe
(
0
);
expect
(
text
).
toBe
(
'
hello z3r0
'
);
[
text
,
references
]
=
view
.
model
.
parseForReferences
(
'
hello @z3r0
'
)
expect
(
references
.
length
).
toBe
(
1
);
expect
(
text
).
toBe
(
'
hello z3r0
'
);
expect
(
JSON
.
stringify
(
references
))
.
toBe
(
'
[{"begin":6,"end":10,"type":"mention","uri":"xmpp:z3r0@localhost"}]
'
);
[
text
,
references
]
=
view
.
model
.
parseForReferences
(
'
hello @some1 @z3r0 @gibson @mr.robot, how are you?
'
)
expect
(
text
).
toBe
(
'
hello @some1 z3r0 gibson mr.robot, how are you?
'
);
expect
(
JSON
.
stringify
(
references
))
.
toBe
(
'
[{"begin":13,"end":17,"type":"mention","uri":"xmpp:z3r0@localhost"},
'
+
'
{"begin":18,"end":24,"type":"mention","uri":"xmpp:gibson@localhost"},
'
+
'
{"begin":25,"end":33,"type":"mention","uri":"xmpp:mr.robot@localhost"}]
'
);
[
text
,
references
]
=
view
.
model
.
parseForReferences
(
'
yo @gib
'
)
expect
(
text
).
toBe
(
'
yo @gib
'
);
expect
(
references
.
length
).
toBe
(
0
);
[
text
,
references
]
=
view
.
model
.
parseForReferences
(
'
yo @gibsonian
'
)
expect
(
text
).
toBe
(
'
yo @gibsonian
'
);
expect
(
references
.
length
).
toBe
(
0
);
done
();
}).
catch
(
_
.
partial
(
console
.
error
,
_
));
}));
});
describe
(
"
when received from someone else
"
,
function
()
{
...
...
@@ -2142,5 +2088,115 @@
done
();
}).
catch
(
_
.
partial
(
console
.
error
,
_
));
}));
describe
(
"
in which someone is mentioned
"
,
function
()
{
it
(
"
gets parsed for mentions which get turned into references
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
lounge
'
,
'
localhost
'
,
'
tom
'
)
.
then
(()
=>
{
const
view
=
_converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
[
'
z3r0
'
,
'
mr.robot
'
,
'
gibson
'
,
'
sw0rdf1sh
'
].
forEach
((
nick
)
=>
{
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
$pres
({
'
to
'
:
'
tom@localhost/resource
'
,
'
from
'
:
`lounge@localhost/
${
nick
}
`
})
.
c
(
'
x
'
,
{
xmlns
:
Strophe
.
NS
.
MUC_USER
})
.
c
(
'
item
'
,
{
'
affiliation
'
:
'
none
'
,
'
jid
'
:
`
${
nick
}
@localhost/resource`
,
'
role
'
:
'
participant
'
})));
});
// Run a few unit tests for the parseForReferences method
let
[
text
,
references
]
=
view
.
model
.
parseForReferences
(
'
hello z3r0
'
)
expect
(
references
.
length
).
toBe
(
0
);
expect
(
text
).
toBe
(
'
hello z3r0
'
);
[
text
,
references
]
=
view
.
model
.
parseForReferences
(
'
hello @z3r0
'
)
expect
(
references
.
length
).
toBe
(
1
);
expect
(
text
).
toBe
(
'
hello z3r0
'
);
expect
(
JSON
.
stringify
(
references
))
.
toBe
(
'
[{"begin":6,"end":10,"type":"mention","uri":"xmpp:z3r0@localhost"}]
'
);
[
text
,
references
]
=
view
.
model
.
parseForReferences
(
'
hello @some1 @z3r0 @gibson @mr.robot, how are you?
'
)
expect
(
text
).
toBe
(
'
hello @some1 z3r0 gibson mr.robot, how are you?
'
);
expect
(
JSON
.
stringify
(
references
))
.
toBe
(
'
[{"begin":13,"end":17,"type":"mention","uri":"xmpp:z3r0@localhost"},
'
+
'
{"begin":18,"end":24,"type":"mention","uri":"xmpp:gibson@localhost"},
'
+
'
{"begin":25,"end":33,"type":"mention","uri":"xmpp:mr.robot@localhost"}]
'
);
[
text
,
references
]
=
view
.
model
.
parseForReferences
(
'
yo @gib
'
)
expect
(
text
).
toBe
(
'
yo @gib
'
);
expect
(
references
.
length
).
toBe
(
0
);
[
text
,
references
]
=
view
.
model
.
parseForReferences
(
'
yo @gibsonian
'
)
expect
(
text
).
toBe
(
'
yo @gibsonian
'
);
expect
(
references
.
length
).
toBe
(
0
);
[
text
,
references
]
=
view
.
model
.
parseForReferences
(
'
@gibson
'
)
expect
(
text
).
toBe
(
'
gibson
'
);
expect
(
references
.
length
).
toBe
(
1
);
expect
(
JSON
.
stringify
(
references
))
.
toBe
(
'
[{"begin":0,"end":6,"type":"mention","uri":"xmpp:gibson@localhost"}]
'
);
done
();
return
;
});
}));
it
(
"
includes XEP-0372 references to that person
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
test_utils
.
openAndEnterChatRoom
(
_converse
,
'
lounge
'
,
'
localhost
'
,
'
tom
'
)
.
then
(()
=>
{
const
view
=
_converse
.
chatboxviews
.
get
(
'
lounge@localhost
'
);
[
'
z3r0
'
,
'
mr.robot
'
,
'
gibson
'
,
'
sw0rdf1sh
'
].
forEach
((
nick
)
=>
{
_converse
.
connection
.
_dataRecv
(
test_utils
.
createRequest
(
$pres
({
'
to
'
:
'
tom@localhost/resource
'
,
'
from
'
:
`lounge@localhost/
${
nick
}
`
})
.
c
(
'
x
'
,
{
xmlns
:
Strophe
.
NS
.
MUC_USER
})
.
c
(
'
item
'
,
{
'
affiliation
'
:
'
none
'
,
'
jid
'
:
`
${
nick
}
@localhost/resource`
,
'
role
'
:
'
participant
'
})));
});
spyOn
(
_converse
.
connection
,
'
send
'
);
const
textarea
=
view
.
el
.
querySelector
(
'
textarea.chat-textarea
'
);
textarea
.
value
=
'
hello @z3r0 @gibson @mr.robot, how are you?
'
const
enter_event
=
{
'
target
'
:
textarea
,
'
preventDefault
'
:
_
.
noop
,
'
stopPropagation
'
:
_
.
noop
,
'
keyCode
'
:
13
// Enter
}
view
.
keyPressed
(
enter_event
);
const
msg
=
_converse
.
connection
.
send
.
calls
.
all
()[
0
].
args
[
0
];
expect
(
msg
.
toLocaleString
())
.
toBe
(
`<message from='dummy@localhost/resource' `
+
`to='lounge@localhost' type='groupchat' id='
${
msg
.
nodeTree
.
getAttribute
(
'
id
'
)}
' `
+
`xmlns='jabber:client'>`
+
`<body>hello z3r0 gibson mr.robot, how are you?</body>`
+
`<active xmlns='http://jabber.org/protocol/chatstates'/>`
+
`<reference xmlns='urn:xmpp:reference:0' begin='6' end='10' type='mention' uri='xmpp:z3r0@localhost'/>`
+
`<reference xmlns='urn:xmpp:reference:0' begin='11' end='17' type='mention' uri='xmpp:gibson@localhost'/>`
+
`<reference xmlns='urn:xmpp:reference:0' begin='18' end='26' type='mention' uri='xmpp:mr.robot@localhost'/>`
+
`</message>`
);
done
();
}).
catch
(
_
.
partial
(
console
.
error
,
_
));
}));
});
});
}));
src/converse-chatboxes.js
View file @
15df9b86
...
...
@@ -20,6 +20,7 @@
const
u
=
converse
.
env
.
utils
;
Strophe
.
addNamespace
(
'
MESSAGE_CORRECT
'
,
'
urn:xmpp:message-correct:0
'
);
Strophe
.
addNamespace
(
'
REFERENCE
'
,
'
urn:xmpp:reference:0
'
);
converse
.
plugins
.
add
(
'
converse-chatboxes
'
,
{
...
...
@@ -323,11 +324,23 @@
if
(
message
.
get
(
'
is_spoiler
'
))
{
if
(
message
.
get
(
'
spoiler_hint
'
))
{
stanza
.
c
(
'
spoiler
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
SPOILER
},
message
.
get
(
'
spoiler_hint
'
)).
up
();
stanza
.
c
(
'
spoiler
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
SPOILER
},
message
.
get
(
'
spoiler_hint
'
)).
up
();
}
else
{
stanza
.
c
(
'
spoiler
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
SPOILER
}).
up
();
stanza
.
c
(
'
spoiler
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
SPOILER
}).
up
();
}
}
(
message
.
get
(
'
references
'
)
||
[]).
forEach
(
reference
=>
{
const
attrs
=
{
'
xmlns
'
:
Strophe
.
NS
.
REFERENCE
,
'
begin
'
:
reference
.
begin
,
'
end
'
:
reference
.
end
,
'
type
'
:
reference
.
type
,
}
if
(
reference
.
uri
)
{
attrs
.
uri
=
reference
.
uri
;
}
stanza
.
c
(
'
reference
'
,
attrs
).
up
();
});
if
(
message
.
get
(
'
file
'
))
{
stanza
.
c
(
'
x
'
,
{
'
xmlns
'
:
Strophe
.
NS
.
OUTOFBAND
}).
c
(
'
url
'
).
t
(
message
.
get
(
'
message
'
)).
up
();
}
...
...
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