maptool icon indicating copy to clipboard operation
maptool copied to clipboard

[Refactoring]: Move formatting of chat messages to the side of the receiving client

Open Irarara opened this issue 2 years ago • 6 comments

Describe the problem

Presently, the formatting of chat messages is done by the sending client, this makes it impossible (or at least, impractical) to implement some settings or features that would affect how the output looks on individual receiving clients.

The improvement you'd like to see

Formatting of messages should be moved to the side of the receiving clients. Currently when sending a message to the chat a TextMessage is created with the already formatted message bundled in it and that message is just inserted into the chat of the receiving client as-is, with the exception of a little post-processing done in MessagePanel.addMessage() (formatting inline rolls and the like). Instead, what could be done is to send the extra data needed for formatting the message along with the TextMessage and the final formatting can then be handled in MessagePanel before it's inserted into the chat.

Expected Benefits

The change would give the receiving client more control over chat output which would allow for the implementation of more customization or accessibility options for the chat. This would also make more advanced functionality like user defined formatting via templates or the like a possibility.

Additional Context

I've had this on my mind for ages, but it never seemed that pressing. But, with recent discussion around themes and what not, giving clients more control over chat output is something that has become more of a relevant.

Also to clarify, when I say "some settings or features", I mean anything that can't be achieved by changing the chat's CSS. Some examples being whether token images are displayed (since the CSS doesn't support display: none 😔), whether user chat color is used, anything to do with overall layout, etc..

Irarara avatar Sep 09 '22 19:09 Irarara

I would be happy to take a stab at this.

Irarara avatar Sep 09 '22 19:09 Irarara

I like the idea. I'm interested in how you plan to accomplish this? Suppose I want the string "Error" to appear in red with a black background. The sending client cannot use "red" or "black" because the receiving client can't change them programmatically to a local preferred palette.

Instead, the sending client would need to transmit something like:

{ "text": "Error", "cssClass": ".error" }

where the definition of the class was (probably) sent when the client connected to the campaign, and the receiving client has the CSS class in their theme configuration such that the text is red and the background is black.

Or am I missing something?

Azhrei avatar Sep 09 '22 19:09 Azhrei

I like the idea. I'm interested in how you plan to accomplish this? Suppose I want the string "Error" to appear in red with a black background. The sending client cannot use "red" or "black" because the receiving client can't change them programmatically to a local preferred palette.

Instead, the sending client would need to transmit something like:

{ "text": "Error", "cssClass": ".error" }

where the definition of the class was (probably) sent when the client connected to the campaign, and the receiving client has the CSS class in their theme configuration such that the text is red and the background is black.

Or am I missing something?

The transmitting client should just send a message type as well as message parameters, and its up to the client to build what ever value is inserted into the chat frame, attaching CSS classes etc.

Changing it to just send the text and a CSS class to be applied to it is less flexible and as pointed out in the issue CSS by itself can't be used to solve all the problems this is intended to address.

cwisniew avatar Sep 09 '22 19:09 cwisniew

Basically what @cwisniew said. The type of message would be sent and used to determine how it should be formatted, and otherwise the formatting would function more or less the same, just on the side of the receiving client.

And just to be clear, this is not intended to address arbitrary formatting done by the user.

Irarara avatar Sep 09 '22 19:09 Irarara

And just to be clear, this is not intended to address arbitrary formatting done by the user.

It is a prerequisite for adding this properly at a later date and doing things like filtering output/having a chat window with multiple channels (e.g. a tab for just whispers etc.).

cwisniew avatar Sep 09 '22 19:09 cwisniew

And just to be clear, this is not intended to address arbitrary formatting done by the user.

Ah, that makes more sense. Thanks. 👍

Azhrei avatar Sep 09 '22 20:09 Azhrei