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
eae70669
Commit
eae70669
authored
Jul 04, 2015
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed some methods and added docstrings, for clarity.
parent
761fe942
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
18 deletions
+33
-18
converse.js
converse.js
+29
-15
spec/chatbox.js
spec/chatbox.js
+4
-3
No files found.
converse.js
View file @
eae70669
...
...
@@ -1094,7 +1094,7 @@
this
.
trigger
(
'
showReceivedOTRMessage
'
,
msg
);
}.
bind
(
this
));
this
.
otr
.
on
(
'
io
'
,
function
(
msg
)
{
this
.
trigger
(
'
sendMessage
Stanza
'
,
msg
);
this
.
trigger
(
'
sendMessage
'
,
msg
);
}.
bind
(
this
));
this
.
otr
.
on
(
'
error
'
,
function
(
msg
)
{
this
.
trigger
(
'
showOTRError
'
,
msg
);
...
...
@@ -1218,7 +1218,7 @@
this
.
model
.
on
(
'
change:status
'
,
this
.
onStatusChanged
,
this
);
this
.
model
.
on
(
'
showOTRError
'
,
this
.
showOTRError
,
this
);
this
.
model
.
on
(
'
showHelpMessages
'
,
this
.
showHelpMessages
,
this
);
this
.
model
.
on
(
'
sendMessage
Stanza
'
,
this
.
sendMessageStanza
,
this
);
this
.
model
.
on
(
'
sendMessage
'
,
this
.
sendMessage
,
this
);
this
.
model
.
on
(
'
showSentOTRMessage
'
,
function
(
text
)
{
this
.
showMessage
({
'
message
'
:
text
,
'
sender
'
:
'
me
'
});
},
this
);
...
...
@@ -1372,12 +1372,14 @@
}
},
sendMessageStanza
:
function
(
text
)
{
/* Sends the actual XML stanza to the XMPP server.
sendMessage
:
function
(
text
)
{
/* Responsible for sending off a text message.
*
* Parameters:
* (string) text - The chat message text.
*/
// TODO: Look in ChatPartners to see what resources we have for the recipient.
// if we have one resource, we sent to only that resources, if we have multiple
// we send to the bare jid.
// TODO: We might want to send to specfic resources. Especially
// in the OTR case.
var
timestamp
=
(
new
Date
()).
getTime
();
var
bare_jid
=
this
.
model
.
get
(
'
jid
'
);
var
message
=
$msg
({
from
:
converse
.
connection
.
jid
,
to
:
bare_jid
,
type
:
'
chat
'
,
id
:
timestamp
})
...
...
@@ -1388,7 +1390,6 @@
// OTR messages aren't carbon copied
message
.
c
(
'
private
'
,
{
'
xmlns
'
:
'
urn:xmpp:carbons:2
'
});
}
converse
.
connection
.
send
(
message
);
if
(
converse
.
forward_messages
)
{
// Forward the message, so that other connected resources are also aware of it.
...
...
@@ -1400,7 +1401,13 @@
}
},
sendMessage
:
function
(
text
)
{
onMessageSubmitted
:
function
(
text
)
{
/* This method gets called once the user has typed a message
* and then pressed enter in a chat box.
*
* Parameters:
* (string) text - The chat message text.
*/
if
(
!
converse
.
connection
.
authenticated
)
{
return
this
.
showHelpMessages
([
'
Sorry, the connection has been lost, and your message could not be sent
'
],
'
error
'
);
}
...
...
@@ -1437,7 +1444,7 @@
time
:
moment
().
format
(),
message
:
text
});
this
.
sendMessage
Stanza
(
text
);
this
.
sendMessage
(
text
);
}
},
...
...
@@ -1491,9 +1498,9 @@
$textarea
.
val
(
''
).
focus
();
if
(
message
!==
''
)
{
if
(
this
.
model
.
get
(
'
chatroom
'
))
{
this
.
sendChatRoomMessage
(
message
);
this
.
onChatRoomMessageSubmitted
(
message
);
}
else
{
this
.
sendMessage
(
message
);
this
.
onMessageSubmitted
(
message
);
}
converse
.
emit
(
'
messageSend
'
,
message
);
}
...
...
@@ -2644,7 +2651,7 @@
this
.
showStatusNotification
(
__
(
"
Error: could not execute the command
"
),
true
);
},
create
ChatRoomMessage
:
function
(
text
)
{
send
ChatRoomMessage
:
function
(
text
)
{
var
msgid
=
converse
.
connection
.
getUniqueId
();
var
msg
=
$msg
({
to
:
this
.
model
.
get
(
'
jid
'
),
...
...
@@ -2692,7 +2699,13 @@
return
this
.
setAffiliation
(
room
,
jid
,
'
admin
'
,
reason
,
handler_cb
,
error_cb
);
},
sendChatRoomMessage
:
function
(
text
)
{
onChatRoomMessageSubmitted
:
function
(
text
)
{
/* Gets called when the user presses enter to send off a
* message in a chat room.
*
* Parameters:
* (String) text - The message text.
*/
var
match
=
text
.
replace
(
/^
\s
*/
,
""
).
match
(
/^
\/(
.*
?)(?:
(
.*
))?
$/
)
||
[
false
,
''
,
''
];
var
args
=
match
[
2
].
splitOnce
(
'
'
);
switch
(
match
[
1
])
{
...
...
@@ -2785,7 +2798,7 @@
undefined
,
this
.
onCommandError
.
bind
(
this
));
break
;
default
:
this
.
create
ChatRoomMessage
(
text
);
this
.
send
ChatRoomMessage
(
text
);
break
;
}
},
...
...
@@ -3718,6 +3731,7 @@
subscribe
:
function
(
message
)
{
/* Send a presence subscription request to this roster contact
*
* Parameters:
* (String) message - An optional message to explain the
* reason for the subscription request.
...
...
spec/chatbox.js
View file @
eae70669
...
...
@@ -779,11 +779,12 @@
var
chatbox
=
converse
.
chatboxes
.
get
(
sender_jid
);
spyOn
(
converse
.
connection
,
'
send
'
);
chatbox
.
set
(
'
otr_status
'
,
1
);
// Set OTR status to UNVERIFIED, to mock an encrypted session
chatbox
.
trigger
(
'
sendMessage
Stanza
'
,
msgtext
);
chatbox
.
trigger
(
'
sendMessage
'
,
msgtext
);
var
$sent
=
$
(
converse
.
connection
.
send
.
argsForCall
[
0
][
0
].
tree
());
expect
(
$sent
.
find
(
'
body
'
).
siblings
(
'
private
'
).
length
).
toBe
(
1
);
expect
(
$sent
.
find
(
'
private
'
).
length
).
toBe
(
1
);
expect
(
$sent
.
find
(
'
private
'
).
attr
(
'
xmlns
'
)).
toBe
(
'
urn:xmpp:carbons:2
'
);
chatbox
.
set
(
'
otr_status
'
,
0
);
// Reset again to UNENCRYPTED
});
});
...
...
@@ -1090,13 +1091,13 @@
message
=
'
/clear
'
;
var
old_length
=
view
.
model
.
messages
.
length
;
spyOn
(
view
,
'
sendMessage
'
).
andCallThrough
();
spyOn
(
view
,
'
onMessageSubmitted
'
).
andCallThrough
();
spyOn
(
view
,
'
clearMessages
'
).
andCallThrough
();
spyOn
(
window
,
'
confirm
'
).
andCallFake
(
function
()
{
return
true
;
});
test_utils
.
sendMessage
(
view
,
message
);
expect
(
view
.
sendMessage
).
toHaveBeenCalled
();
expect
(
view
.
onMessageSubmitted
).
toHaveBeenCalled
();
expect
(
view
.
clearMessages
).
toHaveBeenCalled
();
expect
(
window
.
confirm
).
toHaveBeenCalled
();
expect
(
view
.
model
.
messages
.
length
,
0
);
// The messages must be removed from the chatbox
...
...
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