diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-09-10 12:31:36 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-09-10 12:31:36 +0300 |
| commit | 695dc46d540befe8486eb647c60d08ab0236fa60 (patch) | |
| tree | 3f7d2f6c1bcff02a3fe13c6b7052de50b05fde1e /go-src/windows.go | |
| parent | e970dc54d59da50d818c013eecfac1c561f5e535 (diff) | |
| download | ctfc-695dc46d540befe8486eb647c60d08ab0236fa60.tar ctfc-695dc46d540befe8486eb647c60d08ab0236fa60.tar.gz ctfc-695dc46d540befe8486eb647c60d08ab0236fa60.zip | |
Implemented direct messages
Diffstat (limited to 'go-src/windows.go')
| -rw-r--r-- | go-src/windows.go | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/go-src/windows.go b/go-src/windows.go index 50bc5d5..c8e7234 100644 --- a/go-src/windows.go +++ b/go-src/windows.go @@ -221,6 +221,126 @@ func chatWindow(values ...string) { lastLine = -2 // Practically stops execution of the paginated subwindow routine } +func directMessagesWindow(values ...string) { + csi.ClearScreen() + + initPaginatedValues(0, &values) + + ui.NormalBox(true, chatNavTitle, accountNavTitle, logoutNavTitle) + + allDirectMessageChats := getAllDirectMessageChats() + ui.EmptyLines(pageSize + 3) // empty line + message lines + page number line + empty line + + customLinesBelow := utils.If(values[1] == showHelp).Int(3, 2) + + lastLine := -1 + go routinePaginatedSubwindow(&allDirectMessageChats, + func(s *[]string) { *s = (getAllDirectMessageChats()) }, + &lastLine, + len(values[0]), + customLinesBelow, + true, + ) + + if values[1] == showHelp { + ui.TextField(directMessagesWindowHelpMsg) + } + + input := ui.InputField(chatsSpec) + + nextWindow := handleInputActions(input, true, + inputAction{"H", directMessagesWindow, []string{values[0], showHelp}}, + ) + + if nextWindow == nil { + // If user input is number, navigate to chat of given number, else show error + if chatI, err := strconv.Atoi(input); chatI >= 0 && chatI <= len(allDirectMessageChats) && err == nil { + defer directMessageWindow(strings.Trim(strings.Split(allDirectMessageChats[utils.MaxInt(len(allDirectMessageChats)-pageSize*len(values[0]), 0)+chatI-1], " (")[1], ")")) + } 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(allDirectMessageChats)) { + values[0] += "." + } + defer directMessagesWindow(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 directMessagesWindow(values...) + } else if usernameExists(input) { + defer directMessageWindow(input) + } else { + defer showError(invalidCommand, chatsWindow) + } + } else { + defer nextWindow() + } + lastLine = -2 + +} + +func directMessageWindow(values ...string) { + csi.ClearScreen() + + // We determine page number by length of a string + // This method should be faster than having to cast to int all the time + initPaginatedValues(1, &values) + + currDirectMessagesChat := getDirectMessageChat(values[0]) + + ui.NormalBox(true, chatNavTitle, directMessagesNavTitle, accountNavTitle, logoutNavTitle) + ui.TextField(currDirectMessagesChat.Author2.Name + " (" + currDirectMessagesChat.Author2.Username + ")") + + ui.EmptyLines(pageSize + 3) // empty line + messages lines + page number line + empty line + + customLinesBelow := utils.If(values[2] == showHelp).Int(3, 2) + + lastLine := -1 + go routinePaginatedSubwindow(&currDirectMessagesChat.Messages, + func(s *[]string) { *s = getDirectMessageChat(values[0]).Messages }, + &lastLine, + len(values[1]), + customLinesBelow, + false, + ) + + if values[2] == showHelp { + ui.TextField(directMessageWindowHelpMsg) + values[2] = "" + } + + input := ui.InputField(chatWindowSpec) + + nextWindow := handleInputActions(input, true, + inputAction{"H", directMessageWindow, []string{values[0], values[1], showHelp}}, + ) + + if nextWindow == nil { + switch input { + case ">": + // If possible, increment to the next page (adds a dot to the end of the string) + if len(values[1]) < totalPages(len(currDirectMessagesChat.Messages)) { + values[1] += "." + } + case "<": + // If possible, decrement to the previous page (removes a dot from the string) + if len(values[1]) > 1 { + utils.StrShortenRight(&values[1], 1) + } + default: // Send a message + values[1] = "." // Make sure to be at the first page, when sending a message + // Since "C" is a command, to just enter the letter C you'll need to input "\C" + currDirectMessagesChat.addMessage(strings.TrimPrefix(input, "\\"), loggedInUser.Username) + } + + defer directMessageWindow(values...) + } else { + defer nextWindow() + } + lastLine = -2 // Practically stops execution of the paginated subwindow routine +} + func accountWindow(values ...string) { csi.ClearScreen() |
