How to NOT store plain text messages in the database?

There is a web app.

It has chat, in which you can write only text. Messages are stored in a field of type `text`.

How to be able to specify users in the message, so they know about it?

For example, one user writes in the General chat

@Vasily Pupkin, see here.

Text "@Vasily Pupkin" it needs to stand out somehow, so you can click on it to go to the user profile.

A variant of this: in the database will be saved "[user=48754], look at this." The backend before sending to the browser esparcet the message and show it beautifully. Obviously not the best option.

As this task is (at least approximately) implemented at large sites (social. networking, for example)? And how to implement it on the frontend? To display text, and to the server to send a specially formed message "[user=48754], look at this."?
August 23rd 19 at 11:01
1 answer
August 23rd 19 at 11:03
Why not do it through JavaScript? Looking for the message template of the form "@letter", if what is after "@" in the user list, which can, for example, to cache in the browser or via AJAX request - change "it" to the ACC. link or what you need.

Option 2: Parsim the message on the server, looking for the pattern "@letters" (through regular season), if the user is in the database - replace ACC. code (reference, selection, etc.).

So vskidku, the first option is suitable for selection of personal messages, the second for what would be the names stood out at all as such (as e.g. here on the Toaster).
The fact that are not usernames (they are unique) and names (they are not unique). Maybe ten Vasile Pupkin and then it is not clear to which of them this applies. This is the first. Second, the user can change the name in the profile and all the old links to it will become thus invalid. - Markus_Cummerata commented on August 23rd 19 at 11:06
: how it would work then, if sitting there for 10 Bob online?
What is the meaning of treatment is not a unique identifier? - Eldora commented on August 23rd 19 at 11:09
: I think:
- If names are not unique, it is possible to tie a specific username with a non-unique name/name - does not
- Here (on the Toaster) as You can see, for personal reference, indicates just the username and not name
- In the social. networks, surely there are links to some attribute pointing to the ID of the user, for example:
- Jocelyn.Jakubowski43 commented on August 23rd 19 at 11:12
: OK, but in database how to save? with html? - Markus_Cummerata commented on August 23rd 19 at 11:15
in the database can store several methods or their combinations (combinations), for example:
a) Store in a clean HTML
b) Create additional field where it will be stored separately code (raw), processed separately code HTML
V) to Store through special. markup, Ala [user=101]NAME[/user] (where NAME is automatically replaced with the current user name, when you conclusion), including in a separate field but in another field - ready HTML
g) Create a field of type JSON/XML where the order will be stored user IDs for each @'key in the text
d), etc., the mass of options, their choice depends on how you designed the rest of the application, from the database, and so on. - Jocelyn.Jakubowski43 commented on August 23rd 19 at 11:18

Find more questions by tags MySQL