Some changes in tui

This commit is contained in:
qowevisa 2024-05-25 09:19:41 +03:00
parent 00781f23d2
commit 0aa796bb27
2 changed files with 9 additions and 9 deletions

View File

@ -13,25 +13,24 @@ func (t *TUI) launchMessageChannel() error {
} }
go func() { go func() {
for message := range t.messageChannel { for message := range t.messageChannel {
t.createNotification(string(message), "Message!")
msg, err := communication.Decode(message) msg, err := communication.Decode(message)
t.errorsChannel <- err t.errorsChannel <- err
if err != nil { if err != nil {
continue continue
} }
switch msg.Type { switch msg.From {
case communication.SERVER_COMMAND: case communication.FROM_SERVER:
t.handleServerCommands(msg.Data) t.handleServerCommands(*msg)
case communication.FROM_CLIENT:
t.createNotification(string(msg.Data), "Server Message!")
} }
} }
}() }()
return nil return nil
} }
func (t *TUI) handleServerCommands(data []byte) { func (t *TUI) handleServerCommands(data communication.Message) {
if len(data) == 1 { if data.About == communication.ABOUT_NICKNAME {
if data[0] == communication.NICKNAME {
t.SendMessageToServer("Nickname", 16) t.SendMessageToServer("Nickname", 16)
} }
}
} }

View File

@ -24,4 +24,5 @@ func (t *TUI) SendMessageToServer(title string, minW int) {
if err != nil { if err != nil {
t.errorsChannel <- errors.WrapErr("t.drawSelectedWidget", err) t.errorsChannel <- errors.WrapErr("t.drawSelectedWidget", err)
} }
t.readInputState <- true
} }