Expand my Community achievements bar.

SOLVED

SimpleChatModel: nameColor/timeStampColor/timeFormat not working?

Avatar

Former Community Member

I was trying to set som different colors in my chat using the SimpleChat, and I can't really figure out what's happening. I stripped it down thinking I was ovveriding something somewhere and I only have a application containing a SimpleChat.

//SimpleChat

<ns:SimpleChat id="chat" width="100%" height="100%"/>

//Setting colors in ConnectSessionContainers creationComplete

chat.model.nameColor = 0xFFFFFF;
chat.model.timeStampColor = 0xFFFFFF;
chat.model.timeFormat = "24h";

This makes the colors yellowish instead of white and the timeFormat remains the same. 0xFF0000 makes a nice purple color instead of red.

I'm using the newest SDK (Version 1.3.0) for player 10.1.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Hi,

Ok, I ran the timeformat thing for you and it should work be sent before a message is sent. If you have already sent a message with a particular timeformat, and then changed the timeformat, the new format won't be applicable to the history messages and would be only applicable to any new messages that you send. So, in case you want to particular timeformat for all messages, set it before sending any message and then it will be consistent throughout.

Now , coming to colors in chat, I digged deep and there was a bug in our code for hex to int conversion with colors and vice versa. Here is the fix for you as of now, we will include it in the next update

I am attaching you the formatMessageDescriptor method in SimpleChatModel.as class. Either you replace the existing model source's this method with the one I give or you can subclass that method and use my code.

Here is the method

public function formatMessageDescriptor(p_msgDesc:ChatMessageDescriptor):String

{

var timeStampStr:String = "";

var nameColor:String = getNameColor(p_msgDesc);

var msgColor:String = getMsgColor(p_msgDesc);

var tStampColor:String = getTimeStampColor(p_msgDesc);

var privateModifier:String = "";

if (p_msgDesc.publisherID == userManager.myUserID && pmsgDesc.recipient!=null) {

// it was a message I sent privately to another

privateModifier = " ("Localization.impl.getString("to")" "p_msgDesc.recipientDisplayName")";

} else if (p_msgDesc.role>UserRoles.VIEWER) {

// it was a message sent to a role group, and I can see it (either because I sent it or am in the group)

privateModifier = " ("Localization.impl.getString("to")" "((p_msgDesc.role == UserRoles.OWNER)? Localization.impl.getString("hosts") : Localization.impl.getString("participants"))")";

} else if (p_msgDesc.recipient!=null) {

// it was a message sent privately to me

privateModifier = " ("Localization.impl.getString("privately")")";

}

if (_useTimeStamps && !isNaN(p_msgDesc.timeStamp)) {

var d:Date = new Date(p_msgDesc.timeStamp);

//var hourMinutes:Array = d.toTimeString().split(":").slice(0,2);

var hourMinutes:Array = ;

if (hourMinutes[1] < 10) { //pad minutes if needed

hourMinutes[1] = "0"+hourMinutes[1];

}

if (_timeFormat == TIMEFORMAT_AM_PM) {

var timeTemplate:String = Localization.impl.getString("%12%:%M% %D%");

timeTemplate = timeTemplate.replace("%M%", hourMinutes[1]);

var h:uint = hourMinutes[0];

if (h >= 12) {

h -= 12;

timeTemplate = timeTemplate.replace("%D%", Localization.impl.getString("pm"));

} else {

timeTemplate = timeTemplate.replace("%D%", Localization.impl.getString("am"));

}

if (h == 0) {

timeStampStr = timeTemplate.replace("%12%", "12");

} else {

timeStampStr = timeTemplate.replace("%12%", h);

}

} else {

timeStampStr = hourMinutes[0]":"hourMinutes[1];

}

timeStampStr = "<font color=\"#"parseInt(tStampColor).toString(16)"\">["timeStampStr"]</font> ";

}

var msg:String = p_msgDesc.msg;

msg = msg.replace(/</g, "&lt;");

msg = msg.replace(/>/g, "&gt;");

//TODO: make these colors come from a style!

var toAdd:String;

toAdd = "<font size=\""_historyFontSize"\">"

+timeStampStr

"<font color=\"#"parseInt(nameColor).toString(16)"\"><b>"p_msgDesc.displayNameprivateModifier"</b>: </font>"

"<font color=\"#"parseInt(msgColor).toString(16)"\">"msg+"</font>"

+"</font><br/>";

return toAdd;

}

The difference you will see in you need to do parseInt(color).toString(16) to have it converted to hex to get the right color value. This I have done for all the color types.

Last point, you should change the color values before starting and synchronizing the messages the chat, else it won't be applicable to history messages.

So, instead of changing colors in creationComplete of connectsessionContainer, you should do it in the initialize function i.e.

Something like

<rtc:SimpleChat width="300" height="400" id="chat" initialize="onInitialize()">

And

private function onInitialize ():void

{

chat.model.nameColor = 0xFF0000 ;

}

This will get you the required colors in all messages including the history ones.

Thanks for reporting this.

Regards

Hironmay Basu

View solution in original post

3 Replies

Avatar

Former Community Member

Okei, so the timeFormat suddenly worked for some nysterious reason, but I still can't figure out the colors. Bug?

Avatar

Correct answer by
Former Community Member

Hi,

Ok, I ran the timeformat thing for you and it should work be sent before a message is sent. If you have already sent a message with a particular timeformat, and then changed the timeformat, the new format won't be applicable to the history messages and would be only applicable to any new messages that you send. So, in case you want to particular timeformat for all messages, set it before sending any message and then it will be consistent throughout.

Now , coming to colors in chat, I digged deep and there was a bug in our code for hex to int conversion with colors and vice versa. Here is the fix for you as of now, we will include it in the next update

I am attaching you the formatMessageDescriptor method in SimpleChatModel.as class. Either you replace the existing model source's this method with the one I give or you can subclass that method and use my code.

Here is the method

public function formatMessageDescriptor(p_msgDesc:ChatMessageDescriptor):String

{

var timeStampStr:String = "";

var nameColor:String = getNameColor(p_msgDesc);

var msgColor:String = getMsgColor(p_msgDesc);

var tStampColor:String = getTimeStampColor(p_msgDesc);

var privateModifier:String = "";

if (p_msgDesc.publisherID == userManager.myUserID && pmsgDesc.recipient!=null) {

// it was a message I sent privately to another

privateModifier = " ("Localization.impl.getString("to")" "p_msgDesc.recipientDisplayName")";

} else if (p_msgDesc.role>UserRoles.VIEWER) {

// it was a message sent to a role group, and I can see it (either because I sent it or am in the group)

privateModifier = " ("Localization.impl.getString("to")" "((p_msgDesc.role == UserRoles.OWNER)? Localization.impl.getString("hosts") : Localization.impl.getString("participants"))")";

} else if (p_msgDesc.recipient!=null) {

// it was a message sent privately to me

privateModifier = " ("Localization.impl.getString("privately")")";

}

if (_useTimeStamps && !isNaN(p_msgDesc.timeStamp)) {

var d:Date = new Date(p_msgDesc.timeStamp);

//var hourMinutes:Array = d.toTimeString().split(":").slice(0,2);

var hourMinutes:Array = ;

if (hourMinutes[1] < 10) { //pad minutes if needed

hourMinutes[1] = "0"+hourMinutes[1];

}

if (_timeFormat == TIMEFORMAT_AM_PM) {

var timeTemplate:String = Localization.impl.getString("%12%:%M% %D%");

timeTemplate = timeTemplate.replace("%M%", hourMinutes[1]);

var h:uint = hourMinutes[0];

if (h >= 12) {

h -= 12;

timeTemplate = timeTemplate.replace("%D%", Localization.impl.getString("pm"));

} else {

timeTemplate = timeTemplate.replace("%D%", Localization.impl.getString("am"));

}

if (h == 0) {

timeStampStr = timeTemplate.replace("%12%", "12");

} else {

timeStampStr = timeTemplate.replace("%12%", h);

}

} else {

timeStampStr = hourMinutes[0]":"hourMinutes[1];

}

timeStampStr = "<font color=\"#"parseInt(tStampColor).toString(16)"\">["timeStampStr"]</font> ";

}

var msg:String = p_msgDesc.msg;

msg = msg.replace(/</g, "&lt;");

msg = msg.replace(/>/g, "&gt;");

//TODO: make these colors come from a style!

var toAdd:String;

toAdd = "<font size=\""_historyFontSize"\">"

+timeStampStr

"<font color=\"#"parseInt(nameColor).toString(16)"\"><b>"p_msgDesc.displayNameprivateModifier"</b>: </font>"

"<font color=\"#"parseInt(msgColor).toString(16)"\">"msg+"</font>"

+"</font><br/>";

return toAdd;

}

The difference you will see in you need to do parseInt(color).toString(16) to have it converted to hex to get the right color value. This I have done for all the color types.

Last point, you should change the color values before starting and synchronizing the messages the chat, else it won't be applicable to history messages.

So, instead of changing colors in creationComplete of connectsessionContainer, you should do it in the initialize function i.e.

Something like

<rtc:SimpleChat width="300" height="400" id="chat" initialize="onInitialize()">

And

private function onInitialize ():void

{

chat.model.nameColor = 0xFF0000 ;

}

This will get you the required colors in all messages including the history ones.

Thanks for reporting this.

Regards

Hironmay Basu

Avatar

Former Community Member

Thanks for looking into it!

parseInt(color).toString(16) worked for time and name color, but for the message I left it like it was. Either leave it or change msg.color = _colorPicker.selectedColor to msg.color = _colorPicker.value as uint in protected function sendNewMessage in the SimpleChat.

As for the timeFormat I actually set it right after initializing the ChatModel. I just stripped it down completely to ensure I wasn't doing something wierd in my modified code. But thanks for the hint, I'll keep that in mind!

Thanks again for solving my problem!

Edit: So I changed it for the message as well and changed COLOR_PRIVATE and COLOR_HOSTS to Number like the nameColor and timeStampColor because the same problem occured there.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----