feat: inline image previews, revert, and the official icon

- sent images keep a local copy and render as rounded thumbnails in the
  message, surviving later page reloads
- a prompt's menu can revert it and everything after it: confirm, then
  stage and commit the server-side revert
- the app icon is OpenChamber's own (packages/mobile/assets/icon-only.png)
- document a terminal assessment (native view vs Go ANSI vs xterm.js in
  a WebView) for the next decision

Bump version to 0.2.1 (build 15).
This commit is contained in:
blumia committed 2026-11-17 23:46:06 +08:00
1 parent 72119b73e8
commit dc3730eba7
9 files changed
+221 -22

No files matched your search

+58
View File
@@ -71,6 +71,7 @@ type chat struct {
attaching *signal.Signal[bool]
jumpToLatest *signal.Signal[bool]
lastScroll float32
imagePaths map[string][]string
pickerOpen *signal.Signal[bool]
pickerKind string
@@ -119,6 +120,7 @@ func (c *controller) openChat(s *ocapi.Session, nav *ui.Navigator) *chat {
attachments: signal.NewFunc([]attachment{}, nil),
attaching: signal.New(false),
jumpToLatest: signal.New(false),
imagePaths: map[string][]string{},
pickerOpen: signal.New(false),
pickerItems: signal.NewFunc([]pickerItem{}, nil),
pickerFilter: signal.New(""),
@@ -474,6 +476,11 @@ func (ch *chat) send() {
}
id := newMessageID()
sent := ch.optimisticFiles()
for _, a := range ch.attachments.Peek() {
if a.LocalPath != "" {
ch.imagePaths[id] = append(ch.imagePaths[id], a.LocalPath)
}
}
ch.draft.Set("")
ch.attachments.Set(nil)
ch.errText.Set("")
@@ -1187,6 +1194,15 @@ func (ch *chat) itemRow(it signal.Accessor[chatItem], _ signal.Accessor[int]) ui
ui.View(ui.ViewProps{Style: ui.Style{Padding: ui.Symmetric(8, 12), CornerRadius: 16, Gap: 4,
MaxWidth: ui.Pct(80), Background: colors.Accent}},
ui.Text(ch.textOf(cur.MsgID), ui.Style{Color: colors.OnAccent}),
ui.For(ch.imagesFor(cur.MsgID), func(p string) string { return p },
func(p signal.Accessor[string], _ signal.Accessor[int]) ui.Node {
return ui.Image(ui.ImageProps{
Source: p,
Mode: ui.ImageFill,
Style: ui.Style{Width: ui.Pt(200), Height: ui.Pt(150),
CornerRadius: 10, Clip: true, MaxWidth: ui.Pct(100)},
})
}),
ui.Show(signal.Func(func() bool { return len(ch.byID.Get()[cur.MsgID].Files) > 0 }),
func() ui.Node {
return ui.Text(ch.filesText(cur.MsgID),
@@ -1333,12 +1349,50 @@ func (ch *chat) userSheet() ui.Node {
)
}),
sheetAction("复制消息", "doc.on.doc", act(func() { ch.copyUserMessage(id) })),
sheetAction("撤回此消息及之后", "", act(func() { ch.revertFrom(id) })),
sheetAction("从这里分叉", "", act(func() { ch.forkBefore(id) })),
)
},
})
}
// revertFrom stages and commits a revert at a prompt, dropping that
// message and everything after it.
func (ch *chat) revertFrom(id string) {
ui.Alert(ui.AlertProps{
Title: "撤回消息?",
Message: "这条消息及其之后的内容会从会话中删除,且无法恢复。",
Actions: []ui.Action{
{Title: ui.Val("取消"), Role: ui.ActionCancel},
{Title: ui.Val("撤回"), Role: ui.ActionDestructive,
OnPress: func() { ch.doRevert(id) }},
},
})
}
func (ch *chat) doRevert(id string) {
client := ch.client()
if client == nil {
return
}
ch.errText.Set("")
go func() {
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
defer cancel()
if err := client.StageRevert(ctx, ch.id, ch.dir, id); err != nil {
ui.Post(func() { ch.errText.Set(friendlyError(err)) })
return
}
if err := client.CommitRevert(ctx, ch.id, ch.dir); err != nil {
ui.Post(func() { ch.errText.Set(friendlyError(err)) })
return
}
ui.Post(func() {
ch.reloadTail()
})
}()
}
// forkBefore copies the transcript before a message (a prompt) into a new
// session.
func (ch *chat) forkBefore(id string) {
@@ -1450,6 +1504,10 @@ func (ch *chat) toolRow(cur chatItem) ui.Node {
func (ch *chat) msg(id string) ocapi.Message { return ch.byID.Get()[id] }
func (ch *chat) imagesFor(id string) signal.Accessor[[]string] {
return signal.Func(func() []string { return ch.imagePaths[id] })
}
func (ch *chat) filesText(id string) signal.Accessor[string] {
return signal.Func(func() string {
m := ch.byID.Get()[id]