dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit bce30112cacf6679482dac0762bdaed4213f2955
parent 74bb2c2668e25b2af08e718bc39ed39734a231b6
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 23 Jan 2023 15:32:41 -0800

make username column "collate nocase"

Diffstat:
Acmd/dkf/migrations/120.sql | 268+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpkg/web/handlers/api/v1/topBarHandler.go | 6+++---
2 files changed, 271 insertions(+), 3 deletions(-)

diff --git a/cmd/dkf/migrations/120.sql b/cmd/dkf/migrations/120.sql @@ -0,0 +1,268 @@ +-- +migrate Up + +create table users_tmp ( + id INTEGER not null primary key, + username VARCHAR(50) not null COLLATE NOCASE unique, + password VARCHAR(255) not null, + two_factor_secret BLOB, + two_factor_recovery BLOB, + gpg_public_key TEXT, + token VARCHAR(255) unique, + role VARCHAR(30) default 'member' not null, + lang VARCHAR(10) default '' not null, + chat_color VARCHAR(20) default '#000000' not null, + api_key VARCHAR(50) default '' not null, + created_at DATETIME default CURRENT_TIMESTAMP not null, + deleted_at DATETIME, + updated_at DATETIME default CURRENT_TIMESTAMP, + is_admin TINYINT(1) default 0 not null, + is_hellbanned TINYINT(1) default 0 not null, + verified TINYINT(1) default 0 not null, + chat_font INTEGER default 1 not null, + chat_bold TINYINT default 0 not null, + chat_italic TINYINT default 0 not null, + refresh_rate INTEGER default 5 not null, + login_attempts INTEGER default 0 not null, + temp TINYINT(1) default 0 not null, + notify_new_message TINYINT(1) default 1 not null, + notify_tagged TINYINT(1) default 1 not null, + notify_pmmed TINYINT(1) default 1 not null, + notify_new_message_sound INTEGER default 1 not null, + notify_tagged_sound INTEGER default 1 not null, + notify_pmmed_sound INTEGER default 1 not null, + avatar BLOB, + email VARCHAR(255), + website VARCHAR(255), + is_club_member TINYINT(1) default 0 not null, + last_seen_at DATETIME default 0 not null, + display_hellbanned TINYINT(1) default 0 not null, + chat_tutorial INTEGER default 0 not null, + chat_tutorial_time DATETIME, + chat_read_marker_enabled TINYINT(1) default 1 not null, + chat_read_marker_color VARCHAR(50) default '#4e7597' not null, + chat_read_marker_size INTEGER default 1 not null, + can_upload_file TINYINT(1) default 1, + display_pms INTEGER default 0 not null, + display_ignored TINYINT(1) default 0 not null, + can_use_forum TINYINT(1) default 1, + gpg_two_factor_enabled TINYINT(1) default 0, + display_kick_button TINYINT(1) default 0 not null, + display_moderators TINYINT(1) default 1 not null, + hide_ignored_users_from_list TINYINT(1) default 0 not null, + registration_duration INTEGER default 0, + last_seen_public TINYINT(1) default 1 not null, + vetted TINYINT(1) default 0 not null, + terminate_all_sessions_on_logout TINYINT(1) default 1 not null, + age_public_key VARCHAR(255) default '' not null, + can_change_username TINYINT(1) default 1 not null, + pm_mode INTEGER default 0 not null, + hide_right_column TINYINT(1) default 0 not null, + date_format INTEGER default 0 not null, + can_use_multiline TINYINT(1) default 0 not null, + signup_metadata TEXT default '' not null, + karma INTEGER default 0 not null, + duress_password VARCHAR(255) default '' not null, + is_under_duress TINYINT(1) default 0 not null, + secret_phrase BLOB, + display_hellban_button TINYINT(1) default 1 not null, + display_delete_button TINYINT(1) default 1 not null, + can_change_color TINYINT(1) default 1 not null, + is_incognito TINYINT(1) default 0 not null, + block_new_users_pm TINYINT(1) default 0 not null, + collect_metadata TINYINT(1) default 0 not null, + captcha_required TINYINT(1) default 0 not null, + can_see_hellbanned TINYINT(1) default 0 not null, + theme INTEGER default 0 not null, + afk TINYINT(1) default 0 not null, + notify_chess_move TINYINT(1) default 0 not null, + chat_bar_at_bottom TINYINT(1) default 0 not null, + notify_chess_games TINYINT(1) default 0 not null, + autocomplete_commands_enabled TINYINT(1) default 1 not null, + general_messages_count INTEGER default 0 not null, + afk_indicator_enabled TINYINT(1) default 0 not null, + gpg_two_factor_mode TINYINT(1) default 0, + spellcheck_enabled TINYINT(1) default 0 not null, + can_use_uppercase TINYINT(1) default 1 not null +); + +INSERT INTO users_tmp ( +id, +username, +password, +two_factor_secret, +two_factor_recovery, +gpg_public_key, +token, +role, +lang, +chat_color, +api_key, +created_at, +deleted_at, +updated_at, +is_admin, +is_hellbanned, +verified, +chat_font, +chat_bold, +chat_italic, +refresh_rate, +login_attempts, +temp, +notify_new_message, +notify_tagged, +notify_pmmed, +notify_new_message_sound, +notify_tagged_sound, +notify_pmmed_sound, +avatar, +email, +website, +is_club_member, +last_seen_at, +display_hellbanned, +chat_tutorial, +chat_tutorial_time, +chat_read_marker_enabled, +chat_read_marker_color, +chat_read_marker_size, +can_upload_file, +display_pms, +display_ignored, +can_use_forum, +gpg_two_factor_enabled, +display_kick_button, +display_moderators, +hide_ignored_users_from_list, +registration_duration, +last_seen_public, +vetted, +terminate_all_sessions_on_logout, +age_public_key, +can_change_username, +pm_mode, +hide_right_column, +date_format, +can_use_multiline, +signup_metadata, +karma, +duress_password, +is_under_duress, +secret_phrase, +display_hellban_button, +display_delete_button, +can_change_color, +is_incognito, +block_new_users_pm, +collect_metadata, +captcha_required, +can_see_hellbanned, +theme, +afk, +notify_chess_move, +chat_bar_at_bottom, +notify_chess_games, +autocomplete_commands_enabled, +general_messages_count, +afk_indicator_enabled, +gpg_two_factor_mode, +spellcheck_enabled, +can_use_uppercase) +SELECT +id, +username, +password, +two_factor_secret, +two_factor_recovery, +gpg_public_key, +token, +role, +lang, +chat_color, +api_key, +created_at, +deleted_at, +updated_at, +is_admin, +is_hellbanned, +verified, +chat_font, +chat_bold, +chat_italic, +refresh_rate, +login_attempts, +temp, +notify_new_message, +notify_tagged, +notify_pmmed, +notify_new_message_sound, +notify_tagged_sound, +notify_pmmed_sound, +avatar, +email, +website, +is_club_member, +last_seen_at, +display_hellbanned, +chat_tutorial, +chat_tutorial_time, +chat_read_marker_enabled, +chat_read_marker_color, +chat_read_marker_size, +can_upload_file, +display_pms, +display_ignored, +can_use_forum, +gpg_two_factor_enabled, +display_kick_button, +display_moderators, +hide_ignored_users_from_list, +registration_duration, +last_seen_public, +vetted, +terminate_all_sessions_on_logout, +age_public_key, +can_change_username, +pm_mode, +hide_right_column, +date_format, +can_use_multiline, +signup_metadata, +karma, +duress_password, +is_under_duress, +secret_phrase, +display_hellban_button, +display_delete_button, +can_change_color, +is_incognito, +block_new_users_pm, +collect_metadata, +captcha_required, +can_see_hellbanned, +theme, +afk, +notify_chess_move, +chat_bar_at_bottom, +notify_chess_games, +autocomplete_commands_enabled, +general_messages_count, +afk_indicator_enabled, +gpg_two_factor_mode, +spellcheck_enabled, +can_use_uppercase FROM users; + +DROP TABLE users; + +ALTER TABLE users_tmp RENAME TO users; + +create index users_api_key_idx on users (api_key); +create index users_is_admin_idx on users (is_admin); +create index users_is_club_idx on users (is_club_member); +create index users_is_hellbanned_idx on users (is_hellbanned); +create index users_notify_chess_games_idx on users (notify_chess_games); +create index users_verified_idx on users (verified); +create index users_vetted_idx on users (vetted); + + +-- +migrate Down diff --git a/pkg/web/handlers/api/v1/topBarHandler.go b/pkg/web/handlers/api/v1/topBarHandler.go @@ -591,7 +591,7 @@ func colorifyTaggedUsers(html string, getUsersByUsername getUsersByUsernameFn) ( taggedUsersMap := make(map[string]database.User) taggedUsersIDsMap := make(map[database.UserID]database.User) for _, taggedUser := range taggedUsers { - taggedUsersMap["@"+taggedUser.Username] = taggedUser + taggedUsersMap["@"+strings.ToLower(taggedUser.Username)] = taggedUser if taggedUser.Username != config.NullUsername { taggedUsersIDsMap[taggedUser.ID] = taggedUser } @@ -599,8 +599,8 @@ func colorifyTaggedUsers(html string, getUsersByUsername getUsersByUsernameFn) ( if tagRgx.MatchString(html) { html = tagRgx.ReplaceAllStringFunc(html, func(s string) string { - if user, ok := taggedUsersMap[s]; ok { - return fmt.Sprintf("<span %s>%s</span>", user.GenerateChatStyle1(), s) + if user, ok := taggedUsersMap[strings.ToLower(s)]; ok { + return fmt.Sprintf("<span %s>@%s</span>", user.GenerateChatStyle1(), user.Username) } return s })