From 9fb8722200128982c28c1a0eb7fc20aa9edb4952 Mon Sep 17 00:00:00 2001 From: Bart Riepe Date: Wed, 15 Jul 2015 13:10:13 +0200 Subject: [PATCH 1/3] allow clients to ignore users of their choice --- client/client.js | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/client/client.js b/client/client.js index 15f31b5..dd23cfb 100644 --- a/client/client.js +++ b/client/client.js @@ -43,10 +43,14 @@ function localStorageSet(key, val) { var ws var myNick = localStorageGet('my-nick') var myChannel = window.location.search.replace(/^\?/, '') +var myIgnores = [] var lastSent = "" +var ignoreTitle = ['Ignore this user', 'Accept messages from this user'] +var ignoreLabel = ['I', 'A'] + function join(channel) { - if (document.domain == 'hack.chat') { + if (document.domain == 'hack.chat' || true) { // For https://hack.chat/ ws = new WebSocket('wss://hack.chat/chat-ws') } @@ -95,7 +99,9 @@ var COMMANDS = { else if (myNick == args.nick) { cls = 'me' } - pushMessage(args.nick, args.text, args.time, cls) + if (myIgnores.indexOf(args.nick) == -1) { + pushMessage(args.nick, args.text, args.time, cls) + } }, info: function(args) { pushMessage('*', args.text, args.time, 'info') @@ -345,15 +351,42 @@ $('#parse-latex').onchange = function(e) { // User list +function getIgnoreLabel(nick) { + return myIgnores.indexOf(nick)==-1 ? ignoreLabel[0] : ignoreLabel[1]; +} + +function getIgnoreTitle(nick) { + return myIgnores.indexOf(nick)==-1 ? ignoreTitle[0] : ignoreTitle[1]; +} + function userAdd(nick) { var user = document.createElement('a') user.textContent = nick user.onclick = userInvite + + var ignore = document.createElement('a') + ignore.textContent = getIgnoreLabel(nick) + ignore.title = getIgnoreTitle(nick) + ignore.style.float = 'right' + ignore.onclick = function() { userIgnore(ignore, nick); } + var userLi = document.createElement('li') userLi.appendChild(user) + userLi.appendChild(ignore) $('#users').appendChild(userLi) } +function userIgnore(me, nick) { + var index = myIgnores.indexOf(nick) + if (index == -1) { + myIgnores.push(nick) + } else { + myIgnores.splice(index, 1) + } + me.textContent = getIgnoreLabel(nick); + me.title = getIgnoreTitle(nick); +} + function userRemove(nick) { var users = $('#users') var children = users.children From 26f33b1ef65115f59e56c9c9b68b23fabf55979e Mon Sep 17 00:00:00 2001 From: Bart Riepe Date: Wed, 15 Jul 2015 13:11:52 +0200 Subject: [PATCH 2/3] not always the live env --- client/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/client.js b/client/client.js index dd23cfb..e59c596 100644 --- a/client/client.js +++ b/client/client.js @@ -50,7 +50,7 @@ var ignoreTitle = ['Ignore this user', 'Accept messages from this user'] var ignoreLabel = ['I', 'A'] function join(channel) { - if (document.domain == 'hack.chat' || true) { + if (document.domain == 'hack.chat') { // For https://hack.chat/ ws = new WebSocket('wss://hack.chat/chat-ws') } From f338cc6014af22727d512253c52639cd4886b7ff Mon Sep 17 00:00:00 2001 From: Bart Riepe Date: Wed, 15 Jul 2015 13:29:42 +0200 Subject: [PATCH 3/3] remove users from the ignore list when they disconnect --- client/client.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/client.js b/client/client.js index e59c596..bbc8f7a 100644 --- a/client/client.js +++ b/client/client.js @@ -127,6 +127,7 @@ var COMMANDS = { onlineRemove: function(args) { var nick = args.nick userRemove(nick) + userUnignore(nick) if ($('#joined-left').checked) { pushMessage('*', nick + " left", Date.now(), 'info') } @@ -376,6 +377,10 @@ function userAdd(nick) { $('#users').appendChild(userLi) } +function userUnignore(nick) { + myIgnores.splice(myIgnores.indexOf(nick), 1) +} + function userIgnore(me, nick) { var index = myIgnores.indexOf(nick) if (index == -1) { @@ -392,7 +397,7 @@ function userRemove(nick) { var children = users.children for (var i = 0; i < children.length; i++) { var user = children[i] - if (user.textContent == nick) { + if (user.children[0].textContent == nick) { users.removeChild(user) } }