summaryrefslogtreecommitdiff
path: root/client/user_messages.go
blob: 5fccf820ca059e9495f4b0bac7e19e8818946bca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main

import (
	"citrons.xyz/talk/tui"
	"citrons.xyz/talk/proto"
	"fmt"
)

type nameChangeMsg struct {
	index int
	uid string
	oldName string
	newName string
}

type userStatusMsg struct {
	index int
	uid string
	username string
	status string
}

type whoMsg struct {
	index int
	user proto.Object
}

func (m nameChangeMsg) Id() string {
	return fmt.Sprintf("name change.%d", m.index)
}

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 {
		Fg: tui.BrightBlack, Bg: colorDefault[odd],
	})
	tui.Text(m.oldName, &tui.Style {
		Fg: tui.White, Bg: colorDefault[odd], Italic: true,
	})
	tui.Text(" -> ", &tui.Style {
		Fg: tui.BrightBlack, Bg: colorDefault[odd],
	})
	tui.Text(m.newName, &tui.Style {
		Fg: tui.White, Bg: colorDefault[odd], Bold: true,
	})
	tui.Pop()
}

func (m userStatusMsg) Show(odd bool) {
	tui.Push("", tui.Box {Width: tui.Fill, Height: tui.TextSize})
	tui.Text("status: ", &tui.Style {
		Fg: tui.BrightBlack, Bg: colorDefault[odd],
	})
	tui.Text(m.username, &tui.Style {
		Fg: tui.White, Bg: colorDefault[odd], Bold: true,
	})
	tui.Text(" : ", &tui.Style {
		Fg: tui.BrightBlack, Bg: colorDefault[odd],
	})
	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})
	})
}