-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodel.go
101 lines (83 loc) · 1.72 KB
/
model.go
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
package main
import (
"time"
"github.com/charmbracelet/bubbles/filepicker"
"github.com/charmbracelet/bubbles/list"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
)
type Message struct {
Type string `json:"type"`
IsGroupMsg bool `json:"isGroupMsg"`
Group string `json:"group,omitempty"`
To string `json:"to"`
Content string `json:"content"`
FileData []byte `json:"fileData,omitempty"`
From string `json:"From"`
}
func (item Message) Title() string {
return item.From
}
func (item Message) Description() string {
return item.Content
}
func (item Message) FilterValue() string {
return item.Content
}
type Chat struct {
name, desc string
isGroupChat bool
}
func (item Chat) Title() string {
return item.name
}
func (item Chat) Description() string {
return item.desc
}
func (item Chat) FilterValue() string {
return item.name
}
type component int
const (
none component = iota
input
chat
message
)
type view int
const (
login view = iota
newDM
newGC
joinGC
sendFile
home
help
)
type model struct {
height int
width int
chats list.Model
messages list.Model
filepicker filepicker.Model
selectedFile string
quitting bool
err error
input textinput.Model
usernameInput textinput.Model
filenameInput textinput.Model
groupnameInput textinput.Model
passwordInput textinput.Model
currentChat string
focus component
currentView view
}
type clearErrorMsg struct{}
func clearErrorAfter(t time.Duration) tea.Cmd {
return tea.Tick(t, func(_ time.Time) tea.Msg {
return clearErrorMsg{}
})
}
func (m model) Init() tea.Cmd {
return m.filepicker.Init()
}