Bugfix in window state change handler
This commit is contained in:
parent
790caf9f5a
commit
f81292e955
@ -297,17 +297,15 @@ describe("Notifications", function () {
|
||||
spyOn(converse.env, 'Favico').and.returnValue(favico);
|
||||
const message = 'This message will always increment the message counter from zero';
|
||||
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
||||
const msgFactory = function () {
|
||||
return $msg({
|
||||
from: sender_jid,
|
||||
to: _converse.connection.jid,
|
||||
type: 'chat',
|
||||
id: u.getUniqueId()
|
||||
})
|
||||
.c('body').t(message).up()
|
||||
.c('active', {'xmlns': Strophe.NS.CHATSTATES})
|
||||
.tree();
|
||||
};
|
||||
const msgFactory = () => $msg({
|
||||
from: sender_jid,
|
||||
to: _converse.connection.jid,
|
||||
type: 'chat',
|
||||
id: u.getUniqueId()
|
||||
})
|
||||
.c('body').t(message).up()
|
||||
.c('active', {'xmlns': Strophe.NS.CHATSTATES})
|
||||
.tree();
|
||||
|
||||
// leave converse-chat page
|
||||
_converse.windowState = 'hidden';
|
||||
@ -315,10 +313,15 @@ describe("Notifications", function () {
|
||||
let view = _converse.chatboxviews.get(sender_jid);
|
||||
await u.waitUntil(() => favico.badge.calls.count() === 1, 1000);
|
||||
expect(favico.badge.calls.mostRecent().args.pop()).toBe(1);
|
||||
expect(view.model.get('num_unread')).toBe(1);
|
||||
|
||||
// come back to converse-chat page
|
||||
_converse.saveWindowState({'type': 'focus'});
|
||||
|
||||
|
||||
await u.waitUntil(() => u.isVisible(view));
|
||||
expect(view.model.get('num_unread')).toBe(0);
|
||||
|
||||
await u.waitUntil(() => favico.badge.calls.count() === 2);
|
||||
expect(favico.badge.calls.mostRecent().args.pop()).toBe(0);
|
||||
|
||||
|
@ -39,7 +39,7 @@ export default class ChatView extends BaseChatView {
|
||||
this.model = _converse.chatboxes.get(jid);
|
||||
this.initDebounced();
|
||||
|
||||
api.listen.on('windowStateChanged', this.onWindowStateChanged);
|
||||
api.listen.on('windowStateChanged', d => this.onWindowStateChanged(d));
|
||||
|
||||
this.listenTo(this.model, 'change:composing_spoiler', this.renderMessageForm);
|
||||
this.listenTo(this.model, 'change:hidden', () => !this.model.get('hidden') && this.afterShown());
|
||||
|
@ -20,7 +20,7 @@ class HeadlinesView extends BaseChatView {
|
||||
this.model = _converse.chatboxes.get(jid);
|
||||
this.initDebounced();
|
||||
|
||||
api.listen.on('windowStateChanged', this.onWindowStateChanged);
|
||||
api.listen.on('windowStateChanged', d => this.onWindowStateChanged(d));
|
||||
|
||||
this.model.disable_mam = true; // Don't do MAM queries for this box
|
||||
this.listenTo(this.model, 'change:hidden', () => this.afterShown());
|
||||
|
@ -81,7 +81,7 @@ export default class MUCView extends BaseChatView {
|
||||
this.model = _converse.chatboxes.get(jid);
|
||||
this.initDebounced();
|
||||
|
||||
api.listen.on('windowStateChanged', this.onWindowStateChanged);
|
||||
api.listen.on('windowStateChanged', d => this.onWindowStateChanged(d));
|
||||
|
||||
this.listenTo(
|
||||
this.model,
|
||||
|
@ -443,12 +443,12 @@ export default class BaseChatView extends ElementView {
|
||||
api.trigger('chatBoxScrolledDown', { 'chatbox': this.model }); // TODO: clean up
|
||||
}
|
||||
|
||||
onWindowStateChanged (state) {
|
||||
if (state === 'visible') {
|
||||
onWindowStateChanged (data) {
|
||||
if (data.state === 'visible') {
|
||||
if (!this.model.isHidden() && this.model.get('num_unread', 0)) {
|
||||
this.model.clearUnreadMsgCounter();
|
||||
}
|
||||
} else if (state === 'hidden') {
|
||||
} else if (data.state === 'hidden') {
|
||||
this.model.setChatState(_converse.INACTIVE, { 'silent': true });
|
||||
this.model.sendChatState();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user