From 137d7cc9a77139fe7a267800419f0c85884f3e0f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 22 Jul 2021 15:56:13 +0300 Subject: Improved chats code structure and implemented going to chat via name --- go-src/windows.go | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/go-src/windows.go b/go-src/windows.go index 70da48c..20dedca 100644 --- a/go-src/windows.go +++ b/go-src/windows.go @@ -112,26 +112,24 @@ func chatsWindow(values ...string) { if handled == nil { // If user input is number, navigate to chat of given number, else show error - chatI, err := strconv.Atoi(input) - if chatI >= 0 && chatI <= len(allChats) && err == nil { + if chatI, err := strconv.Atoi(input); chatI >= 0 && chatI <= len(allChats) && err == nil { defer chatWindow(strings.Split(allChats[utils.MaxInt(len(allChats)-pageSize*len(values[0]), 0)+chatI-1], " : ")[0]) - } else { - switch input { - case ">": - // If possible, increment to the next page (adds a dot to the end of the string) - if len(values[0]) < totalPages(len(allChats)) { - values[0] += "." - } - case "<": - // If possible, decrement to the previous page (removes a dot from the string) - if len(values[0]) > 1 { - utils.StrShortenRight(&values[0], 1) - } - default: - defer showError(invalidCommand, chatsWindow) + } else if input == ">" { + // If possible, increment to the next page (adds a dot to the end of the string) + if len(values[0]) < totalPages(len(allChats)) { + values[0] += "." } - defer chatsWindow(values...) + } else if input == "<" { + // If possible, decrement to the previous page (removes a dot from the string) + if len(values[0]) > 1 { + utils.StrShortenRight(&values[0], 1) + } + defer chatsWindow(values...) + } else if chatNameExists(input) { + defer chatWindow(input) + } else { + defer showError(invalidCommand, chatsWindow) } } else { defer handled() -- cgit v1.2.3