From 7a8908c93eb2548f779dc826b59ce45f660e41ee Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 4 Oct 2019 17:30:42 +0200 Subject: [PATCH] Fix ability to create more than one team. Add chat notifications --- www/common/common-notifier.js | 2 +- www/common/messenger-ui.js | 15 ++++++++++---- www/teams/inner.js | 37 ++++++++++++++++++++++++++++------- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/www/common/common-notifier.js b/www/common/common-notifier.js index 99415b553..688c677a6 100644 --- a/www/common/common-notifier.js +++ b/www/common/common-notifier.js @@ -13,7 +13,7 @@ define([ }; Notifier.notify = function (data) { - if (Visible.isSupported() && !Visible.currently()) { + if (Visible.isSupported() && (!Visible.currently() || (data && data.force))) { if (data) { var title = data.title; if (document.title) { title += ' (' + document.title + ')'; } diff --git a/www/common/messenger-ui.js b/www/common/messenger-ui.js index 4dcff9c8e..9d6ba71ad 100644 --- a/www/common/messenger-ui.js +++ b/www/common/messenger-ui.js @@ -113,8 +113,12 @@ define([ var notifyToolbar = function () { if (!toolbar || !toolbar['chat']) { return; } - if (toolbar['chat'].find('button').hasClass('cp-toolbar-button-active')) { return; } - toolbar['chat'].find('button').addClass('cp-toolbar-notification'); + if (!toolbar['chat'].find('button').hasClass('cp-toolbar-button-active')) { + toolbar['chat'].find('button').addClass('cp-toolbar-notification'); + } + if (!toolbar['chat'].hasClass('cp-leftside-active')) { + toolbar['chat'].find('span.fa').addClass('cp-team-chat-notification'); + } }; var notify = function (id) { @@ -568,12 +572,15 @@ define([ var el_message = markup.message(message); - common.notify(); if (message.type === 'MSG') { var name = typeof message.name !== "undefined" ? (message.name || Messages.anonymous) : contactsData[message.author].displayName; - common.notify({title: name, msg: message.text}); + common.notify({ + title: name, + msg: message.text, + force: toolbar && toolbar.team && !toolbar['chat'].hasClass('cp-leftside-active') + }); } notifyToolbar(); diff --git a/www/teams/inner.js b/www/teams/inner.js index 7e7b18c24..c2a04224e 100644 --- a/www/teams/inner.js +++ b/www/teams/inner.js @@ -195,6 +195,9 @@ define([ APP.$rightside.removeClass('cp-rightside-drive'); APP.$leftside.removeClass('cp-leftside-narrow'); } + if (key === 'chat') { + $category.find('.cp-team-chat-notification').removeClass('cp-team-chat-notification'); + } $categories.find('.cp-leftside-active').removeClass('cp-leftside-active'); $category.addClass('cp-leftside-active'); @@ -205,7 +208,10 @@ define([ }); if (active === 'drive') { APP.$rightside.addClass('cp-rightside-drive'); - APP.$leftside.addClass('cp-leftside-narrow'); + APP.$leftside.on('mouseover', function() { + APP.$leftside.addClass('cp-leftside-narrow'); + APP.$leftside.off('mouseover'); + }); } else { APP.$rightside.removeClass('cp-rightside-drive'); APP.$leftside.removeClass('cp-leftside-narrow'); @@ -360,11 +366,16 @@ define([ var isOwner = Object.keys(privateData.teams || {}).some(function (id) { return privateData.teams[id].owner; - }) && !privateData.devMode; // XXX - if (Object.keys(privateData.teams || {}).length >= 3 || isOwner) { - content.push(h('div.alert.alert-warning', { + }) && !privateData.devMode; + + var getWarningBox = function () { + return h('div.alert.alert-warning', { role:'alert' - }, isOwner ? Messages.team_maxOwner : Messages._getKey('team_maxTeams', [MAX_TEAMS_SLOTS]))); + }, isOwner ? Messages.team_maxOwner : Messages._getKey('team_maxTeams', [MAX_TEAMS_SLOTS])); + }; + + if (Object.keys(privateData.teams || {}).length >= 3 || isOwner) { + content.push(getWarningBox()); return void cb(content); } @@ -384,7 +395,16 @@ define([ state = true; APP.module.execCommand('CREATE_TEAM', { name: name - }, function () { + }, function (obj) { + if (obj && obj.error) { + console.error(obj.error); + return void UI.warn(Messages.error); + } + // Redraw the create block + var $createDiv = $('div.cp-team-create').empty(); + isOwner = true; + $createDiv.append(getWarningBox()); + // Redraw the teams list var $div = $('div.cp-team-list').empty(); refreshList(common, function (content) { state = false; @@ -682,7 +702,10 @@ define([ return void UI.alert(Messages.error); } common.setTeamChat(obj.channel); - MessengerUI.create($(container), common, true); + MessengerUI.create($(container), common, { + chat: $('.cp-team-cat-chat'), + team: true + }); cb(content); }); });