diff options
author | redmatrix <git@macgirvin.com> | 2016-05-11 20:20:17 -0700 |
---|---|---|
committer | redmatrix <git@macgirvin.com> | 2016-05-11 20:20:17 -0700 |
commit | ac1ec996847235152b61e681ae39d976d3177d4b (patch) | |
tree | 82c30eab0f84dcbd366449348004244825589686 | |
parent | fae78b947ffd31aa6592bc2108272531fdbc293d (diff) | |
parent | 8e5718bf04b2db7a87ea2416bd01e081b621b247 (diff) | |
download | volse-hubzilla-1.6.tar.gz volse-hubzilla-1.6.tar.bz2 volse-hubzilla-1.6.zip |
Merge branch 'dev'1.6
-rw-r--r-- | view/tpl/chat.tpl | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/view/tpl/chat.tpl b/view/tpl/chat.tpl index afdbdeb28..e92265b5d 100644 --- a/view/tpl/chat.tpl +++ b/view/tpl/chat.tpl @@ -103,6 +103,7 @@ $(document).ready(function() { $('#chatroom_bookmarks, #vcard').hide(); $('#chatroom_list, #chatroom_members').show(); adjustInlineTopBarHeight(); + chatNotificationInit(); }); $(window).resize(function () { @@ -138,6 +139,8 @@ function load_chats() { } +var previousChatRoomMembers = null; // initialize chat room member change register +var currentChatRoomMembers = null; // initialize chat room member change register function update_inroom(inroom) { var html = document.createElement('div'); var count = inroom.length; @@ -147,9 +150,37 @@ function update_inroom(inroom) { $(newNode).html('<img style="height: 32px; width: 32px;" src="' + item.img + '" alt="' + item.name + '" /> ' + '<span class="name">' + item.name + '</span><br /><span class="' + item.status_class + '">' + item.status + '</span>'); html.appendChild(newNode); }); + memberChange = chatRoomMembersChange(inroom); // get list of arrivals and departures + if(memberChange.membersArriving.length > 0) { + // Issue pop-up notification if anyone enters the room. + chat_issue_notification(JSON.stringify(memberChange.membersArriving.pop().name) + ' entered the room', 'Hubzilla Chat'); + } $('#chatMembers').html(html); } +// Determine if the new list of chat room members has any new members or if any have left +function chatRoomMembersChange(inroom) { + previousChatRoomMembers = currentChatRoomMembers; + currentChatRoomMembers = inroom; + var membersArriving = []; + var membersLeaving = []; + if(previousChatRoomMembers !== null) { + var newMember = false; + $.each( currentChatRoomMembers, function(index, currMember) { + newMember = true; + $.each( previousChatRoomMembers, function(index, prevMember) { + if (prevMember.name === currMember.name) { + newMember = false; + } + }); + if (newMember === true) { + membersArriving.push(currMember); + } + }); + } + return {membersArriving: membersArriving, membersLeaving: membersLeaving}; +} + function update_chats(chats) { var count = chats.length; $.each( chats, function(index, item) { @@ -172,6 +203,51 @@ function update_chats(chats) { }); } +var chat_notify_granted = false; // Initialize notification permission to denied +// Request notification access from the user +// TODO: Check Hubzilla member config setting before requesting permission +function chatNotificationInit() { + + if (!("Notification" in window)) { + window.console.log("This browser does not support system notifications"); + } + // Let's check whether notification permissions have already been granted + else if (Notification.permission === "granted") { + // If it's okay let's create a notification + chat_notify_granted = true; //var notification = new Notification("Hi there!"); + } + + // Otherwise, we need to ask the user for permission + else if (Notification.permission !== 'denied') { + Notification.requestPermission(function (permission) { + // If the user accepts, let's create a notification + if (permission === "granted") { + chat_notify_granted = true; //var notification = new Notification("Hi there!"); + } + }); + } +} + +// Issue a pop-up notification using the web standard Notification API +// https://developer.mozilla.org/docs/Web/API/notification +var chat_issue_notification = function (theBody,theTitle) { + if ( !chat_notify_granted ) { + return; + } + var nIcon = "/images/icons/48/group.png"; + var options = { + body: theBody, + icon: nIcon, + silent: false + } + var n = new Notification(theTitle,options); + n.onclick = function (event) { + setTimeout(n.close.bind(n), 300); + } + // TODO: Allow audio notification option + //chat_notify_audio.play(); +} + function chatJotGetLink() { reply = prompt("{{$linkurl}}"); if(reply && reply.length) { |