diff options
Diffstat (limited to 'client/user_messages.go')
| -rw-r--r-- | client/user_messages.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/client/user_messages.go b/client/user_messages.go index 80b8fcc..5fccf82 100644 --- a/client/user_messages.go +++ b/client/user_messages.go @@ -2,6 +2,7 @@ package main import ( "citrons.xyz/talk/tui" + "citrons.xyz/talk/proto" "fmt" ) @@ -19,6 +20,11 @@ type userStatusMsg struct { status string } +type whoMsg struct { + index int + user proto.Object +} + func (m nameChangeMsg) Id() string { return fmt.Sprintf("name change.%d", m.index) } @@ -27,6 +33,10 @@ func (m userStatusMsg) Id() string { return fmt.Sprintf("user status.%d", m.index) } +func (m whoMsg) Id() string { + return fmt.Sprintf("who.%d", m.index) +} + func (m nameChangeMsg) Show(odd bool) { tui.Push("", tui.Box {Width: tui.Fill, Height: tui.TextSize}) tui.Text("nick: ", &tui.Style { @@ -58,3 +68,62 @@ func (m userStatusMsg) Show(odd bool) { tui.Text(m.status, nil) tui.Pop() } + +func (m whoMsg) Show(odd bool) { + tui.Push("", tui.Box { + Width: tui.Fill, Height: tui.Children, Dir: tui.Right, + Style: &tui.Style {Bg: colorCmd[odd], Fg: tui.White}, + }) + tui.Push("", tui.Box {Width: tui.TextSize, Height: tui.TextSize}) + tui.Text("* ", nil) + tui.Pop() + + tui.Push("", tui.Box {Width: tui.Fill, Height: tui.TextSize}) + tui.Text(m.user.Fields[""], &tui.Style { + Fg: tui.White, Bg: colorCmd[odd], Bold: true, + }) + tui.Text(" : ", nil) + if m.user.Fields["status"] != "" { + tui.Text(m.user.Fields["status"], nil) + } else { + var text string + if m.user.Kind == "gone" { + text = "gone" + } else { + text = "no status" + } + tui.Text(text, &tui.Style { + Fg: tui.White, Bg: colorCmd[odd], Italic: true, + }) + } + tui.Pop() + + tui.Pop() +} + +func (w *cmdWindow) nameChange(uid, oldName, newName string) { + lastIndex++ + w.Buf.Add(nameChangeMsg {lastIndex, uid, oldName, newName}) +} + +func (w *cmdWindow) userStatus(uid, status string) { + globalApp.cache.Fetch(uid, func(u *proto.Object) { + var name string + if u != nil { + name = u.Fields[""] + } + lastIndex++ + w.Buf.Add(userStatusMsg {lastIndex, uid, name, status}) + }) +} + +func (w *cmdWindow) who(uid string) { + globalApp.cache.Fetch(uid, func(u *proto.Object) { + if u == nil { + w.err("error fetching user information") + return + } + lastIndex++ + w.Buf.Add(whoMsg {lastIndex, *u}) + }) +} |
