From 0aa796bb27cec3ff63621829e06546a133930bb1 Mon Sep 17 00:00:00 2001 From: qowevisa Date: Sat, 25 May 2024 09:19:41 +0300 Subject: [PATCH] Some changes in tui --- tui/channel_message.go | 17 ++++++++--------- tui/util.go | 1 + 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tui/channel_message.go b/tui/channel_message.go index c91d7e9..1aaf791 100644 --- a/tui/channel_message.go +++ b/tui/channel_message.go @@ -13,25 +13,24 @@ func (t *TUI) launchMessageChannel() error { } go func() { for message := range t.messageChannel { - t.createNotification(string(message), "Message!") msg, err := communication.Decode(message) t.errorsChannel <- err if err != nil { continue } - switch msg.Type { - case communication.SERVER_COMMAND: - t.handleServerCommands(msg.Data) + switch msg.From { + case communication.FROM_SERVER: + t.handleServerCommands(*msg) + case communication.FROM_CLIENT: + t.createNotification(string(msg.Data), "Server Message!") } } }() return nil } -func (t *TUI) handleServerCommands(data []byte) { - if len(data) == 1 { - if data[0] == communication.NICKNAME { - t.SendMessageToServer("Nickname", 16) - } +func (t *TUI) handleServerCommands(data communication.Message) { + if data.About == communication.ABOUT_NICKNAME { + t.SendMessageToServer("Nickname", 16) } } diff --git a/tui/util.go b/tui/util.go index 5653e36..bc6f6e3 100644 --- a/tui/util.go +++ b/tui/util.go @@ -24,4 +24,5 @@ func (t *TUI) SendMessageToServer(title string, minW int) { if err != nil { t.errorsChannel <- errors.WrapErr("t.drawSelectedWidget", err) } + t.readInputState <- true }