zorchenhimer / MovieNight

Single instance video streaming server with integrated chat.
https://discord.gg/F2VSgjJ
MIT License
689 stars 87 forks source link

Change the chat data to having a standard location for the HTML() templates #32

Open joeyak opened 5 years ago

joeyak commented 5 years ago

It would be better to have a specific spot to store all the html message templates. Perhaps a slice or constants in another file.

zorchenhimer commented 5 years ago

I thought I had a TODO for this somewhere.

But yes, ideally that stuff should be a template somewhere that's loaded once at the server start. Maybe a global, read-only, map[string]html.Template? Where the string is the use of the template, eg "MsgAction" or "EvBan".

joeyak commented 5 years ago

I like the map[string]html.Template idea. The keys should be "enum" constants. Maybe with a Tmpl prefix.

zorchenhimer commented 5 years ago

This just occurred to me, but the templates cannot just be loaded into the server. They need to be sent to the wasm client, as that's what actually calls .HTML() on the data.

But now that we have some more robust communication between the client and server, this shouldn't pose much of a problem.

joeyak commented 5 years ago

Were you thinking of having the templates loaded on server start? I was thinking of making the templates "contasts", but I think I might like the load at runtime better.

zorchenhimer commented 5 years ago

Yea, on server start. I think I'd like to handle it similarly to how emotes are loaded. Once on server start, but they can be refreshed by an admin with a command.

Refreshing shouldn't update HTML that's already been displayed, only new HTML. Comparing it to emotes again, when emotes are refreshed and new ones are found, old messages are not re-parsed for the new emote.