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
e0a58efc
Commit
e0a58efc
authored
May 27, 2015
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Linting and code formatting.
Also use and add a Strophe namespace for CSI.
parent
c7ce646f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
73 deletions
+70
-73
converse.js
converse.js
+70
-73
No files found.
converse.js
View file @
e0a58efc
...
@@ -156,6 +156,7 @@
...
@@ -156,6 +156,7 @@
Strophe
.
addNamespace
(
'
REGISTER
'
,
'
jabber:iq:register
'
);
Strophe
.
addNamespace
(
'
REGISTER
'
,
'
jabber:iq:register
'
);
Strophe
.
addNamespace
(
'
ROSTERX
'
,
'
http://jabber.org/protocol/rosterx
'
);
Strophe
.
addNamespace
(
'
ROSTERX
'
,
'
http://jabber.org/protocol/rosterx
'
);
Strophe
.
addNamespace
(
'
XFORM
'
,
'
jabber:x:data
'
);
Strophe
.
addNamespace
(
'
XFORM
'
,
'
jabber:x:data
'
);
Strophe
.
addNamespace
(
'
CSI
'
,
'
urn:xmpp:csi:0
'
);
// Add Strophe Statuses
// Add Strophe Statuses
var
i
=
0
;
var
i
=
0
;
...
@@ -384,59 +385,52 @@
...
@@ -384,59 +385,52 @@
// Module-level functions
// Module-level functions
// ----------------------
// ----------------------
this
.
autoAwayReset
=
function
(){
this
.
sendCSI
=
function
(
stat
)
{
if
(
converse
.
_idleCounter
>
0
)
{
converse
.
_idleCounter
=
0
;
if
(
converse
.
_autoAway
>
0
)
{
converse
.
_autoAway
=
0
;
if
(
converse
.
HAS_CSI
)
{
if
(
converse
.
HAS_CSI
)
{
converse
.
connection
.
send
(
$build
(
"
active
"
,
{
xmlns
:
'
urn:xmpp:csi:0
'
}));
converse
.
connection
.
send
(
$build
(
stat
,
{
xmlns
:
Strophe
.
NS
.
CSI
}));
}
}
};
this
.
autoAwayReset
=
function
()
{
if
(
converse
.
_idleCounter
>
0
)
{
converse
.
_idleCounter
=
0
;
if
(
converse
.
_autoAway
>
0
)
{
converse
.
_autoAway
=
0
;
converse
.
sendCSI
(
ACTIVE
);
converse
.
xmppstatus
.
setStatus
(
'
online
'
);
converse
.
xmppstatus
.
setStatus
(
'
online
'
);
}
}
}
}
};
};
this
.
registerAutoAwayHandler
=
function
(){
this
.
registerAutoAwayHandler
=
function
()
{
// TODO: we should probably come up with a way to decouple CSI and auto-away
if
(
this
.
auto_away
>
0
||
this
.
auto_xa
>
0
)
{
if
(
converse
.
auto_away
>
0
||
converse
.
auto_xa
>
0
){
this
.
HAS_CSI
=
this
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
CSI
})
?
true
:
false
;
if
(
this
.
auto_xa
>
0
&&
this
.
auto_xa
<
this
.
auto_away
)
{
if
(
converse
.
features
.
findWhere
({
'
var
'
:
'
urn:xmpp:csi
'
}))
{
this
.
auto_xa
=
this
.
auto_away
;
// The server supports XEP-0352 Client State Indication
}
converse
.
HAS_CSI
=
true
;
this
.
_idleCounter
=
0
;
}
else
{
this
.
_autoAway
=
0
;
converse
.
HAS_CSI
=
false
;
$
(
window
).
on
(
'
click
'
,
function
()
{
converse
.
autoAwayReset
();
});
}
$
(
window
).
on
(
'
mousemove
'
,
function
()
{
converse
.
autoAwayReset
();
});
if
(
converse
.
auto_xa
>
0
&&
converse
.
auto_xa
<
converse
.
auto_away
)
converse
.
auto_xa
=
converse
.
auto_away
;
$
(
window
).
on
(
'
keypress
'
,
function
()
{
converse
.
autoAwayReset
();
});
converse
.
_idleCounter
=
0
;
$
(
window
).
on
(
'
focus
'
,
function
()
{
converse
.
autoAwayReset
();
});
converse
.
_autoAway
=
0
;
$
(
window
).
on
(
'
beforeunload
'
,
function
()
{
converse
.
autoAwayReset
();
});
$
(
window
).
on
(
'
click
'
,
function
(){
converse
.
autoAwayReset
()});
$
(
window
).
on
(
'
mousemove
'
,
function
(){
converse
.
autoAwayReset
()});
$
(
window
).
on
(
'
keypress
'
,
function
(){
converse
.
autoAwayReset
()});
$
(
window
).
on
(
'
focus
'
,
function
(){
converse
.
autoAwayReset
()});
$
(
window
).
on
(
'
beforeunload
'
,
function
(){
converse
.
autoAwayReset
()});
window
.
setInterval
(
function
()
{
window
.
setInterval
(
function
()
{
if
((
converse
.
_idleCounter
<=
converse
.
auto_away
||
(
converse
.
auto_xa
>
0
&&
converse
.
_idleCounter
<=
converse
.
auto_xa
))
&&
if
((
this
.
_idleCounter
<=
this
.
auto_away
||
(
this
.
auto_xa
>
0
&&
this
.
_idleCounter
<=
this
.
auto_xa
))
&&
(
converse
.
xmppstatus
.
get
(
'
status
'
)
==
'
online
'
&&
converse
.
_autoAway
==
0
)
||
(
converse
.
xmppstatus
.
get
(
'
status
'
)
==
'
away
'
&&
converse
.
_autoAway
==
1
)
){
(
this
.
xmppstatus
.
get
(
'
status
'
)
==
'
online
'
&&
this
.
_autoAway
===
0
)
||
(
this
.
xmppstatus
.
get
(
'
status
'
)
==
'
away
'
&&
this
.
_autoAway
==
1
)
){
converse
.
_idleCounter
++
;
this
.
_idleCounter
++
;
}
if
(
converse
.
auto_away
>
0
&&
converse
.
_autoAway
!=
1
&&
converse
.
_idleCounter
>
converse
.
auto_away
&&
converse
.
_idleCounter
<=
converse
.
auto_xa
){
if
(
converse
.
HAS_CSI
)
{
converse
.
connection
.
send
(
$build
(
"
inactive
"
,
{
xmlns
:
'
urn:xmpp:csi:0
'
}));
}
converse
.
_autoAway
=
1
;
converse
.
xmppstatus
.
setStatus
(
'
away
'
);
}
}
else
if
(
converse
.
auto_xa
>
0
&&
converse
.
_autoAway
!=
2
&&
converse
.
_idleCounter
>
converse
.
auto_xa
){
if
(
this
.
auto_away
>
0
&&
this
.
_autoAway
!=
1
&&
this
.
_idleCounter
>
this
.
auto_away
&&
this
.
_idleCounter
<=
this
.
auto_xa
){
if
(
converse
.
HAS_CSI
)
{
this
.
sendCSI
(
INACTIVE
);
converse
.
connection
.
send
(
$build
(
"
inactive
"
,
{
xmlns
:
'
urn:xmpp:csi:0
'
}));
this
.
_autoAway
=
1
;
this
.
xmppstatus
.
setStatus
(
'
away
'
);
}
}
converse
.
_autoAway
=
2
;
else
if
(
this
.
auto_xa
>
0
&&
this
.
_autoAway
!=
2
&&
this
.
_idleCounter
>
this
.
auto_xa
){
converse
.
xmppstatus
.
setStatus
(
'
xa
'
);
this
.
sendCSI
(
INACTIVE
);
this
.
_autoAway
=
2
;
this
.
xmppstatus
.
setStatus
(
'
xa
'
);
}
}
},
1000
);
//every seconds
}
.
bind
(
this
)
,
1000
);
//every seconds
return
true
;
return
true
;
}
}
};
};
...
@@ -444,7 +438,7 @@
...
@@ -444,7 +438,7 @@
this
.
playNotification
=
function
()
{
this
.
playNotification
=
function
()
{
var
audio
;
var
audio
;
if
(
converse
.
play_sounds
&&
typeof
Audio
!==
"
undefined
"
){
if
(
converse
.
play_sounds
&&
typeof
Audio
!==
"
undefined
"
)
{
audio
=
new
Audio
(
converse
.
sounds_path
+
"
msg_received.ogg
"
);
audio
=
new
Audio
(
converse
.
sounds_path
+
"
msg_received.ogg
"
);
if
(
audio
.
canPlayType
(
'
/audio/ogg
'
))
{
if
(
audio
.
canPlayType
(
'
/audio/ogg
'
))
{
audio
.
play
();
audio
.
play
();
...
@@ -725,44 +719,47 @@
...
@@ -725,44 +719,47 @@
},
this
),
200
));
},
this
),
200
));
};
};
this
.
ping
=
function
(
jid
,
success
,
error
,
timeout
){
this
.
ping
=
function
(
jid
,
success
,
error
,
timeout
)
{
//var feature = converse.features.findWhere({'var': Strophe.NS.PING});
// XXX: We could first check here if the server advertised that it supports PING.
//if (feature) {
// However, some servers don't advertise while still keeping the
converse
.
lastMessage
=
new
Date
();
// connection option due to pings.
if
(
typeof
jid
===
'
undefined
'
||
jid
==
null
)
{
jid
=
converse
.
bare_jid
;
}
//
// var feature = converse.features.findWhere({'var': Strophe.NS.PING});
converse
.
lastMessage
=
new
Date
();
if
(
typeof
jid
===
'
undefined
'
||
jid
===
null
)
{
jid
=
converse
.
bare_jid
;
}
if
(
typeof
timeout
===
'
undefined
'
)
{
timeout
=
null
;
}
if
(
typeof
timeout
===
'
undefined
'
)
{
timeout
=
null
;
}
if
(
typeof
success
===
'
undefined
'
)
{
success
=
null
;
}
if
(
typeof
success
===
'
undefined
'
)
{
success
=
null
;
}
if
(
typeof
error
===
'
undefined
'
)
{
error
=
null
;
}
if
(
typeof
error
===
'
undefined
'
)
{
error
=
null
;
}
if
(
converse
.
connection
)
{
if
(
converse
.
connection
)
{
converse
.
connection
.
ping
.
ping
(
jid
,
success
,
error
,
timeout
);
converse
.
connection
.
ping
.
ping
(
jid
,
success
,
error
,
timeout
);
return
true
return
true
;
};
}
//}
return
false
;
return
false
;
};
};
this
.
pong
=
function
(
ping
){
this
.
pong
=
function
(
ping
)
{
converse
.
lastMessage
=
new
Date
();
converse
.
lastMessage
=
new
Date
();
converse
.
connection
.
ping
.
pong
(
ping
);
converse
.
connection
.
ping
.
pong
(
ping
);
return
true
;
return
true
;
};
};
this
.
registerPongHandler
=
function
(){
this
.
registerPongHandler
=
function
()
{
var
feature
=
converse
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
PING
});
if
(
converse
.
features
.
findWhere
({
'
var
'
:
Strophe
.
NS
.
PING
}))
{
if
(
feature
)
{
converse
.
connection
.
disco
.
addFeature
(
Strophe
.
NS
.
PING
);
converse
.
connection
.
disco
.
addFeature
(
Strophe
.
NS
.
PING
);
converse
.
connection
.
ping
.
addPingHandler
(
this
.
pong
);
converse
.
connection
.
ping
.
addPingHandler
(
this
.
pong
);
}
}
};
};
this
.
registerPingHandler
=
function
(){
this
.
registerPingHandler
=
function
()
{
if
(
this
.
ping_interval
>
0
)
{
if
(
this
.
ping_interval
>
0
)
{
//handler on each message : save last message date in order to ping only when needed
//handler on each message : save last message date in order to ping only when needed
converse
.
connection
.
addHandler
(
function
(){
converse
.
lastMessage
=
new
Date
();});
converse
.
connection
.
addHandler
(
function
()
{
converse
.
lastMessage
=
new
Date
();});
converse
.
connection
.
addTimedHandler
(
1000
,
function
()
{
converse
.
connection
.
addTimedHandler
(
1000
,
function
()
{
now
=
new
Date
();
now
=
new
Date
();
if
(
!
converse
.
lastMessage
)
converse
.
lastMessage
=
now
;
if
(
!
converse
.
lastMessage
)
{
if
((
now
-
converse
.
lastMessage
)
/
1000
>
converse
.
ping_interval
){
converse
.
lastMessage
=
now
;
}
if
((
now
-
converse
.
lastMessage
)
/
1000
>
converse
.
ping_interval
)
{
return
converse
.
ping
();
return
converse
.
ping
();
}
}
return
true
;
return
true
;
...
@@ -1144,7 +1141,7 @@
...
@@ -1144,7 +1141,7 @@
'
mousedown .dragresize-tm
'
:
'
onDragResizeStart
'
'
mousedown .dragresize-tm
'
:
'
onDragResizeStart
'
},
},
initialize
:
function
(){
initialize
:
function
()
{
this
.
model
.
messages
.
on
(
'
add
'
,
this
.
onMessageAdded
,
this
);
this
.
model
.
messages
.
on
(
'
add
'
,
this
.
onMessageAdded
,
this
);
this
.
model
.
on
(
'
show
'
,
this
.
show
,
this
);
this
.
model
.
on
(
'
show
'
,
this
.
show
,
this
);
this
.
model
.
on
(
'
destroy
'
,
this
.
hide
,
this
);
this
.
model
.
on
(
'
destroy
'
,
this
.
hide
,
this
);
...
@@ -1670,11 +1667,11 @@
...
@@ -1670,11 +1667,11 @@
var
msgs
=
[];
var
msgs
=
[];
if
(
data
.
otr_status
==
UNENCRYPTED
)
{
if
(
data
.
otr_status
==
UNENCRYPTED
)
{
msgs
.
push
(
__
(
"
Your messages are not encrypted anymore
"
));
msgs
.
push
(
__
(
"
Your messages are not encrypted anymore
"
));
}
else
if
(
data
.
otr_status
==
UNVERIFIED
){
}
else
if
(
data
.
otr_status
==
UNVERIFIED
)
{
msgs
.
push
(
__
(
"
Your messages are now encrypted but your contact's identity has not been verified.
"
));
msgs
.
push
(
__
(
"
Your messages are now encrypted but your contact's identity has not been verified.
"
));
}
else
if
(
data
.
otr_status
==
VERIFIED
){
}
else
if
(
data
.
otr_status
==
VERIFIED
)
{
msgs
.
push
(
__
(
"
Your contact's identify has been verified.
"
));
msgs
.
push
(
__
(
"
Your contact's identify has been verified.
"
));
}
else
if
(
data
.
otr_status
==
FINISHED
){
}
else
if
(
data
.
otr_status
==
FINISHED
)
{
msgs
.
push
(
__
(
"
Your contact has ended encryption on their end, you should do the same.
"
));
msgs
.
push
(
__
(
"
Your contact has ended encryption on their end, you should do the same.
"
));
}
}
return
this
.
showHelpMessages
(
msgs
,
'
info
'
,
false
);
return
this
.
showHelpMessages
(
msgs
,
'
info
'
,
false
);
...
@@ -1685,11 +1682,11 @@
...
@@ -1685,11 +1682,11 @@
var
data
=
this
.
model
.
toJSON
();
var
data
=
this
.
model
.
toJSON
();
if
(
data
.
otr_status
==
UNENCRYPTED
)
{
if
(
data
.
otr_status
==
UNENCRYPTED
)
{
data
.
otr_tooltip
=
__
(
'
Your messages are not encrypted. Click here to enable OTR encryption.
'
);
data
.
otr_tooltip
=
__
(
'
Your messages are not encrypted. Click here to enable OTR encryption.
'
);
}
else
if
(
data
.
otr_status
==
UNVERIFIED
){
}
else
if
(
data
.
otr_status
==
UNVERIFIED
)
{
data
.
otr_tooltip
=
__
(
'
Your messages are encrypted, but your contact has not been verified.
'
);
data
.
otr_tooltip
=
__
(
'
Your messages are encrypted, but your contact has not been verified.
'
);
}
else
if
(
data
.
otr_status
==
VERIFIED
){
}
else
if
(
data
.
otr_status
==
VERIFIED
)
{
data
.
otr_tooltip
=
__
(
'
Your messages are encrypted and your contact verified.
'
);
data
.
otr_tooltip
=
__
(
'
Your messages are encrypted and your contact verified.
'
);
}
else
if
(
data
.
otr_status
==
FINISHED
){
}
else
if
(
data
.
otr_status
==
FINISHED
)
{
data
.
otr_tooltip
=
__
(
'
Your contact has closed their end of the private session, you should do the same
'
);
data
.
otr_tooltip
=
__
(
'
Your contact has closed their end of the private session, you should do the same
'
);
}
}
this
.
$el
.
find
(
'
.chat-toolbar
'
).
html
(
this
.
$el
.
find
(
'
.chat-toolbar
'
).
html
(
...
@@ -4820,7 +4817,7 @@
...
@@ -4820,7 +4817,7 @@
this
.
save
({
'
status
'
:
value
});
this
.
save
({
'
status
'
:
value
});
},
},
getStatus
:
function
()
{
getStatus
:
function
()
{
return
this
.
get
(
'
status
'
)
||
'
online
'
;
return
this
.
get
(
'
status
'
)
||
'
online
'
;
},
},
...
@@ -4874,7 +4871,7 @@
...
@@ -4874,7 +4871,7 @@
'
desc_change_status
'
:
__
(
'
Click to change your chat status
'
)
'
desc_change_status
'
:
__
(
'
Click to change your chat status
'
)
}));
}));
// iterate through all the <option> elements and add option values
// iterate through all the <option> elements and add option values
options
.
each
(
function
(){
options
.
each
(
function
()
{
options_list
.
push
(
converse
.
templates
.
status_option
({
options_list
.
push
(
converse
.
templates
.
status_option
({
'
value
'
:
$
(
this
).
val
(),
'
value
'
:
$
(
this
).
val
(),
'
text
'
:
this
.
text
'
text
'
:
this
.
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