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
2db3db9b
Commit
2db3db9b
authored
Aug 16, 2018
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for editing messages containing mentions
parent
d9c5867f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
8 deletions
+96
-8
spec/messages.js
spec/messages.js
+76
-3
src/converse-chatboxes.js
src/converse-chatboxes.js
+3
-2
src/converse-chatview.js
src/converse-chatview.js
+1
-1
src/converse-message-view.js
src/converse-message-view.js
+1
-1
src/converse-muc-views.js
src/converse-muc-views.js
+1
-0
src/utils/core.js
src/utils/core.js
+14
-1
No files found.
spec/messages.js
View file @
2db3db9b
...
...
@@ -2091,7 +2091,7 @@
describe
(
"
when received
"
,
function
()
{
it
(
"
highlights all users mentioned via XEP-0372 references
"
,
it
(
"
highlights all users mentioned via XEP-0372 references
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
...
...
@@ -2137,7 +2137,7 @@
describe
(
"
in which someone is mentioned
"
,
function
()
{
it
(
"
gets parsed for mentions which get turned into references
"
,
it
(
"
gets parsed for mentions which get turned into references
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
function
(
done
,
_converse
)
{
...
...
@@ -2190,12 +2190,85 @@
expect
(
references
.
length
).
toBe
(
1
);
expect
(
JSON
.
stringify
(
references
))
.
toBe
(
'
[{"begin":0,"end":6,"value":"gibson","type":"mention","uri":"xmpp:gibson@localhost"}]
'
);
done
();
return
;
});
}));
it
(
"
can get corrected and given new 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
'
})));
});
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
}
spyOn
(
_converse
.
connection
,
'
send
'
);
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='18' end='26' type='mention' uri='xmpp:mr.robot@localhost'/>`
+
`<reference xmlns='urn:xmpp:reference:0' begin='11' end='17' type='mention' uri='xmpp:gibson@localhost'/>`
+
`<reference xmlns='urn:xmpp:reference:0' begin='6' end='10' type='mention' uri='xmpp:z3r0@localhost'/>`
+
`</message>`
);
const
first_msg
=
view
.
model
.
messages
.
findWhere
({
'
message
'
:
'
hello z3r0 gibson mr.robot, how are you?
'
});
const
action
=
view
.
el
.
querySelector
(
'
.chat-msg .chat-msg__action
'
);
action
.
style
.
opacity
=
1
;
action
.
click
();
expect
(
textarea
.
value
).
toBe
(
'
hello @z3r0 @gibson @mr.robot, how are you?
'
);
expect
(
view
.
model
.
messages
.
at
(
0
).
get
(
'
correcting
'
)).
toBe
(
true
);
expect
(
view
.
el
.
querySelectorAll
(
'
.chat-msg
'
).
length
).
toBe
(
1
);
expect
(
u
.
hasClass
(
'
correcting
'
,
view
.
el
.
querySelector
(
'
.chat-msg
'
))).
toBe
(
true
);
textarea
.
value
=
'
hello @z3r0 @gibson @sw0rdf1sh, how are you?
'
;
view
.
keyPressed
(
enter_event
);
const
correction
=
_converse
.
connection
.
send
.
calls
.
all
()[
1
].
args
[
0
];
expect
(
correction
.
toLocaleString
())
.
toBe
(
`<message from='dummy@localhost/resource' `
+
`to='lounge@localhost' type='groupchat' id='
${
correction
.
nodeTree
.
getAttribute
(
'
id
'
)}
' `
+
`xmlns='jabber:client'>`
+
`<body>hello z3r0 gibson sw0rdf1sh, how are you?</body>`
+
`<active xmlns='http://jabber.org/protocol/chatstates'/>`
+
`<reference xmlns='urn:xmpp:reference:0' begin='18' end='27' type='mention' uri='xmpp:sw0rdf1sh@localhost'/>`
+
`<reference xmlns='urn:xmpp:reference:0' begin='11' end='17' type='mention' uri='xmpp:gibson@localhost'/>`
+
`<reference xmlns='urn:xmpp:reference:0' begin='6' end='10' type='mention' uri='xmpp:z3r0@localhost'/>`
+
`<replace xmlns='urn:xmpp:message-correct:0' id='
${
msg
.
nodeTree
.
getAttribute
(
'
id
'
)}
'/>`
+
`</message>`
);
done
();
}).
catch
(
_
.
partial
(
console
.
error
,
_
));
}));
it
(
"
includes XEP-0372 references to that person
"
,
mock
.
initConverseWithPromises
(
null
,
[
'
rosterGroupsFetched
'
],
{},
...
...
src/converse-chatboxes.js
View file @
2db3db9b
...
...
@@ -400,10 +400,11 @@
const
older_versions
=
message
.
get
(
'
older_versions
'
)
||
[];
older_versions
.
push
(
message
.
get
(
'
message
'
));
message
.
save
({
'
correcting
'
:
false
,
'
edited
'
:
true
,
'
message
'
:
attrs
.
message
,
'
older_versions
'
:
older_versions
,
'
edited
'
:
true
,
'
correcting
'
:
false
'
references
'
:
attrs
.
references
});
return
this
.
sendMessageStanza
(
message
);
}
...
...
src/converse-chatview.js
View file @
2db3db9b
...
...
@@ -970,7 +970,7 @@
currently_correcting
.
save
(
'
correcting
'
,
false
);
}
message
.
save
(
'
correcting
'
,
true
);
this
.
insertIntoTextArea
(
message
.
get
(
'
message
'
),
true
,
true
);
this
.
insertIntoTextArea
(
u
.
prefixMentions
(
message
),
true
,
true
);
}
else
{
message
.
save
(
'
correcting
'
,
false
);
this
.
insertIntoTextArea
(
''
,
true
,
false
);
...
...
src/converse-message-view.js
View file @
2db3db9b
...
...
@@ -167,7 +167,7 @@
text
=
xss
.
filterXSS
(
text
,
{
'
whiteList
'
:
{}});
msg_content
.
innerHTML
=
_
.
flow
(
_
.
partial
(
u
.
geoUriToHttp
,
_
,
_converse
.
geouri_replacement
),
_
.
partial
(
u
.
addMentions
,
_
,
this
.
model
.
get
(
'
references
'
),
this
.
model
.
collection
.
chatbox
),
_
.
partial
(
u
.
addMentions
Markup
,
_
,
this
.
model
.
get
(
'
references
'
),
this
.
model
.
collection
.
chatbox
),
u
.
addHyperlinks
,
u
.
renderNewLines
,
_
.
partial
(
u
.
addEmoji
,
_converse
,
emojione
,
_
)
...
...
src/converse-muc-views.js
View file @
2db3db9b
...
...
@@ -518,6 +518,7 @@
is_chatroom
:
true
,
events
:
{
'
change input.fileupload
'
:
'
onFileSelection
'
,
'
click .chat-msg__action-edit
'
:
'
onMessageEditButtonClicked
'
,
'
click .chatbox-navback
'
:
'
showControlBox
'
,
'
click .close-chatbox-button
'
:
'
close
'
,
'
click .configure-chatroom-button
'
:
'
getAndRenderConfigurationForm
'
,
...
...
src/utils/core.js
View file @
2db3db9b
...
...
@@ -229,7 +229,20 @@
return
encodeURI
(
decodeURI
(
url
)).
replace
(
/
[
!'()
]
/g
,
escape
).
replace
(
/
\*
/g
,
"
%2A
"
);
};
u
.
addMentions
=
function
(
text
,
references
,
chatbox
)
{
u
.
prefixMentions
=
function
(
message
)
{
/* Given a message object, return its text with @ chars
* inserted before the mentioned nicknames.
*/
let
text
=
message
.
get
(
'
message
'
);
(
message
.
get
(
'
references
'
)
||
[])
.
sort
((
a
,
b
)
=>
b
.
begin
-
a
.
begin
)
.
forEach
(
ref
=>
{
text
=
`
${
text
.
slice
(
0
,
ref
.
begin
)}
@
${
text
.
slice
(
ref
.
begin
)}
`
});
return
text
;
};
u
.
addMentionsMarkup
=
function
(
text
,
references
,
chatbox
)
{
if
(
chatbox
.
get
(
'
message_type
'
)
!==
'
groupchat
'
)
{
return
text
;
}
...
...
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