Notify server when user discards attachment

This commit is contained in:
Drew DeVault 2020-11-12 12:09:51 -05:00
parent aad5f44f6c
commit 5268eba101
2 changed files with 16 additions and 0 deletions

View file

@ -53,6 +53,7 @@ func registerRoutes(p *alps.GoPlugin) {
p.POST("/compose", handleComposeNew) p.POST("/compose", handleComposeNew)
p.POST("/compose/attachment", handleComposeAttachment) p.POST("/compose/attachment", handleComposeAttachment)
p.POST("/compose/attachment/:uuid/remove", handleCancelAttachment)
p.GET("/message/:mbox/:uid/reply", handleReply) p.GET("/message/:mbox/:uid/reply", handleReply)
p.POST("/message/:mbox/:uid/reply", handleReply) p.POST("/message/:mbox/:uid/reply", handleReply)
@ -763,6 +764,15 @@ func handleComposeAttachment(ctx *alps.Context) error {
return ctx.JSON(http.StatusOK, &uuids) return ctx.JSON(http.StatusOK, &uuids)
} }
func handleCancelAttachment(ctx *alps.Context) error {
uuid := ctx.Param("uuid")
a := ctx.Session.PopAttachment(uuid)
if a != nil {
a.Form.RemoveAll()
}
return ctx.JSON(http.StatusOK, nil)
}
func unwrapIMAPAddressList(addrs []*imap.Address) []string { func unwrapIMAPAddressList(addrs []*imap.Address) []string {
l := make([]string, len(addrs)) l := make([]string, len(addrs))
for i, addr := range addrs { for i, addr := range addrs {

View file

@ -80,6 +80,12 @@ function attachFile(file) {
attachments = attachments.filter(a => a !== attachment); attachments = attachments.filter(a => a !== attachment);
node.remove(); node.remove();
updateState(); updateState();
if (typeof attachment.uuid !== "undefined") {
const cancel = new XMLHttpRequest();
cancel.open("POST", `/compose/attachment/${attachment.uuid}/remove`);
cancel.send();
}
}); });
let formData = new FormData(); let formData = new FormData();