fix bug: force scrollbar to the bottom while scrolling in chat when new
message pops up new rss added : cat = news
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
class Databap extends PhpObject
|
||||
{
|
||||
//Common Constants
|
||||
const VERSION = '1.0.0-RC2'; //Versioning: <Main_Version>.<Enhancement_Package>.<Patch>-<Release_Candidate>
|
||||
const VERSION = '1.0.0-RC3'; //Versioning: <Main_Version>.<Enhancement_Package>.<Patch>-<Release_Candidate>
|
||||
const VERSION_DATE = '02/07/2014';
|
||||
const EXPECTED_PAGE_COOKIE = 'exp_page';
|
||||
const MAIN_SEPARATOR = ' ';
|
||||
@@ -96,6 +96,7 @@ class Databap extends PhpObject
|
||||
const CHAT_IMG_MAX_WIDTH = 700;
|
||||
const CHAT_IMG_MAX_HEIGHT = 1080;
|
||||
const JSON_PREFIX = '[\-JSON-/]';
|
||||
const MAX_NB_NEWS = 3;
|
||||
|
||||
//Options Name Id Constants
|
||||
const LANG_FR = 'FR';
|
||||
@@ -413,7 +414,31 @@ class Databap extends PhpObject
|
||||
$oFeed = new Feed($asDesc);
|
||||
|
||||
//Building items
|
||||
switch(mb_strtolower($sCat))
|
||||
if($sCat=='news')
|
||||
{
|
||||
$asNews = $this->getNews(false);
|
||||
$iLinkId = count($asNews);
|
||||
foreach($asNews as $iMsgId=>$asRow)
|
||||
{
|
||||
//TODO mutualiser avec le reste
|
||||
$sChatlink = $this->getInternalLink('chat', $iMsgId);
|
||||
$asItem = array
|
||||
(
|
||||
'title'=>'Lien'.($sCat==''?'':' - '.$sCat).' #'.$iLinkId,
|
||||
'category'=>$sCat,
|
||||
'description'=>$asRow['message'],
|
||||
'author'=>$asRow['nickname'],
|
||||
'link'=>$sChatlink,
|
||||
'pub_date'=>$asRow['time'],
|
||||
'guid'=>$sChatlink
|
||||
);
|
||||
$oFeed->addItem($asItem);
|
||||
$iLinkId -= 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch($sCat)
|
||||
{
|
||||
case '9gag':
|
||||
$sRegEx = '(https?://|www\\.)(.*)9gag\\.com';
|
||||
@@ -429,8 +454,8 @@ class Databap extends PhpObject
|
||||
break;
|
||||
}
|
||||
$asResult = $this->oMySql->selectRows(array('select'=>array('id_message', 'nickname', 'message', 'led'), 'from'=>'messages', 'constraint'=>array('message'=>$sRegEx), 'constOpe'=>array('message'=>' REGEXP ')));
|
||||
$sPattern = '/(https?\:\/\/|www\.)[\S]+\.[a-zA-Z]{2,4}([\S]*)/ui';
|
||||
|
||||
$sPattern = '/(https?\:\/\/|www\.)[\S]+\.[a-zA-Z]{2,4}([\S]*)/ui';
|
||||
foreach($asResult as $iLinkId=>$asRow)
|
||||
{
|
||||
//get link out of message
|
||||
@@ -451,6 +476,7 @@ class Databap extends PhpObject
|
||||
);
|
||||
$oFeed->addItem($asItem);
|
||||
}
|
||||
}
|
||||
|
||||
return $oFeed->getFeed();
|
||||
}
|
||||
@@ -462,7 +488,8 @@ class Databap extends PhpObject
|
||||
|
||||
//Update and spread the news
|
||||
$asResult = array();
|
||||
if(date('N')>5 || date('G')>19) $asResult[] = "Pas de mise-à-jour pendant le week end ou en soirée.";
|
||||
$iTimeStamp = time();
|
||||
if(date('N', $iTimeStamp)>5 || date('G', $iTimeStamp)>19) $asResult[] = "Pas de mise-à-jour pendant le week end ou en soirée.";
|
||||
else
|
||||
{
|
||||
foreach($asArticles as $asArticle)
|
||||
@@ -1833,7 +1860,7 @@ class Databap extends PhpObject
|
||||
return $this->jsonExport($asMessages);
|
||||
}
|
||||
|
||||
public function getNews()
|
||||
public function getNews($bExport=true)
|
||||
{
|
||||
$sMsgIdCol = MySqlManager::getId(self::MSG_TABLE);
|
||||
$sMsgTxtCol = MySqlManager::getText(self::MSG_TABLE);
|
||||
@@ -1860,20 +1887,21 @@ class Databap extends PhpObject
|
||||
{
|
||||
if($asNews[$iKey]['type']==self::MESSAGE_STATUS) $asNews[$iKey][$sMsgTxtCol] = $asNews[$iKey]['nickname'].' '.$asNews[$iKey][$sMsgTxtCol];
|
||||
$asNews2[] = $asNews[$iKey];
|
||||
if(count($asNews2)==3) break;
|
||||
if(count($asNews2)==self::MAX_NB_NEWS) break;
|
||||
}
|
||||
|
||||
$asFormatNews = array();
|
||||
foreach($asNews2 as $asNew)
|
||||
{
|
||||
$iMsgId = '-'.$asNew[$sMsgIdCol];
|
||||
$asFormatNews[$iMsgId]['time'] = $asNew['led'];
|
||||
$asFormatNews[$iMsgId]['time_desc'] = ToolBox::getDateTimeDesc($asNew['led']);
|
||||
$asFormatNews[$iMsgId]['message'] = self::getDescriptionFormat($asNew['message']);
|
||||
$asFormatNews[$iMsgId]['nickname'] = self::getNickNameFormat($asNew['nickname']);
|
||||
}
|
||||
|
||||
$sSuccess = (count($asFormatNews)>0);
|
||||
return $this->getJsonPostResult($sSuccess, $sSuccess?'':'Aucune news', array('news'=>$asFormatNews));
|
||||
return $bExport?$this->getJsonPostResult($sSuccess, $sSuccess?'':'Aucune news', array('news'=>$asFormatNews)):$asFormatNews;
|
||||
}
|
||||
|
||||
private function getConnectedChans($iuserId=0)
|
||||
|
||||
@@ -82,6 +82,8 @@ databap.pageInit = function()
|
||||
self.vars2('unread_msg', 'object');
|
||||
self.tmp('news_period', 10*60*1000);
|
||||
self.tmp('get_news', false);
|
||||
self.tmp('last_message_id', '0');
|
||||
self.tmp('scrolling', 'boolean');
|
||||
|
||||
//Main elements
|
||||
$MsgInput = databap.getMainElem('#message');
|
||||
@@ -93,8 +95,10 @@ databap.pageInit = function()
|
||||
$MsgInput.keyup(function(event){add_message(event);});
|
||||
|
||||
//Loading the chat
|
||||
databap.vars.last_message_id = '0';
|
||||
self.initScrollBar('#chat_container', '#chat_messages_box', '#chat_messages');
|
||||
$('#chat_container').find('.thumb')
|
||||
.mousedown(function(){self.tmp('scrolling', true);})
|
||||
.mouseup(function(){self.tmp('scrolling', false);});
|
||||
|
||||
//Loading Chans
|
||||
setChanButton();
|
||||
@@ -380,7 +384,7 @@ function switchChan(sChanKeyName)
|
||||
//Show current channel messages
|
||||
databap.getMainElem('#chat_messages').find('p').hide();
|
||||
databap.getMainElem('#chat_messages').find('p.class_'+sChanKeyName+', p.class_'+databap.consts.all_chan_id).show();
|
||||
databap.updateScrollBar('bottom');
|
||||
databap.updateScrollBar(self.tmp('scrolling')?'relative':'bottom');
|
||||
|
||||
//Show Current channel members
|
||||
databap.getMainElem('#connected_users').find('p').hide();
|
||||
@@ -624,7 +628,7 @@ function refresh_chat(bReset)
|
||||
{
|
||||
if(bReset)
|
||||
{
|
||||
databap.vars.last_message_id = 0;
|
||||
self.tmp('last_message_id', 0);
|
||||
databap.getMainElem('#chat_messages').empty();
|
||||
}
|
||||
databap.getInfo
|
||||
@@ -632,13 +636,13 @@ function refresh_chat(bReset)
|
||||
'messages',
|
||||
function(result)
|
||||
{
|
||||
var prevLastMsgId = databap.vars.last_message_id;
|
||||
var prevLastMsgId = self.tmp('last_message_id');;
|
||||
updateUsersList = false;
|
||||
databap.resetIcon();
|
||||
if(databap.vars.last_message_id < result.last_message_id || bReset)
|
||||
if(prevLastMsgId < result.last_message_id || bReset)
|
||||
{
|
||||
//Update last read message id
|
||||
databap.vars.last_message_id = Math.max(result.last_message_id, prevLastMsgId);
|
||||
self.tmp('last_message_id', Math.max(result.last_message_id, prevLastMsgId));
|
||||
|
||||
//Display messages
|
||||
$.each
|
||||
@@ -659,16 +663,15 @@ function refresh_chat(bReset)
|
||||
databap.tmp('get_news', false);
|
||||
|
||||
//Nicknames changes
|
||||
if(updateUsersList === true || prevLastMsgId == 0)
|
||||
if(updateUsersList === true || bReset)
|
||||
{
|
||||
databap.updateScrollBar('bottom');
|
||||
refresh_users();
|
||||
refresh_users(); //which execute switchChan()
|
||||
updateUsersList = false;
|
||||
}
|
||||
else switchChan();
|
||||
}
|
||||
},
|
||||
{message_id:databap.vars.last_message_id},
|
||||
{message_id:self.tmp('last_message_id')},
|
||||
'json',
|
||||
function(textStatus)
|
||||
{
|
||||
@@ -820,40 +823,17 @@ function refresh_users()
|
||||
var profileLink = databap.getInternalLink('profil', user_info.id_user);
|
||||
var mission = 'Mission actuelle : '+(user_info.status || 'Aucune');
|
||||
var pm = 'Cliquez pour lancer un channel privé avec '+user_info.name+' ('+user_info.company+')';
|
||||
var user = $('<p>', {'class':'connected_user class_'+sChankeyName})
|
||||
var $user = $('<p>', {'class':'connected_user class_'+sChankeyName})
|
||||
.append($('<a>', {'class':'connected_user_logo', href:profileLink, title:mission, target:'_blank'})
|
||||
.append($('<img>', {src:databap.consts.app_image_folder+user_info.logo}))
|
||||
.append((user_info.afk=='1')?$('<i>', {class:'fa fa-c-afk afk'}):''))
|
||||
.append($('<a>', {'class':'connected_user_name clickable '+sNickName, id:user_info.id_user, title:pm}).text(sNickName));
|
||||
|
||||
$user = $(user)/*.css("visibility", "hidden")*/;
|
||||
$user.find('.connected_user_name').click(joinPmChan);
|
||||
databap.getMainElem('#connected_users').append($user);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
//Resize Nickname
|
||||
/*var iMaxSize = 126 - 24 - 5; //boxSize - imageSize - marginLeftSize
|
||||
$.each
|
||||
(
|
||||
users_list,
|
||||
function(user_id, user)
|
||||
{
|
||||
databap.getMainElem('.'+user).each(function()
|
||||
{
|
||||
$nick = $(this);
|
||||
while($nick.width() > iMaxSize)
|
||||
{
|
||||
sNickName = $nick.text();
|
||||
$nick.text(sNickName.substr(0, sNickName.length - 1));
|
||||
}
|
||||
$nick.parent().css("visibility", "visible");
|
||||
});
|
||||
}
|
||||
);*/
|
||||
|
||||
switchChan();
|
||||
},
|
||||
{},
|
||||
@@ -900,9 +880,12 @@ function displayHelp()
|
||||
});
|
||||
|
||||
//Close button activation
|
||||
$Help.find('#close_help').click(function(){$(this).closest('.help').slideUp('fast', function()
|
||||
$Help.find('#close_help').click(function()
|
||||
{
|
||||
$(this).closest('.help').slideUp('fast', function()
|
||||
{
|
||||
databap.updateScrollBar('bottom');
|
||||
});});
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user