Skip to content

Commit

Permalink
[en] New parameter 'max_displayed_lines' (by default 150) used to fre…
Browse files Browse the repository at this point in the history
…e browser's memory when lot of lines are written in the chat. [1h20]

[fr] Nouveau paramètre 'max_displayed_lines' (par défaut 150) permettant de libérer la mémoire du navigateur lorsque bcp de messages sont affichés. [1h20]

git-svn-id: https://phpfreechat.svn.sourceforge.net/svnroot/phpfreechat/trunk@887 2772adf2-ac07-0410-9d30-e29d8120292e
  • Loading branch information
kerphi committed Dec 4, 2006
1 parent cbd0431 commit 0ec4e0e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/client/chat.js.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
var pfc_showwhosonline = <?php echo $json->encode($showwhosonline); ?>;
var pfc_focus_on_connect = <?php echo $json->encode($focus_on_connect); ?>;
var pfc_max_text_len = <?php echo $json->encode($max_text_len); ?>;
var pfc_max_displayed_lines = <?php echo $json->encode($max_displayed_lines); ?>;
var pfc_quit_on_closedwindow = <?php echo $json->encode($quit_on_closedwindow); ?>;
var pfc_debug = <?php echo $json->encode($debug); ?>;
var pfc_btn_sh_smileys = <?php echo $json->encode($btn_sh_smileys); ?>;
Expand Down
41 changes: 30 additions & 11 deletions src/client/pfcclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ pfcClient.prototype = {
handleComingRequest: function( cmds )
{
var msg_html = $H();
var max_msgid = 0;

//alert(cmds.inspect());

Expand Down Expand Up @@ -804,20 +805,20 @@ pfcClient.prototype = {
line += '<span class="pfc_heure">'+ time +'</span> ';
if (cmd == 'send')
{
line += ' <span class="pfc_nick">';
line += '&#x2039;';
line += '<span ';
line += ' <span class="pfc_nick">';
line += '&#x2039;';
line += '<span ';
line += 'onclick="pfc.insert_text(\'' + sender.replace("'", '\\\'') + ', \',\'\',false)" ';
line += 'class="pfc_nickmarker pfc_nick_'+ hex_md5(_to_utf8(sender)) +'">';
line += sender;
line += '</span>';
line += '&#x203A;';
line += '</span> ';
line += 'class="pfc_nickmarker pfc_nick_'+ hex_md5(_to_utf8(sender)) +'">';
line += sender;
line += '</span>';
line += '&#x203A;';
line += '</span> ';
}
if (cmd == 'notice' || cmd == 'me')
line += '<span class="pfc_words">* '+ this.parseMessage(param) +'</span> ';
line += '<span class="pfc_words">* '+ this.parseMessage(param) +'</span> ';
else
line += '<span class="pfc_words">'+ this.parseMessage(param) +'</span> ';
line += '<span class="pfc_words">'+ this.parseMessage(param) +'</span> ';
line += '</div>';

if (oldmsg == 0)
Expand All @@ -828,7 +829,7 @@ pfcClient.prototype = {
var tabid = recipientid;
if (this.gui.getTabId() != tabid)
this.gui.notifyTab(tabid);
// notify the window (change the title)
// notify the window (change the title)
if (!this.detectactivity.isActive() && pfc_notify_window)
this.gui.notifyWindow();
}
Expand All @@ -837,6 +838,9 @@ pfcClient.prototype = {
msg_html[recipientid] = line;
else
msg_html[recipientid] += line;

// remember the max message id in order to clean old lines
if (max_msgid < id) max_msgid = id;
}

// loop on all recipients and post messages
Expand All @@ -858,6 +862,21 @@ pfcClient.prototype = {
recipientdiv.appendChild(m);
this.gui.scrollDown(tabid, m);
}

// delete the old messages from the client (save some memory)
var limit_msgid = max_msgid - pfc_max_displayed_lines;
var elt = $('pfc_msg'+limit_msgid);
while (elt)
{
// delete this element to save browser memory
if (is_ff)
elt.innerHTML = '';
else
// this code don't work in FF, why ? don't know ..
elt.parentElement.removeChild(elt);
limit_msgid--;
elt = $('pfc_msg'+limit_msgid);
}
},

/**
Expand Down
3 changes: 2 additions & 1 deletion src/pfcglobalconfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class pfcGlobalConfig
var $refresh_delay = 5000; // in mili-seconds (5 seconds)
var $max_refresh_delay = 60000; // in mili-seconds (60 seconds)
var $timeout = 20000; // in mili-seconds (20 seconds)
var $max_msg = 20;
var $max_msg = 20; // number of messages keept in the history (this is what you see when you reload the chat)
var $max_displayed_lines = 150; // maximum number of displayed lines (old lines will be deleted to save browser's memory)
var $quit_on_closedwindow = true; // could be annoying because the reload event is the same as a close event
var $focus_on_connect = true;
var $connect_at_startup = true;
Expand Down

0 comments on commit 0ec4e0e

Please sign in to comment.