Desktop Notifications

This commit is contained in:
2020-09-24 00:22:31 +02:00
parent c1663de541
commit 36dc674ba4
5 changed files with 296 additions and 233 deletions

File diff suppressed because it is too large Load Diff

39
jquery/push.min.js vendored Normal file

File diff suppressed because one or more lines are too long

1
jquery/push.min.js.map Normal file

File diff suppressed because one or more lines are too long

View File

@@ -24,7 +24,7 @@
</div> </div>
<div id="chat_input" class="round"> <div id="chat_input" class="round">
<form id="chat_form" name="chat_form"> <form id="chat_form" name="chat_form">
</form> </form>
</div> </div>
</div> </div>
@@ -80,7 +80,7 @@ databap.pageInit = function()
databap.consts.chanPrefix = 'chan_'; databap.consts.chanPrefix = 'chan_';
databap.consts.chanQuitPrefix = 'quit_chan_'; databap.consts.chanQuitPrefix = 'quit_chan_';
databap.consts.chanUnreadPrefix = 'unread_chan_'; databap.consts.chanUnreadPrefix = 'unread_chan_';
//Page variables //Page variables
self.tmp('sending_msg', 'boolean'); self.tmp('sending_msg', 'boolean');
self.tmp('refresh', 'boolean'); self.tmp('refresh', 'boolean');
@@ -90,47 +90,50 @@ databap.pageInit = function()
self.tmp('last_message_id', '0'); self.tmp('last_message_id', '0');
self.tmp('scrolling', 'boolean'); self.tmp('scrolling', 'boolean');
databap.tmp('tab_info', 'object'); databap.tmp('tab_info', 'object');
//Main elements //Main elements
$MsgInput = databap.getMainElem('#message'); $MsgInput = databap.getMainElem('#message');
$MsgInputBox = databap.getMainElem('#chat_input'); $MsgInputBox = databap.getMainElem('#chat_input');
//Bind message box key events //Bind message box key events
databap.getMainElem('#chat_form').submit(function(e){e.preventDefault();}); databap.getMainElem('#chat_form').submit(function(e){e.preventDefault();});
$MsgInput.bind('keydown', function(e){if(e.which == 9)e.preventDefault();}); $MsgInput.bind('keydown', function(e){if(e.which == 9)e.preventDefault();});
$MsgInput.keyup(function(e){keyController(e);}); $MsgInput.keyup(function(e){keyController(e);});
//Loading the chat //Loading the chat
self.initScrollBar('#chat_container', '#chat_messages_box', '#chat_messages'); self.initScrollBar('#chat_container', '#chat_messages_box', '#chat_messages');
//Loading Chans //Loading Chans
setChanButton(); setChanButton();
databap.vars.chans_list[databap.consts.all_chan_id] = databap.consts.all_chan_text; databap.vars.chans_list[databap.consts.all_chan_id] = databap.consts.all_chan_text;
databap.tmp(['unread_msg', databap.consts.all_chan_text], 0); databap.tmp(['unread_msg', databap.consts.all_chan_text], 0);
joinChan(databap.consts.default_chan, true); joinChan(databap.consts.default_chan, true);
//window focus //window focus
$(window).focus(onPageFocus); $(window).focus(onPageFocus);
$(window).blur(onPageBlur); $(window).blur(onPageBlur);
//Message Input Focus //Message Input Focus
$MsgInput.focus(); $MsgInput.focus();
//Init sidebar events //Init sidebar events
initSideBar(); initSideBar();
//Setup Image upload //Setup Image upload
initImageUpload(); initImageUpload();
//Init's end //Init's end
databap.setInitEnd(true); databap.setInitEnd(true);
//Notification Permission
if(!Push.Permission.has()) Push.Permission.request(()=>{}, ()=>{});
}; };
//On resize //On resize
databap.onResize = function() databap.onResize = function()
{ {
self.setScrollBarSize('maximize'); self.setScrollBarSize('maximize');
//Message Input //Message Input
//$('#message').width($('#chat_input').width() - $('#message_img').outerWidth(true)- 1); //$('#message').width($('#chat_input').width() - $('#message_img').outerWidth(true)- 1);
}; };
@@ -152,7 +155,7 @@ databap.onKeyDown = function(e)
}; };
function initImageUpload() function initImageUpload()
{ {
//Load Uploader //Load Uploader
self.tmp('uploader', new qq.FileUploader self.tmp('uploader', new qq.FileUploader
( (
@@ -161,13 +164,13 @@ function initImageUpload()
action: databap.getActionLink('upload_image'), action: databap.getActionLink('upload_image'),
allowedExtensions: databap.consts.authorized_img_exts, allowedExtensions: databap.consts.authorized_img_exts,
sizeLimit: parseInt(databap.consts.max_size)*100, sizeLimit: parseInt(databap.consts.max_size)*100,
template: '<div class="uploader_box">' + template: '<div class="uploader_box">' +
'<div class="uploader_droparea round">' + '<div class="uploader_droparea round">' +
'<span>Glisser les images ici</span>' + '<span>Glisser les images ici</span>' +
'</div>' + '</div>' +
'<a class="uploader_button hide"></a>' + '<a class="uploader_button hide"></a>' +
'<div class="uploader_buffer hide"></div>' + '<div class="uploader_buffer hide"></div>' +
'<ul id="uploader_list" class="uploader_list hide"></ul>' + '<ul id="uploader_list" class="uploader_list hide"></ul>' +
'</div>', '</div>',
onComplete:function(id, fileName, result) onComplete:function(id, fileName, result)
{ {
@@ -189,17 +192,17 @@ function initImageUpload()
} }
)); ));
$('.uploader_box').append($('#message_input').children()); $('.uploader_box').append($('#message_input').children());
//Prompt file explorer //Prompt file explorer
$('#upload_img').click(function(){$('#c1_file').click();}); $('#upload_img').click(function(){$('#c1_file').click();});
//Clipboard handling //Clipboard handling
$(function(){$.pasteimage(function(sSource) $(function(){$.pasteimage(function(sSource)
{ {
//Parse the uri to strip out "base64" //Parse the uri to strip out "base64"
var sSourceSplit = sSource.split("base64,"); var sSourceSplit = sSource.split("base64,");
var sSourceString = sSourceSplit[1]; var sSourceString = sSourceSplit[1];
//Write base64-encoded string into input field //Write base64-encoded string into input field
postMessage('/imgsrc '+sSourceString); postMessage('/imgsrc '+sSourceString);
});}); });});
@@ -219,7 +222,7 @@ function initSideBar()
.addClass('round') .addClass('round')
.closest('.sidebar_box').find('.sidebar_box_content') .closest('.sidebar_box').find('.sidebar_box_content')
.hide('fast'); .hide('fast');
$This $This
.toggleClass('round') .toggleClass('round')
.closest('.sidebar_box').find('.sidebar_box_content') .closest('.sidebar_box').find('.sidebar_box_content')
@@ -268,11 +271,11 @@ function getNews()
}); });
} }
else $('<div>', {'class':'new'}).hide().text('Aucune news.').appendTo($NewsBox); else $('<div>', {'class':'new'}).hide().text('Aucune news.').appendTo($NewsBox);
$NewsBox.find('.loading').hide(); $NewsBox.find('.loading').hide();
$NewsBox.find('.new').toggle(); $NewsBox.find('.new').toggle();
$NewsBox.find('.new:hidden').remove(); $NewsBox.find('.new:hidden').remove();
//Request in 10mins //Request in 10mins
databap.tmp('news_timer', setTimeout(getNews, databap.tmp('news_period'))); databap.tmp('news_timer', setTimeout(getNews, databap.tmp('news_period')));
}, },
@@ -325,7 +328,7 @@ function setChanButton()
var $This = $(this); var $This = $(this);
joinChan($This.val()); joinChan($This.val());
$This.val(''); $This.val('');
} }
if(typeof e.keyCode == 'undefined' || e.keyCode == 13) if(typeof e.keyCode == 'undefined' || e.keyCode == 13)
{ {
@@ -336,7 +339,7 @@ function setChanButton()
}) })
.blur(function(){$(this).keyup();}) .blur(function(){$(this).keyup();})
).hide() ).hide()
); );
} }
function getChanKeyName(sChanName) function getChanKeyName(sChanName)
@@ -367,7 +370,7 @@ function joinChan(sChanName, bFirstConn, asAttendees, bSwitchOnJoin)
asAttendees = asAttendees || []; asAttendees = asAttendees || [];
bSwitchOnJoin = (typeof bSwitchOnJoin === 'undefined')?true:bSwitchOnJoin; bSwitchOnJoin = (typeof bSwitchOnJoin === 'undefined')?true:bSwitchOnJoin;
var sChanName = ucwords(sChanName); var sChanName = ucwords(sChanName);
if(sChanName!='') if(sChanName!='')
{ {
//Join for the first time //Join for the first time
@@ -393,10 +396,10 @@ function joinChan(sChanName, bFirstConn, asAttendees, bSwitchOnJoin)
if(!getChanName(iChanId)) addChanTab(iChanId, sReturnedChanName, data.channel_tab_names[iChanId], !bSwitchOnJoin); if(!getChanName(iChanId)) addChanTab(iChanId, sReturnedChanName, data.channel_tab_names[iChanId], !bSwitchOnJoin);
} }
); );
//Full reload of messages //Full reload of messages
refresh_chat(true); refresh_chat(true);
//Switch to the right chan //Switch to the right chan
switchChan(bSwitchOnJoin?data.current_chan_id:null); switchChan(bSwitchOnJoin?data.current_chan_id:null);
} }
@@ -416,7 +419,7 @@ function joinChan(sChanName, bFirstConn, asAttendees, bSwitchOnJoin)
switchChan(bSwitchOnJoin?getChanKeyName(sChanName):null); switchChan(bSwitchOnJoin?getChanKeyName(sChanName):null);
} }
} }
//Focus input bar //Focus input bar
$('#message').focus(); $('#message').focus();
} }
@@ -449,26 +452,26 @@ function switchChan(sChanKeyName)
{ {
var sChanName = currentChan(getChanName(sChanKeyName)); var sChanName = currentChan(getChanName(sChanKeyName));
sChanKeyName = sChanKeyName || getChanKeyName(sChanName); sChanKeyName = sChanKeyName || getChanKeyName(sChanName);
//Unread msg //Unread msg
if(databap.vars.focus) if(databap.vars.focus)
{ {
databap.tmp(['unread_msg', sChanName], 0); databap.tmp(['unread_msg', sChanName], 0);
databap.tmp(['unread_msg', databap.consts.all_chan_text], 0); databap.tmp(['unread_msg', databap.consts.all_chan_text], 0);
} }
syncUnreadMsg(); syncUnreadMsg();
//Switch current channel button to active //Switch current channel button to active
$('#chat_chan').find('span[id^="'+databap.consts.chanPrefix+'"]').removeClass('active').addClass('clickable'); $('#chat_chan').find('span[id^="'+databap.consts.chanPrefix+'"]').removeClass('active').addClass('clickable');
$('#'+databap.consts.chanPrefix+sChanKeyName).addClass('active').removeClass('clickable'); $('#'+databap.consts.chanPrefix+sChanKeyName).addClass('active').removeClass('clickable');
//Show current channel messages //Show current channel messages
databap.getMainElem('#chat_messages').find('p').hide(); databap.getMainElem('#chat_messages').find('p').hide();
databap.getMainElem('#chat_messages').find('p.class_'+sChanKeyName+', p.class_'+databap.consts.all_chan_id).show(); databap.getMainElem('#chat_messages').find('p.class_'+sChanKeyName+', p.class_'+databap.consts.all_chan_id).show();
//Update scrollbar //Update scrollbar
databap.updateScrollBar(self.tmp('scrolling')?'relative':'bottom'); databap.updateScrollBar(self.tmp('scrolling')?'relative':'bottom');
//Show Current channel members //Show Current channel members
databap.getMainElem('#connected_users').find('p').hide(); databap.getMainElem('#connected_users').find('p').hide();
databap.getMainElem('#connected_users').find('p.class_'+sChanKeyName).show(); databap.getMainElem('#connected_users').find('p.class_'+sChanKeyName).show();
@@ -511,7 +514,7 @@ function addChanTab(sChanKeyName, sChanName, sChanTabName, bLightUp)
sChanTabName = sChanTabName || sChanName; sChanTabName = sChanTabName || sChanName;
databap.vars.chans_list[sChanKeyName] = sChanName; databap.vars.chans_list[sChanKeyName] = sChanName;
databap.tmp(['unread_msg', sChanName], 0); databap.tmp(['unread_msg', sChanName], 0);
//Add channel tab //Add channel tab
var sChanId = databap.consts.chanPrefix+sChanKeyName; var sChanId = databap.consts.chanPrefix+sChanKeyName;
if(!$('#'+sChanId).length) if(!$('#'+sChanId).length)
@@ -524,8 +527,8 @@ function addChanTab(sChanKeyName, sChanName, sChanTabName, bLightUp)
.append('<span class="chan_title">'+sChanTabName+'</span>') .append('<span class="chan_title">'+sChanTabName+'</span>')
.append('<span class="chan_unread" id="'+sChanUnreadId+'"></span>') .append('<span class="chan_unread" id="'+sChanUnreadId+'"></span>')
.append($('<a id="'+sChanQuitId+'" class="quit_chan clickable"><i class="fa fa-c-close"></i></a>').click(function(e){e.stopPropagation();quitChan($(this).attr('id').substr(databap.consts.chanQuitPrefix.length));})); .append($('<a id="'+sChanQuitId+'" class="quit_chan clickable"><i class="fa fa-c-close"></i></a>').click(function(e){e.stopPropagation();quitChan($(this).attr('id').substr(databap.consts.chanQuitPrefix.length));}));
//Add channel tab name and bind delete button //Add channel tab name and bind delete button
$('#join_chan').before($ChanButton); $('#join_chan').before($ChanButton);
} }
@@ -549,16 +552,16 @@ function quitChan(sChanKeyName)
databap.showError(textStatus); databap.showError(textStatus);
} }
); );
//Delete tab //Delete tab
$('#'+databap.consts.chanPrefix+sChanKeyName).fadeOut('fast', function(){$(this).remove();}); $('#'+databap.consts.chanPrefix+sChanKeyName).fadeOut('fast', function(){$(this).remove();});
//Delete from list //Delete from list
delete databap.vars.chans_list[sChanKeyName]; delete databap.vars.chans_list[sChanKeyName];
//Switch back to another chan //Switch back to another chan
if(sChanName == currentChan()) switchChan(Object.keys(databap.vars.chans_list)[1]); if(sChanName == currentChan()) switchChan(Object.keys(databap.vars.chans_list)[1]);
//Delete messages //Delete messages
databap.getMainElem('#chat_messages').find('p.class_'+sChanKeyName).remove(); databap.getMainElem('#chat_messages').find('p.class_'+sChanKeyName).remove();
} }
@@ -614,7 +617,7 @@ function keyController(e)
else if(chat_message == '/help') displayHelp(); else if(chat_message == '/help') displayHelp();
else if(chat_message.substr(0, 8) == '/invite ') invite($.trim(chat_message.substr(8)), currentChan()); else if(chat_message.substr(0, 8) == '/invite ') invite($.trim(chat_message.substr(8)), currentChan());
else if(chat_message != '') bSuccess = postMessage(); else if(chat_message != '') bSuccess = postMessage();
if(bSuccess) if(bSuccess)
{ {
databap.vars.prev_chat_value = chat_message; databap.vars.prev_chat_value = chat_message;
@@ -644,11 +647,11 @@ function keyController(e)
$This = databap.getMainElem('#message'); $This = databap.getMainElem('#message');
var sChatMsg = $This.val(); var sChatMsg = $This.val();
var iChatMsgLen = sChatMsg.length; var iChatMsgLen = sChatMsg.length;
if(!e.altKey && iChatMsgLen>0) if(!e.altKey && iChatMsgLen>0)
{ {
var iCurPos, iFirstPos, iOffset, sWord, sWordLen, bInvite; var iCurPos, iFirstPos, iOffset, sWord, sWordLen, bInvite;
//Loading previous data //Loading previous data
bLooping = !$.isEmptyObject(databap.tmp('tab_info')); bLooping = !$.isEmptyObject(databap.tmp('tab_info'));
if(bLooping) if(bLooping)
@@ -665,7 +668,7 @@ function keyController(e)
iFirstPos = sChatMsg.substr(0, iCurPos).lastIndexOf(' ') + 1; iFirstPos = sChatMsg.substr(0, iCurPos).lastIndexOf(' ') + 1;
iOffset = sChatMsg.substr(iFirstPos).indexOf(' '); iOffset = sChatMsg.substr(iFirstPos).indexOf(' ');
sWord = sChatMsg.substr(iFirstPos, (iOffset==-1)?iChatMsgLen:iOffset); sWord = sChatMsg.substr(iFirstPos, (iOffset==-1)?iChatMsgLen:iOffset);
//@ excluded //@ excluded
if(sWord.substr(0, 1)=='@') if(sWord.substr(0, 1)=='@')
{ {
@@ -675,35 +678,35 @@ function keyController(e)
} }
sWordLen = sWord.length; sWordLen = sWord.length;
bInvite = (sChatMsg.substr(0, 7) == '/invite'); bInvite = (sChatMsg.substr(0, 7) == '/invite');
//No guess if not at least one letter //No guess if not at least one letter
if(sWordLen>0 || bInvite) if(sWordLen>0 || bInvite)
{ {
//turn to safename for matching //turn to safename for matching
var sSafeWord = getSafeNickname(sWord); var sSafeWord = getSafeNickname(sWord);
var iSafeWordLen = sSafeWord.length; var iSafeWordLen = sSafeWord.length;
//List of current channel users //List of current channel users
var asUserList = databap.tmp(['users', bInvite?databap.consts.all_chan_id:getChanKeyName(currentChan())]); var asUserList = databap.tmp(['users', bInvite?databap.consts.all_chan_id:getChanKeyName(currentChan())]);
var asSafeUserList = Object.keys(asUserList); var asSafeUserList = Object.keys(asUserList);
var iUserListLen = asSafeUserList.length; var iUserListLen = asSafeUserList.length;
//Starting list where we left off //Starting list where we left off
var iCount = 0; var iCount = 0;
var iIndex = 0; var iIndex = 0;
if(bLooping) iIndex = (Number(array_search(databap.tmp(['tab_info', 'safe_nickname']), asSafeUserList)) + 1)%iUserListLen; if(bLooping) iIndex = (Number(array_search(databap.tmp(['tab_info', 'safe_nickname']), asSafeUserList)) + 1)%iUserListLen;
//Looping on user names to find the one(s) starting with the searched word //Looping on user names to find the one(s) starting with the searched word
while(iCount < iUserListLen) while(iCount < iUserListLen)
{ {
//Checking for first letters of user names //Checking for first letters of user names
if(sSafeWord == asSafeUserList[iIndex].substr(0, sSafeWord.length)) break; if(sSafeWord == asSafeUserList[iIndex].substr(0, sSafeWord.length)) break;
//Looping to the top of the list once finished //Looping to the top of the list once finished
iIndex = (iIndex + 1)%iUserListLen; iIndex = (iIndex + 1)%iUserListLen;
iCount++; iCount++;
} }
if(iCount !== iUserListLen) if(iCount !== iUserListLen)
{ {
//Replace text in message input box //Replace text in message input box
@@ -713,7 +716,7 @@ function keyController(e)
var sNickName = asUserList[sSafeNickName]; var sNickName = asUserList[sSafeNickName];
$This.val(sBeforeWord+sNickName+sAfterWord); $This.val(sBeforeWord+sNickName+sAfterWord);
$This.setCursorPosition((sBeforeWord+sNickName).length); $This.setCursorPosition((sBeforeWord+sNickName).length);
//Save value for tab-loops //Save value for tab-loops
if(bLooping) databap.tmp(['tab_info', 'safe_nickname'], sSafeNickName); //not saving index in case of user list refresh if(bLooping) databap.tmp(['tab_info', 'safe_nickname'], sSafeNickName); //not saving index in case of user list refresh
else databap.tmp(['tab_info'], {'chat_msg':sChatMsg, 'cur_pos':iCurPos, 'first_pos':iFirstPos, 'word':sWord, 'safe_nickname':sSafeNickName}); else databap.tmp(['tab_info'], {'chat_msg':sChatMsg, 'cur_pos':iCurPos, 'first_pos':iFirstPos, 'word':sWord, 'safe_nickname':sSafeNickName});
@@ -734,7 +737,7 @@ function keyController(e)
{ {
$this.width(100); $this.width(100);
} }
else if(iInputSize > maxSize) else if(iInputSize > maxSize)
{ {
$this.width(maxSize); $this.width(maxSize);
} }
@@ -771,7 +774,7 @@ function refresh_chat(bReset)
{ {
//Update last read message id //Update last read message id
self.tmp('last_message_id', Math.max(result.last_message_id, prevLastMsgId)); self.tmp('last_message_id', Math.max(result.last_message_id, prevLastMsgId));
//Display messages //Display messages
$.each $.each
( (
@@ -781,14 +784,14 @@ function refresh_chat(bReset)
addMessage(message_info, bReset); addMessage(message_info, bReset);
} }
); );
//Image display //Image display
setImageDisplay(); setImageDisplay();
//News //News
if(databap.tmp('get_news') === true && !bReset) getNews(); if(databap.tmp('get_news') === true && !bReset) getNews();
databap.tmp('get_news', false); databap.tmp('get_news', false);
//Nicknames changes //Nicknames changes
if(updateUsersList === true || bReset) if(updateUsersList === true || bReset)
{ {
@@ -818,22 +821,25 @@ function refresh_chat(bReset)
function addMessage(message_info, bReset) function addMessage(message_info, bReset)
{ {
message_info.nickname = message_info.nickname || ''; message_info.nickname = message_info.nickname || '';
var sChanKeyName = message_info.id_chan; var sChanKeyName = message_info.id_chan;
var sMsgPrefix = '<a class="user clickable" title="Ecrire un PM &agrave; '+message_info.nickname+'">'+message_info.nickname+'</a><span class="console">&gt;</span>'; var sMsgPrefix = '<a class="user clickable" title="Ecrire un PM &agrave; '+message_info.nickname+'">'+message_info.nickname+'</a><span class="console">&gt;</span>';
var msg_body = ''; var msg_body = '';
var sUnreadChanName, iUnreadCount; var sUnreadChanName, iUnreadCount;
var bSystemMsg = false; var bSystemMsg = false;
var bImage = false; var bImage = false;
var sNotif = '';
switch(message_info.msg_class) switch(message_info.msg_class)
{ {
case databap.consts.msg_types.user: case databap.consts.msg_types.user:
msg_body = sMsgPrefix+'<span class="text">'+message_info.message+'</span>'; msg_body = sMsgPrefix+'<span class="text">'+message_info.message+'</span>';
sNotif = message_info.nickname+' : '+message_info.message;
break; break;
case databap.consts.msg_types.news: case databap.consts.msg_types.news:
databap.tmp('get_news', true); databap.tmp('get_news', true);
msg_body = '<span class="text action">'+message_info.nickname+' a une news : <span class="news"><i class="fa fa-30 fa-c-news"></i> '+message_info.message+' <i class="fa fa-30 fa-c-news"></i></span></span>'; msg_body = '<span class="text action">'+message_info.nickname+' a une news : <span class="news"><i class="fa fa-30 fa-c-news"></i> '+message_info.message+' <i class="fa fa-30 fa-c-news"></i></span></span>';
sNotif = message_info.nickname+' a une news : '+message_info.message;
break; break;
case databap.consts.msg_types.add.code: case databap.consts.msg_types.add.code:
var url = databap.getInternalLink('code', message_info.message); var url = databap.getInternalLink('code', message_info.message);
@@ -859,6 +865,7 @@ function addMessage(message_info, bReset)
msgTargetUser = message_info.message.substr(1, slicePos - 1); msgTargetUser = message_info.message.substr(1, slicePos - 1);
var msg = message_info.message.slice(slicePos + 1); var msg = message_info.message.slice(slicePos + 1);
msg_body = '<a class="user clickable" title="Ecrire un PM &agrave; '+message_info.nickname+'">'+message_info.nickname+'</a><span class="console"> <span class="highlight">&#64;'+msgTargetUser+'</span>&gt;</span><span class="text">'+msg+'</span>'; msg_body = '<a class="user clickable" title="Ecrire un PM &agrave; '+message_info.nickname+'">'+message_info.nickname+'</a><span class="console"> <span class="highlight">&#64;'+msgTargetUser+'</span>&gt;</span><span class="text">'+msg+'</span>';
sNotif = message_info.nickname+' @'+msgTargetUser+' : '+msg;
break; break;
case databap.consts.msg_types.nick: case databap.consts.msg_types.nick:
msg_body = '<span class="text">'+message_info.message+' (<a href="'+databap.getInternalLink('profil', message_info.id_user)+'" target="_blank"><i class="fa fa-c-profile fa-inline"></i>'+message_info.name+'</a>)</span>'; msg_body = '<span class="text">'+message_info.message+' (<a href="'+databap.getInternalLink('profil', message_info.id_user)+'" target="_blank"><i class="fa fa-c-profile fa-inline"></i>'+message_info.name+'</a>)</span>';
@@ -875,6 +882,7 @@ function addMessage(message_info, bReset)
var msg = '<a href="'+message_info.message.url+'" target="_blank" title="'+message_info.message.title+'"><img src="'+message_info.message.url_img+'" width="'+message_info.message.width+'" height="'+message_info.message.height+'" class="proxy" /></a>'; var msg = '<a href="'+message_info.message.url+'" target="_blank" title="'+message_info.message.title+'"><img src="'+message_info.message.url_img+'" width="'+message_info.message.width+'" height="'+message_info.message.height+'" class="proxy" /></a>';
msg_body = sMsgPrefix+'<span class="text">'+msg+'</span>'; msg_body = sMsgPrefix+'<span class="text">'+msg+'</span>';
bImage = true; bImage = true;
sNotif = message_info.nickname+' a posté une image';
break; break;
case databap.consts.msg_types.reboot: case databap.consts.msg_types.reboot:
if(!bReset) if(!bReset)
@@ -915,7 +923,7 @@ function addMessage(message_info, bReset)
msg_body = '<span class="text">'+message_info.nickname+' a modifi&eacute; la table <a href="'+url+'" target="_blank"><i class="fa fa-c-table fa-inline"></i>'+message_info.description+'</a></span>'; msg_body = '<span class="text">'+message_info.nickname+' a modifi&eacute; la table <a href="'+url+'" target="_blank"><i class="fa fa-c-table fa-inline"></i>'+message_info.description+'</a></span>';
break; break;
} }
if(msg_body != '') if(msg_body != '')
{ {
//Hide image button //Hide image button
@@ -929,7 +937,7 @@ function addMessage(message_info, bReset)
$Banner.find('.banner_title').width(message_info.message.width - 31); $Banner.find('.banner_title').width(message_info.message.width - 31);
$Msg.find('a').addClass('img_box').append($Banner); $Msg.find('a').addClass('img_box').append($Banner);
} }
//Adding message to channel panel //Adding message to channel panel
$Message = $('<p>', {'class':message_info.msg_class+' class_'+sChanKeyName+' hide round_right'}) $Message = $('<p>', {'class':message_info.msg_class+' class_'+sChanKeyName+' hide round_right'})
.append($('<span>', {'class':'time'}).text(((message_info.date==databap.consts.cur_date)?'':message_info.date+' - ')+message_info.time)) .append($('<span>', {'class':'time'}).text(((message_info.date==databap.consts.cur_date)?'':message_info.date+' - ')+message_info.time))
@@ -937,15 +945,28 @@ function addMessage(message_info, bReset)
$Message.find('.chan_link').click(function(){joinChan($(this).find('.chan_text').text());}); $Message.find('.chan_link').click(function(){joinChan($(this).find('.chan_text').text());});
$Message.find('.user').click(setPm); $Message.find('.user').click(setPm);
databap.getMainElem('#chat_messages').append($Message); databap.getMainElem('#chat_messages').append($Message);
//Unread messages //Unread messages
if(!bReset && !bSystemMsg /* && message_info.id_user!=databap.vars.user_id */) if(!bReset && !bSystemMsg /* && message_info.id_user!=databap.vars.user_id */)
{ {
sUnreadChanName = getChanName(message_info.id_chan); sUnreadChanName = getChanName(message_info.id_chan);
iUnreadCount = (databap.tmp(['unread_msg', sUnreadChanName]) || 0) + 1; iUnreadCount = (databap.tmp(['unread_msg', sUnreadChanName]) || 0) + 1;
databap.tmp(['unread_msg', sUnreadChanName], iUnreadCount); databap.tmp(['unread_msg', sUnreadChanName], iUnreadCount);
//Desktop Notification
if(!databap.vars.focus && sNotif != '' && Push.Permission.has()) {
Push.create('Databap - '+message_info.nickname, {
body: sNotif,
icon: databap.consts.app_image_folder+(databap.tmp(['logos', message_info.id_user]) || 'logo_25.png'),
timeout: 4000,
onClick: function () {
window.focus();
this.close();
}
});
}
} }
//Move to bottom if user is typing //Move to bottom if user is typing
if(message_info.id_user===databap.vars.user_id) self.tmp('scrolling', false); if(message_info.id_user===databap.vars.user_id) self.tmp('scrolling', false);
} }
@@ -963,7 +984,7 @@ function setImageDisplay()
$Images.find('.banner .fa').toggleClass('fa-c-image', !self.vars2('opt_chat_images')); $Images.find('.banner .fa').toggleClass('fa-c-image', !self.vars2('opt_chat_images'));
$Images.find('.banner .fa').toggleClass('fa-c-close', self.vars2('opt_chat_images')); $Images.find('.banner .fa').toggleClass('fa-c-close', self.vars2('opt_chat_images'));
$Images.find('.banner .button').attr('title', (self.vars2('opt_chat_images')?'Cacher':'Afficher')+' les images'); $Images.find('.banner .button').attr('title', (self.vars2('opt_chat_images')?'Cacher':'Afficher')+' les images');
databap.updateScrollBar('bottom'); databap.updateScrollBar('bottom');
} }
@@ -982,7 +1003,7 @@ function refresh_users()
databap.getMainElem('#connected_users').empty(); databap.getMainElem('#connected_users').empty();
databap.tmp('users', {}); databap.tmp('users', {});
databap.tmp('id_users', {}); databap.tmp('id_users', {});
$.each $.each
( (
result, result,
@@ -1000,7 +1021,8 @@ function refresh_users()
databap.tmp(['users', sChankeyName, sSafeNickName], sNickName); databap.tmp(['users', sChankeyName, sSafeNickName], sNickName);
databap.tmp(['users', databap.consts.all_chan_id, sSafeNickName], sNickName); databap.tmp(['users', databap.consts.all_chan_id, sSafeNickName], sNickName);
databap.tmp(['id_users', sNickName], user_info.id_user); databap.tmp(['id_users', sNickName], user_info.id_user);
databap.tmp(['logos', user_info.id_user], user_info.logo);
//Append name to user list box //Append name to user list box
var sProfileLink = databap.getInternalLink('profil', user_info.id_user); var sProfileLink = databap.getInternalLink('profil', user_info.id_user);
var sMission = user_info.status || ''; var sMission = user_info.status || '';
@@ -1034,7 +1056,7 @@ function refresh_users()
function getSafeNickname(sNickName) function getSafeNickname(sNickName)
{ {
return sNickName.stripVowelAccent().toLowerCase(); return sNickName.stripVowelAccent().toLowerCase();
} }
function setPm() function setPm()
@@ -1059,14 +1081,14 @@ function displayHelp()
{ {
//Get template //Get template
$Help = $('#help').clone().attr('id', 'help_'+Math.floor((Math.random()*1000))); $Help = $('#help').clone().attr('id', 'help_'+Math.floor((Math.random()*1000)));
//Visible on all channels //Visible on all channels
$Help.find('p').addClass('class_'+databap.consts.all_chan_id); $Help.find('p').addClass('class_'+databap.consts.all_chan_id);
$Help.appendTo('#chat_messages').slideDown('fast', function() $Help.appendTo('#chat_messages').slideDown('fast', function()
{ {
databap.updateScrollBar('bottom'); databap.updateScrollBar('bottom');
}); });
//Close button activation //Close button activation
$Help.find('#close_help').click(function() $Help.find('#close_help').click(function()
{ {
@@ -1076,4 +1098,4 @@ function displayHelp()
}); });
}); });
} }
</script> </script>

View File

@@ -11,6 +11,7 @@
<script type="text/javascript" src="jquery/jquery.min.js?v[#]version[#]"></script> <script type="text/javascript" src="jquery/jquery.min.js?v[#]version[#]"></script>
<script type="text/javascript" src="jquery/jquery.mods.js?v[#]version[#]"></script> <script type="text/javascript" src="jquery/jquery.mods.js?v[#]version[#]"></script>
<script type="text/javascript" src="jquery/fileuploader.js?v[#]version[#]"></script> <script type="text/javascript" src="jquery/fileuploader.js?v[#]version[#]"></script>
<script type="text/javascript" src="jquery/push.min.js?v[#]version[#]"></script>
<script type="text/javascript" src="jquery/common.js?v[#]version[#]"></script> <script type="text/javascript" src="jquery/common.js?v[#]version[#]"></script>
<script type="text/javascript" src="jquery/databap.js?v[#]version[#]"></script> <script type="text/javascript" src="jquery/databap.js?v[#]version[#]"></script>
<script type="text/javascript"> <script type="text/javascript">
@@ -77,4 +78,4 @@
</div> </div>
</div> </div>
</body> </body>
</html> </html>