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,8 +297,7 @@ describe("Notifications", function () {
spyOn(converse.env, 'Favico').and.returnValue(favico); spyOn(converse.env, 'Favico').and.returnValue(favico);
const message = 'This message will always increment the message counter from zero'; 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 sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
const msgFactory = function () { const msgFactory = () => $msg({
return $msg({
from: sender_jid, from: sender_jid,
to: _converse.connection.jid, to: _converse.connection.jid,
type: 'chat', type: 'chat',
@ -307,7 +306,6 @@ describe("Notifications", function () {
.c('body').t(message).up() .c('body').t(message).up()
.c('active', {'xmlns': Strophe.NS.CHATSTATES}) .c('active', {'xmlns': Strophe.NS.CHATSTATES})
.tree(); .tree();
};
// leave converse-chat page // leave converse-chat page
_converse.windowState = 'hidden'; _converse.windowState = 'hidden';
@ -315,10 +313,15 @@ describe("Notifications", function () {
let view = _converse.chatboxviews.get(sender_jid); let view = _converse.chatboxviews.get(sender_jid);
await u.waitUntil(() => favico.badge.calls.count() === 1, 1000); await u.waitUntil(() => favico.badge.calls.count() === 1, 1000);
expect(favico.badge.calls.mostRecent().args.pop()).toBe(1); expect(favico.badge.calls.mostRecent().args.pop()).toBe(1);
expect(view.model.get('num_unread')).toBe(1);
// come back to converse-chat page // come back to converse-chat page
_converse.saveWindowState({'type': 'focus'}); _converse.saveWindowState({'type': 'focus'});
await u.waitUntil(() => u.isVisible(view)); await u.waitUntil(() => u.isVisible(view));
expect(view.model.get('num_unread')).toBe(0);
await u.waitUntil(() => favico.badge.calls.count() === 2); await u.waitUntil(() => favico.badge.calls.count() === 2);
expect(favico.badge.calls.mostRecent().args.pop()).toBe(0); 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.model = _converse.chatboxes.get(jid);
this.initDebounced(); 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:composing_spoiler', this.renderMessageForm);
this.listenTo(this.model, 'change:hidden', () => !this.model.get('hidden') && this.afterShown()); 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.model = _converse.chatboxes.get(jid);
this.initDebounced(); 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.model.disable_mam = true; // Don't do MAM queries for this box
this.listenTo(this.model, 'change:hidden', () => this.afterShown()); 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.model = _converse.chatboxes.get(jid);
this.initDebounced(); this.initDebounced();
api.listen.on('windowStateChanged', this.onWindowStateChanged); api.listen.on('windowStateChanged', d => this.onWindowStateChanged(d));
this.listenTo( this.listenTo(
this.model, this.model,

View File

@ -443,12 +443,12 @@ export default class BaseChatView extends ElementView {
api.trigger('chatBoxScrolledDown', { 'chatbox': this.model }); // TODO: clean up api.trigger('chatBoxScrolledDown', { 'chatbox': this.model }); // TODO: clean up
} }
onWindowStateChanged (state) { onWindowStateChanged (data) {
if (state === 'visible') { if (data.state === 'visible') {
if (!this.model.isHidden() && this.model.get('num_unread', 0)) { if (!this.model.isHidden() && this.model.get('num_unread', 0)) {
this.model.clearUnreadMsgCounter(); this.model.clearUnreadMsgCounter();
} }
} else if (state === 'hidden') { } else if (data.state === 'hidden') {
this.model.setChatState(_converse.INACTIVE, { 'silent': true }); this.model.setChatState(_converse.INACTIVE, { 'silent': true });
this.model.sendChatState(); this.model.sendChatState();
} }