dkforest

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

commit 9ec3f4d6ccc232be90c2523482080c2f6428046b
parent 8efccca3677eba3460290ea3ac46eb358473194b
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sat, 10 Jun 2023 23:54:16 -0700

improve locate cmd

Diffstat:
Mpkg/managers/managers.go | 2+-
Mpkg/web/handlers/interceptors/slashInterceptor.go | 20+++++++++++++++-----
2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/pkg/managers/managers.go b/pkg/managers/managers.go @@ -173,7 +173,7 @@ func (m *ActiveUsersManager) LocateUser(target database.Username) (out []databas m.RLock() for roomKey, usersMap := range m.activeUsers { for username := range usersMap { - if username == target { + if strings.ToLower(string(username)) == strings.ToLower(string(target)) { roomID := database.RoomID(utils.DoParseInt64(string(roomKey))) out = append(out, roomID) } diff --git a/pkg/web/handlers/interceptors/slashInterceptor.go b/pkg/web/handlers/interceptors/slashInterceptor.go @@ -1709,13 +1709,23 @@ func handleRefreshCmd(c *command.Command) (handled bool) { func handleLocateCmd(c *command.Command) (handled bool) { if m := locateRgx.FindStringSubmatch(c.Message); len(m) == 2 { username := database.Username(m[1]) - roomIDs := managers.ActiveUsers.LocateUser(username) + user, err := c.DB.GetUserByUsername(username) + if err != nil { + c.Err = errors.New("username does not exists") + return true + } + roomIDs := managers.ActiveUsers.LocateUser(user.Username) rooms, _ := c.DB.GetChatRoomsByID(roomIDs) - roomLinks := make([]string, len(rooms)) - for idx, room := range rooms { - roomLinks[idx] = "#" + room.Name + var msg string + if len(rooms) > 0 { + roomLinks := make([]string, len(rooms)) + for idx, room := range rooms { + roomLinks[idx] = "#" + room.Name + } + msg = username.AtStr() + " is in " + strings.Join(roomLinks, " ") + } else { + msg = username.AtStr() + " could not be located in a public room" } - msg := username.AtStr() + " is in " + strings.Join(roomLinks, " ") c.ZeroProcMsg(msg) c.Err = command.ErrRedirect return true