Bugfix in window state change handler

This commit is contained in:
JC Brand 2021-02-09 10:00:23 +01:00
parent 790caf9f5a
commit f81292e955
5 changed files with 20 additions and 17 deletions

View File

@ -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);

View File

@ -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());

View File

@ -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());

View File

@ -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,

View File

@ -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();
}