Skip to content
This repository was archived by the owner on Apr 1, 2018. It is now read-only.
Open
Show file tree
Hide file tree
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
47 changes: 47 additions & 0 deletions client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ var COMMANDS = {
cls = 'me'
}
pushMessage(args.nick, args.text, args.time, cls)

if (!windowActive && $('#notifications-chat').checked && args.nick != myNick) {
new Notification('?' + myChannel, {body: args.nick + ": " + args.text});
}
else if(!windowActive && $('#notifications-mention').checked && args.text.indexOf('@' + myNick) !== -1) {
new Notification('?' + myChannel, {body: args.nick + ": " + args.text});
}
},
info: function(args) {
pushMessage('*', args.text, args.time, 'info')
Expand All @@ -123,13 +130,21 @@ var COMMANDS = {
if ($('#joined-left').checked) {
pushMessage('*', nick + " joined", Date.now(), 'info')
}

if (!windowActive && $('#notifications-joinLeave').checked) {
new Notification('?' + myChannel, {body: nick + ' joined'});
}
},
onlineRemove: function(args) {
var nick = args.nick
userRemove(nick)
if ($('#joined-left').checked) {
pushMessage('*', nick + " left", Date.now(), 'info')
}

if (!windowActive && $('#notifications-joinLeave').checked) {
new Notification('?' + myChannel, {body: nick + ' left'});
}
},
}

Expand Down Expand Up @@ -346,6 +361,17 @@ if (localStorageGet('joined-left') == 'false') {
if (localStorageGet('parse-latex') == 'false') {
$('#parse-latex').checked = false
}
if (Notification.permission == 'granted') {
if(localStorageGet('notifications-mention') == 'true') {
$('#notifications-mention').checked = true
}
if(localStorageGet('notifications-chat') == 'true') {
$('#notifications-chat').checked = true
}
if(localStorageGet('notifications-joinLeave') == 'true') {
$('#notifications-joinLeave').checked = true
}
}

$('#pin-sidebar').onchange = function(e) {
localStorageSet('pin-sidebar', !!e.target.checked)
Expand All @@ -357,6 +383,27 @@ $('#parse-latex').onchange = function(e) {
localStorageSet('parse-latex', !!e.target.checked)
}

// Notifications

function updateNotifications(e)
{
if(e.checked && window.Notification && Notification.permission != 'granted') {
e.checked = false
Notification.requestPermission(function() {
if(Notification.permission == 'granted') {
e.checked = true
localStorageSet(e.id, true)
}
});
}
else if (e.checked && window.Notification) {
localStorageSet(e.id, true)
}
else {
localStorageSet(e.id, false)
}
}

// User list

function userAdd(nick) {
Expand Down
10 changes: 10 additions & 0 deletions client/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ html
p
input#pin-sidebar(type="checkbox")
label(for="pin-sidebar") Pin sidebar
h4 Notifications
p
input#notifications-mention(type="checkbox" onchange="updateNotifications(this)")
label(for="parse-latex") When @mentioned
p
input#notifications-chat(type="checkbox" onchange="updateNotifications(this)")
label(for="parse-latex") When chat received
p
input#notifications-joinLeave(type="checkbox" onchange="updateNotifications(this)")
label(for="parse-latex") When users join/leave
h4 Settings
p
input#joined-left(type="checkbox", checked)
Expand Down