I can't tell but is the chat room supposed to make everyone's name in a different color? It doesn't seem to be doing that on our site:

http://www.tribalectic.com/Drupal/chatrooms/chat/1

Am I missing something or does this feature not exist?

-Drew

Comments

manimal’s picture

I'm having the same problem.. they just all come up red text. I'm using the dev release from january of this year.

Hinode’s picture

The persistent red color seems to be a bug in the following code: ($Id: chatroom.module,v 1.59.2.67 2007/10/05 19:37:34 darrenoh Exp $)

Line 1310

function _chatroom_load_hex_colours() {
  $colours = array();
  $hex = array('00', '33', '66', '99', 'CC', 'FF');
  foreach ($hex as $rkey => $rvalue) {
    foreach ($hex as $gkey => $gvalue) {
      foreach ($hex as $bkey => $bvalue) {
        if ($rkey + $gkey + $bkey + 3 < 8) {
          $colour->colour = '#'. $rvalue . $gvalue . $bvalue;
          $colour->unUsed = TRUE;
          $colours[] = $colour;
        }
      }
    }
  }
  return $colours;
}

The array $colours[] was populated with the same object ($colour), thus, have the same reference in memory and all elements assume the value of the last assign (color = #CC0000).

I do not know PHP, but the following code work for me and maybe indicate a way to more simple solutions.

class objColour {
	var $colour;
	var $unUsed;
}
/**
 * Get an array of dark hex values for user colours.
 */
function _chatroom_load_hex_colours() {
  $colours = array();
  $hex = array('00', '33', '66', '99', 'CC', 'FF');
  foreach ($hex as $rkey => $rvalue) {
    foreach ($hex as $gkey => $gvalue) {
      foreach ($hex as $bkey => $bvalue) {
        if ($rkey + $gkey + $bkey + 3 < 8) {
          $colour = new objColour;
          $colour->colour = '#'. $rvalue . $gvalue . $bvalue;
          $colour->unUsed = TRUE;
          $colours[] = $colour;
        }
      }
    }
  }
  return $colours;
}

If users colors yet do not work, try enable the "Chat Room: chat on-line list" block. I'm not sure, but the "Drupal.settings.chatroom.chatUsers.length" is not actualizing and a call to the on-line list do this.

manimal’s picture

tried it, and it didn't seem to work for me..

I have the online list block enabled as well, and it shows the red usernames in that as well..

Hinode’s picture

I do not know why the code above didn't work for you...

In fact, I'm using drupal 5.5 and chatroom 5.x-1.x-dev (not 5.x-1.9).

You may try to verify if the code is ok by adding the following line (try before and after the suggested patch) and see if the array was populated in the right way.

function _chatroom_load_hex_colours() {
  $colours = array();
  $hex = array('00', '33', '66', '99', 'CC', 'FF');
  foreach ($hex as $rkey => $rvalue) {
    foreach ($hex as $gkey => $gvalue) {
      foreach ($hex as $bkey => $bvalue) {
        if ($rkey + $gkey + $bkey + 3 < 8) {
		  $colour = new objColour;
          $colour->colour = '#'. $rvalue . $gvalue . $bvalue;
          $colour->unUsed = TRUE;
          $colours[] = $colour;
        }
      }
    }
  }
  drupal_set_message('<pre>' . print_r($colours,1) . '</pre>');
  return $colours;
}

(don't forget excluding the tags)

With the patched code, all times you enter in a chatroom the header should be like this:

Array
(
    [0] => objColour Object
        (
            [colour] => #000000
            [unUsed] => 1
        )

    [1] => objColour Object
        (
            [colour] => #000033
            [unUsed] => 1
        )
...

Otherwise, with the orignal code, all colors will be #CC0000 (at least it was happening here).

In addition, examine the chatroom.js (line 260):

p.css('color', Drupal.chatroom.chat.getUserColour(msgs[i].user));

and replace to:

alert('color: ' + Drupal.chatroom.chat.getUserColour(msgs[i].user));
p.css('color', Drupal.chatroom.chat.getUserColour(msgs[i].user));

Now, every message you send to chat trigger an alert window that show the color assign to the current user (or other user, if sent by a remote machine). In fact, that color was (random) assigned the first time the current user send a message. A remote user color was assign the same way, but here the Drupal.settings.chatroom.chatUsers.length must reflect the correct number of users in a chatroom, otherwise the user get a black color (undefined).

Obs: I note that the user colors you see in your screen is not the same that others will see in yours.

manimal’s picture

okay, that worked..

seemed the code you posted did work.. I just didn't think you changed much more than the part attached above the "function _chatroom_load_hex_colours" section.. I missed the line: $colour = new objColour;

works nicely.. thanks a lot!

szegadlo’s picture

The much simpler solution is to put:

$colours[] = clone $colour;

instead of:

$colours[] = $colour;

And that's it. (On-line block has to be enabled.)

tsaorin’s picture

Title: Color for usernames » Changing too texts of each user

It would be prettier if the text of each user was printed with the same color of the user name.

I don't know much php, but I suppose It would be easy to find where Chatroom write the text and applies the same color its author.

Darren Oh’s picture

Title: Changing too texts of each user » Color for usernames
Flying Drupalist’s picture

Fix works for me. Hopefully this will go into the next patch.

geerlingguy’s picture

Version: 5.x-1.9 » 6.x-2.9

Bumping to current version - I'm wondering where to configure this at all... everyone gets a blue username in my chats; I'd like to have users have different colors (maybe even let users choose a color on their profile page—that'd be icing on the cake, though).