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
705c0438
Commit
705c0438
authored
Jun 17, 2016
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes concerning tab visibility
parent
10ca2900
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
19 deletions
+33
-19
dev.html
dev.html
+3
-0
spec/chatbox.js
spec/chatbox.js
+15
-5
src/converse-chatview.js
src/converse-chatview.js
+1
-1
src/converse-core.js
src/converse-core.js
+12
-11
src/converse-notification.js
src/converse-notification.js
+2
-2
No files found.
dev.html
View file @
705c0438
...
...
@@ -60,6 +60,9 @@
'
prosody@conference.prosody.im
'
,
'
jdev@conference.jabber.org
'
],
notify_all_room_messages
:
[
'
discuss@conference.conversejs.org
'
],
auto_reconnect
:
true
,
bosh_service_url
:
'
https://conversejs.org/http-bind/
'
,
// Please use this connection manager only for testing purposes
keepalive
:
true
,
...
...
spec/chatbox.js
View file @
705c0438
...
...
@@ -1276,13 +1276,20 @@
describe
(
"
A Message Counter
"
,
function
()
{
beforeEach
(
function
()
{
converse
.
clearMsgCounter
();
}.
bind
(
converse
));
test_utils
.
closeAllChatBoxes
();
test_utils
.
removeControlBox
();
converse
.
roster
.
browserStorage
.
_clear
();
test_utils
.
initConverse
();
test_utils
.
createContacts
(
'
current
'
);
test_utils
.
openControlBox
();
test_utils
.
openContactsPanel
();
});
it
(
"
is incremented when the message is received and the window is not focused
"
,
function
()
{
spyOn
(
converse
,
'
emit
'
);
expect
(
this
.
msg_counter
).
toBe
(
0
);
spyOn
(
converse
,
'
incrementMsgCounter
'
).
andCallThrough
();
$
(
window
).
trigger
(
'
blur
'
)
;
var
previous_state
=
converse
.
windowState
;
var
message
=
'
This message will increment the message counter
'
;
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
,
msg
=
$msg
({
...
...
@@ -1292,17 +1299,20 @@
id
:
(
new
Date
()).
getTime
()
}).
c
(
'
body
'
).
t
(
message
).
up
()
.
c
(
'
active
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/chatstates
'
}).
tree
();
converse
.
windowState
=
'
hidden
'
;
this
.
chatboxes
.
onMessage
(
msg
);
expect
(
converse
.
incrementMsgCounter
).
toHaveBeenCalled
();
expect
(
this
.
msg_counter
).
toBe
(
1
);
expect
(
converse
.
emit
).
toHaveBeenCalledWith
(
'
message
'
,
msg
);
converse
.
windowSate
=
previous_state
;
}.
bind
(
converse
));
it
(
"
is cleared when the window is focused
"
,
function
()
{
converse
.
windowState
=
'
hidden
'
;
spyOn
(
converse
,
'
clearMsgCounter
'
).
andCallThrough
();
runs
(
function
()
{
$
(
window
).
triggerHandler
(
'
blur
'
);
$
(
window
).
triggerHandler
(
'
focus
'
);
converse
.
saveWindowState
(
null
,
'
focus
'
);
converse
.
saveWindowState
(
null
,
'
blur
'
);
});
waits
(
50
);
runs
(
function
()
{
...
...
@@ -1313,7 +1323,7 @@
it
(
"
is not incremented when the message is received and the window is focused
"
,
function
()
{
expect
(
this
.
msg_counter
).
toBe
(
0
);
spyOn
(
converse
,
'
incrementMsgCounter
'
).
andCallThrough
();
$
(
window
).
trigger
(
'
focus
'
);
converse
.
saveWindowState
(
null
,
'
focus
'
);
var
message
=
'
This message will not increment the message counter
'
;
var
sender_jid
=
mock
.
cur_names
[
0
].
replace
(
/ /g
,
'
.
'
).
toLowerCase
()
+
'
@localhost
'
,
msg
=
$msg
({
...
...
src/converse-chatview.js
View file @
705c0438
...
...
@@ -342,7 +342,7 @@
if
(
this
.
model
.
get
(
'
scrolled
'
,
true
))
{
this
.
$el
.
find
(
'
.new-msgs-indicator
'
).
removeClass
(
'
hidden
'
);
}
if
(
converse
.
windowState
===
'
blur
'
||
this
.
model
.
get
(
'
scrolled
'
,
true
))
{
if
(
converse
.
windowState
===
'
hidden
'
||
this
.
model
.
get
(
'
scrolled
'
,
true
))
{
converse
.
incrementMsgCounter
();
}
}
...
...
src/converse-core.js
View file @
705c0438
...
...
@@ -515,8 +515,6 @@
}
else
{
document
.
title
=
document
.
title
.
replace
(
/^Messages
\(\d
+
\)
/
,
"
Messages (
"
+
this
.
msg_counter
+
"
)
"
);
}
window
.
blur
();
window
.
focus
();
}
else
if
(
document
.
title
.
search
(
/^Messages
\(\d
+
\)
/
)
!==
-
1
)
{
document
.
title
=
document
.
title
.
replace
(
/^Messages
\(\d
+
\)
/
,
""
);
}
...
...
@@ -570,7 +568,10 @@
}
};
var
saveWindowState
=
function
(
ev
,
hidden
)
{
this
.
saveWindowState
=
function
(
ev
,
hidden
)
{
// XXX: eventually we should be able to just use
// document.visibilityState (when we drop support for older
// browsers).
var
state
;
var
v
=
"
visible
"
,
h
=
"
hidden
"
,
event_map
=
{
...
...
@@ -581,7 +582,7 @@
'
focusout
'
:
h
,
'
pagehide
'
:
h
};
ev
=
ev
||
window
.
event
;
ev
=
ev
||
document
.
createEvent
(
'
Events
'
)
;
if
(
ev
.
type
in
event_map
)
{
state
=
event_map
[
ev
.
type
];
}
else
{
...
...
@@ -600,23 +601,23 @@
var
hidden
=
"
hidden
"
;
// Standards:
if
(
hidden
in
document
)
{
document
.
addEventListener
(
"
visibilitychange
"
,
_
.
partial
(
saveWindowState
,
_
,
hidden
));
document
.
addEventListener
(
"
visibilitychange
"
,
_
.
partial
(
converse
.
saveWindowState
,
_
,
hidden
));
}
else
if
((
hidden
=
"
mozHidden
"
)
in
document
)
{
document
.
addEventListener
(
"
mozvisibilitychange
"
,
_
.
partial
(
saveWindowState
,
_
,
hidden
));
document
.
addEventListener
(
"
mozvisibilitychange
"
,
_
.
partial
(
converse
.
saveWindowState
,
_
,
hidden
));
}
else
if
((
hidden
=
"
webkitHidden
"
)
in
document
)
{
document
.
addEventListener
(
"
webkitvisibilitychange
"
,
_
.
partial
(
saveWindowState
,
_
,
hidden
));
document
.
addEventListener
(
"
webkitvisibilitychange
"
,
_
.
partial
(
converse
.
saveWindowState
,
_
,
hidden
));
}
else
if
((
hidden
=
"
msHidden
"
)
in
document
)
{
document
.
addEventListener
(
"
msvisibilitychange
"
,
_
.
partial
(
saveWindowState
,
_
,
hidden
));
document
.
addEventListener
(
"
msvisibilitychange
"
,
_
.
partial
(
converse
.
saveWindowState
,
_
,
hidden
));
}
else
if
(
"
onfocusin
"
in
document
)
{
// IE 9 and lower:
document
.
onfocusin
=
document
.
onfocusout
=
_
.
partial
(
saveWindowState
,
_
,
hidden
);
document
.
onfocusin
=
document
.
onfocusout
=
_
.
partial
(
converse
.
saveWindowState
,
_
,
hidden
);
}
else
{
// All others:
window
.
onpageshow
=
window
.
onpagehide
=
window
.
onfocus
=
window
.
onblur
=
_
.
partial
(
saveWindowState
,
_
,
hidden
);
window
.
onpageshow
=
window
.
onpagehide
=
window
.
onfocus
=
window
.
onblur
=
_
.
partial
(
converse
.
saveWindowState
,
_
,
hidden
);
}
// set the initial state (but only if browser supports the Page Visibility API)
if
(
document
[
hidden
]
!==
undefined
)
{
_
.
partial
(
saveWindowState
,
_
,
hidden
)({
type
:
document
[
hidden
]
?
"
blur
"
:
"
focus
"
});
_
.
partial
(
converse
.
saveWindowState
,
_
,
hidden
)({
type
:
document
[
hidden
]
?
"
blur
"
:
"
focus
"
});
}
};
...
...
src/converse-notification.js
View file @
705c0438
...
...
@@ -110,11 +110,11 @@
}
};
converse
.
areDesktopNotificationsEnabled
=
function
(
ignore_
blur
)
{
converse
.
areDesktopNotificationsEnabled
=
function
(
ignore_
hidden
)
{
var
enabled
=
converse
.
supports_html5_notification
&&
converse
.
show_desktop_notifications
&&
Notification
.
permission
===
"
granted
"
;
if
(
ignore_
blur
)
{
if
(
ignore_
hidden
)
{
return
enabled
;
}
else
{
return
enabled
&&
converse
.
windowState
===
'
hidden
'
;
...
...
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