okTurtles / group-income

Voluntary Basic Income system that's decentralized and end-to-end encrypted.
https://groupincome.org
GNU Affero General Public License v3.0
328 stars 43 forks source link

SPIKE: Improve the text format in MESSAGE_TYPES.TEXT #1874

Open Silver-IT opened 4 months ago

Silver-IT commented 4 months ago

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

corrideat commented 4 months ago

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