diff options
| author | citrons <citrons@mondecitronne.com> | 2025-06-07 19:23:22 -0500 |
|---|---|---|
| committer | citrons <citrons@mondecitronne.com> | 2025-06-07 19:23:22 -0500 |
| commit | 1186ddcc211f33ea21d7679a3a4a80847434df94 (patch) | |
| tree | 33975a28994197eec40931c2d3973fc6f37b91f3 /client | |
| parent | 7d9933ccf0ac6fb9cafdd54a26a91bd9f1ed9a78 (diff) | |
user information command
Diffstat (limited to 'client')
| -rw-r--r-- | client/channel_window.go | 9 | ||||
| -rw-r--r-- | client/command.go | 8 | ||||
| -rw-r--r-- | client/user_messages.go | 69 |
3 files changed, 85 insertions, 1 deletions
diff --git a/client/channel_window.go b/client/channel_window.go index ff9484a..9a78b34 100644 --- a/client/channel_window.go +++ b/client/channel_window.go @@ -264,9 +264,16 @@ func (m channelMsg) showName(bg int32) { } else { nameStyle.Bold = true } - tui.Push(m.Id() + ".name", tui.Box { + mouse := tui.Push(m.Id() + ".name", tui.Box { Width: tui.TextSize, Height: 1, NoWrap: true, }) + switch { + case mouse.Button == 0 && mouse.Pressed: + fallthrough + case tui.MenuOption("who?"): + globalApp.cmdWindow.who(m.Fields["f"]) + globalApp.redraw = true + } tui.Text(m.window.username(m.Fields["f"]), &nameStyle) tui.Pop() } diff --git a/client/command.go b/client/command.go index 0db7f33..2bc7868 100644 --- a/client/command.go +++ b/client/command.go @@ -109,6 +109,14 @@ func (a *application) doCommand(command string, args []string, text string) { a.sendUpdate(proto.Object { "u", a.uid, map[string]string {"status": text}, }, cb) + case "who": + a.lookup(text, "u", func(u *proto.Object, fail *proto.Fail) { + if fail != nil { + a.cmdWindow.fail(proto.Object(*fail)) + } else { + a.cmdWindow.who(u.Id) + } + }) case "create": if a.authenticated { a.createChannel(text) 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}) + }) +} |
