Accept pasted images in inbox Other and Reply answers

This commit is contained in:
Ian Gulliver
2026-10-16 22:49:06 -07:00
parent a9bec7a7ea
commit ea90178fce
19 changed files with 579 additions and 469 deletions
+13 -4
View File
@@ -42,6 +42,10 @@ func (m *Manager) Respond(ctx context.Context, user string, creates []api.InboxR
if create.Attachments != nil {
attachments = *create.Attachments
}
images := []string{}
if create.Images != nil {
images = *create.Images
}
resolutions = append(resolutions, store.Resolution{
State: state,
@@ -52,6 +56,7 @@ func (m *Manager) Respond(ctx context.Context, user string, creates []api.InboxR
Type: create.Type,
Options: create.Options,
Text: create.Text,
Images: images,
Attachments: attachments,
CreatedAt: time.Now().UTC(),
},
@@ -102,6 +107,7 @@ func CheckResponse(item api.InboxItem, c api.InboxResponseCreate) (api.InboxStat
if c.Text != nil {
text = strings.TrimSpace(*c.Text)
}
images := c.Images != nil && len(*c.Images) > 0
question := item.Kind == api.Question
bad := func(format string, args ...any) (api.InboxState, error) {
return "", fmt.Errorf("%w: item %s: "+format, append([]any{ErrInvalid, item.Id}, args...)...)
@@ -128,14 +134,14 @@ func CheckResponse(item api.InboxItem, c api.InboxResponseCreate) (api.InboxStat
}
seen[o] = true
}
if text != "" && item.Payload["multiple"] != true {
return bad("a pick-one option takes no text; use other")
if (text != "" || images) && item.Payload["multiple"] != true {
return bad("a pick-one option takes no text or images; use other")
}
return api.Answered, nil
case api.Other:
if text == "" {
return bad("other needs text")
if text == "" && !images {
return bad("other needs text or images")
}
return api.Answered, nil
@@ -143,6 +149,9 @@ func CheckResponse(item api.InboxItem, c api.InboxResponseCreate) (api.InboxStat
if question {
return bad("questions need an option or other, not a dismissal")
}
if images {
return bad("a dismissal takes no images")
}
return api.Dismissed, nil
}