From afcc264f99ef285747d527e2004a852ea6624554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Wed, 19 Feb 2020 14:13:11 +0100 Subject: [PATCH] Show a toast when clicking nick of a user who left --- css/glowingbear.css | 25 +++++++++++++++++++++++++ js/inputbar.js | 12 ++++++++++++ js/models.js | 14 ++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/css/glowingbear.css b/css/glowingbear.css index 312ef04..64eb2c2 100644 --- a/css/glowingbear.css +++ b/css/glowingbear.css @@ -708,6 +708,31 @@ img.emojione { width: auto; } +#toast { + position: fixed; + left: 50%; + bottom: 50px; + width: 250px; + margin-left: -125px; + + background-color: #333; + text-align: center; + border-radius: 3px; + padding: 10px 15px; + z-index: 100; + animation: fadein 0.5s, fadeout 0.5s 4.5s; +} + +@keyframes fadein { + from { bottom: 0; opacity: 0; } + to { bottom: 50px; opacity: 1; } +} + +@keyframes fadeout { + from { bottom: 50px; opacity: 1; } + to { bottom: 0; opacity: 0; } +} + .glyphicon-spin { -webkit-animation: spin 1000ms infinite linear; animation: spin 1000ms infinite linear; diff --git a/js/inputbar.js b/js/inputbar.js index ceb2265..656a4a7 100644 --- a/js/inputbar.js +++ b/js/inputbar.js @@ -217,6 +217,18 @@ weechat.directive('inputBar', function() { // Extract nick from bufferline prefix var nick = prefix[prefix.length - 1].text; + // Check whether the user is still online + var buffer = models.getBuffer(bufferline.buffer); + var is_online = buffer.queryNicklist(nick); + if (!is_online) { + // show a toast that the user left + var toast = document.createElement('div'); + toast.id = "toast"; + toast.innerHTML = nick + " has left the room"; + document.body.appendChild(toast); + setTimeout(function() { document.body.removeChild(toast); }, 5000); + } + var newValue = $scope.command || ''; // can be undefined, in that case, use the empty string var addColon = newValue.length === 0; if (newValue.length > 0) { diff --git a/js/models.js b/js/models.js index 469bdaf..1ebc411 100644 --- a/js/models.js +++ b/js/models.js @@ -308,6 +308,19 @@ models.service('models', ['$rootScope', '$filter', 'bufferResume', function($roo return nicklist.hasOwnProperty('root'); }; + // Check whether a particular nick is in the nicklist + var queryNicklist = function(nick) { + for (var groupIdx in nicklist) { + var nicks = nicklist[groupIdx].nicks; + for (var nickIdx in nicks) { + if (nicks[nickIdx].name === nick) { + return true; + } + } + } + return false; + }; + /* Clear all our buffer lines */ var clear = function() { while(lines.length > 0) { @@ -353,6 +366,7 @@ models.service('models', ['$rootScope', '$filter', 'bufferResume', function($roo isNicklistEmpty: isNicklistEmpty, nicklistRequested: nicklistRequested, pinned: pinned, + queryNicklist: queryNicklist, }; };