Skip to content
This repository has been archived by the owner on Apr 1, 2018. It is now read-only.

Spammers driving me mad #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ 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') {
// For https://hack.chat/
Expand Down Expand Up @@ -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')
Expand All @@ -121,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')
}
Expand Down Expand Up @@ -345,21 +352,52 @@ $('#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 userUnignore(nick) {
myIgnores.splice(myIgnores.indexOf(nick), 1)
}

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
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)
}
}
Expand Down