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 }