commit 2f3bc47d3b6d0f0e52f9bb5bba4f53ec3454e325
parent 700f51d73543afad1bb1e916d18358fd8498267f
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 8 Jun 2023 21:27:35 -0700
dedup logic
Diffstat:
1 file changed, 25 insertions(+), 17 deletions(-)
diff --git a/pkg/web/handlers/streamModals/codeModal.go b/pkg/web/handlers/streamModals/codeModal.go
@@ -13,6 +13,23 @@ import (
const name = "code"
+var langs = [][]string{
+ {"", "Raw text"},
+ {"go", "Golang"},
+ {"rs", "Rust"},
+ {"cpp", "C++"},
+ {"c", "C"},
+ {"py", "Python"},
+ {"js", "Javascript"},
+ {"php", "PHP"},
+ {"css", "CSS"},
+ {"sql", "SQL"},
+ {"c#", "C#"},
+ {"rb", "Ruby"},
+ {"html", "HTML"},
+ {"bash", "Bash"},
+}
+
type CodeModal struct {
StreamModal
}
@@ -85,22 +102,6 @@ func getCodeModalHTML(codeModalIdx int, roomName, csrf string, msgTyp database.C
</div>
</form>
</div>`
- langs := [][]string{
- {"", "Raw text"},
- {"go", "Golang"},
- {"rs", "Rust"},
- {"cpp", "C++"},
- {"c", "C"},
- {"py", "Python"},
- {"js", "Javascript"},
- {"php", "PHP"},
- {"css", "CSS"},
- {"sql", "SQL"},
- {"c#", "C#"},
- {"rb", "Ruby"},
- {"html", "HTML"},
- {"bash", "Bash"},
- }
data := map[string]any{
"CSRF": csrf,
"RoomName": roomName,
@@ -127,7 +128,14 @@ func (_ CodeModal) InterceptMsg(cmd *command.Command) {
CodeModal{}.Hide(cmd.AuthUser.ID, cmd.Room.ID)
- if !utils.InArr(lang, []string{"go", "c", "cpp", "py", "js", "php", "css", "sql", "rs", "c#", "rb", "html", "bash"}) {
+ found := false
+ for _, l := range langs {
+ if lang == l[0] {
+ found = true
+ break
+ }
+ }
+ if !found {
lang = ""
}
cmd.DB.DB().Model(&database.User{}).Where("id = ?", cmd.AuthUser.ID).Update("syntax_highlight_code", lang)