feat: search sessions, attach files, read aloud, jump to latest
Reach the first-party mobile client's everyday features: - sessions: a search button opens a field; typing asks the server with its search parameter (350 ms settle) and clearing restores the list - composer: attach photos or files (up to five, 10 MB each) as data URLs with the prompt; attachments show as removable chips and are named under the sent message - turn menu: read the answer aloud with the system voice, or stop it - chat: a "latest" button appears after scrolling up and returns to the end of the conversation - reset a live search when a connection ends Bump version to 0.2.0 (build 14).
This commit is contained in:
1 parent
4c6fcf4cbe
commit
72119b73e8
11 files changed
+445
-56
No files matched your search
+39
-4
@@ -36,9 +36,11 @@ type controller struct {
|
||||
|
||||
connections *signal.Signal[[]storage.Connection]
|
||||
|
||||
url *signal.Signal[string]
|
||||
status *signal.Signal[string]
|
||||
errorMsg *signal.Signal[string]
|
||||
url *signal.Signal[string]
|
||||
sessionQuery *signal.Signal[string]
|
||||
searchOpen *signal.Signal[bool]
|
||||
status *signal.Signal[string]
|
||||
errorMsg *signal.Signal[string]
|
||||
|
||||
formOpen *signal.Signal[bool]
|
||||
formConnecting bool
|
||||
@@ -83,6 +85,8 @@ func newController(st storage.Store) *controller {
|
||||
st: st,
|
||||
connections: signal.NewFunc(conns, nil),
|
||||
url: signal.New(""),
|
||||
sessionQuery: signal.New(""),
|
||||
searchOpen: signal.New(false),
|
||||
status: signal.New(""),
|
||||
errorMsg: signal.New(""),
|
||||
formOpen: signal.New(false),
|
||||
@@ -360,6 +364,33 @@ func (c *controller) labelOf(conn storage.Connection) string {
|
||||
return label
|
||||
}
|
||||
|
||||
// searchSessions runs the query the search field holds.
|
||||
func (c *controller) searchSessions(q string) {
|
||||
if c.client == nil || c.busy.Peek() {
|
||||
return
|
||||
}
|
||||
c.busy.Set(true)
|
||||
client := c.client
|
||||
go func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
page, err := client.ListSessions(ctx, ocapi.ListSessionsOptions{Limit: 50, Order: "desc", Search: q})
|
||||
ui.Post(func() {
|
||||
c.busy.Set(false)
|
||||
if err != nil {
|
||||
c.errorMsg.Set(friendlyError(err))
|
||||
return
|
||||
}
|
||||
c.sessions.Set(page.Data)
|
||||
if q == "" {
|
||||
c.status.Set(fmt.Sprintf("已更新,%d 个会话", len(page.Data)))
|
||||
} else {
|
||||
c.status.Set(fmt.Sprintf("找到 %d 个会话", len(page.Data)))
|
||||
}
|
||||
})
|
||||
}()
|
||||
}
|
||||
|
||||
func (c *controller) refresh() {
|
||||
if c.client == nil || c.busy.Peek() {
|
||||
return
|
||||
@@ -369,7 +400,9 @@ func (c *controller) refresh() {
|
||||
go func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
page, err := client.ListSessions(ctx, ocapi.ListSessionsOptions{Limit: 50, Order: "desc"})
|
||||
page, err := client.ListSessions(ctx, ocapi.ListSessionsOptions{
|
||||
Limit: 50, Order: "desc", Search: c.sessionQuery.Peek(),
|
||||
})
|
||||
active, aerr := client.ActiveSessions(ctx)
|
||||
running := make(map[string]bool, len(active))
|
||||
for id := range active {
|
||||
@@ -419,6 +452,8 @@ func (c *controller) logout(reason string) {
|
||||
c.active.Set(map[string]bool{})
|
||||
c.perms.Set(nil)
|
||||
c.server.Set("")
|
||||
c.sessionQuery.Set("")
|
||||
c.searchOpen.Set(false)
|
||||
c.errorMsg.Set(reason)
|
||||
if conn.ID != "" && reason != "" {
|
||||
go func() { _ = c.st.ClearToken(conn) }()
|
||||
|
||||
Reference in new issue
Block a user