group-income icon indicating copy to clipboard operation
group-income copied to clipboard

SPIKE: Improve the text format in MESSAGE_TYPES.TEXT

Open Silver-IT opened this issue 2 years ago • 1 comments

Problem

The text messages in our chat system could have different types of content inside.

Simple text: 'Hello!!!'
Mention: '@alexjin'
Channel: '#general'

... (Possibly URL, email, and more which we should handle in different way than the simple text)

And we should handle each one in different ways. e.g., Mention with different style, URL which should copy it to clipboard when click it, email with href of mailto, ... I don't think it's good way to figure out all of them in the text of current format, which is simple text.

Solution

Convert the simple text to the stringified JSON for the messages with MESSAGE_TYPES.TEXT of it's type.

{
  type: MESSAGE_TYPES.TEXT,
  text: '[{"type":"user","user_id":"z9brRu3VHLEtDhcpFpcAB6e1LC6DKZPq4B5iaKBeP2PEf7d87pV2"},{"type":"text","text":", how are you? Can you join this channel? "}, {"type":"channel","channel_id":"z9brRu3VSfDZF3KiJzqhSWAzZGPE26ruQkrzDQLQjDSKFMkz4L2e"}]'
}

Thanks to @corrideat who gave me a Aha moment with the message below. https://okturtles.slack.com/archives/C02QF71TK1Q/p1708946968977639?thread_ts=1708930845.615099&cid=C02QF71TK1Q

Silver-IT avatar Mar 01 '24 01:03 Silver-IT

@Silver-IT Yes, I think that this is the proper way to do this, and it also allows for extensibility in the future.

corrideat avatar Mar 01 '24 18:03 corrideat