aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2020-11-12 12:09:51 -0500
committerDrew DeVault <sir@cmpwn.com>2020-11-12 12:09:51 -0500
commit5268eba101e1919e2ced0385c51c58b14b8ed668 (patch)
tree3f82948ab9d258a25b91f27ad05a4a44124b739b
parentaad5f44f6cb605589fa017bc521e47a4a517b57d (diff)
downloadalps-5268eba101e1919e2ced0385c51c58b14b8ed668.tar.gz
alps-5268eba101e1919e2ced0385c51c58b14b8ed668.zip
Notify server when user discards attachment
-rw-r--r--plugins/base/routes.go10
-rw-r--r--themes/alps/assets/attachments.js6
2 files changed, 16 insertions, 0 deletions
diff --git a/plugins/base/routes.go b/plugins/base/routes.go
index df32876..c4ab492 100644
--- a/plugins/base/routes.go
+++ b/plugins/base/routes.go
@@ -53,6 +53,7 @@ func registerRoutes(p *alps.GoPlugin) {
p.POST("/compose", handleComposeNew)
p.POST("/compose/attachment", handleComposeAttachment)
+ p.POST("/compose/attachment/:uuid/remove", handleCancelAttachment)
p.GET("/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)
}
+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 {
l := make([]string, len(addrs))
for i, addr := range addrs {
diff --git a/themes/alps/assets/attachments.js b/themes/alps/assets/attachments.js
index 612808a..dc6cc04 100644
--- a/themes/alps/assets/attachments.js
+++ b/themes/alps/assets/attachments.js
@@ -80,6 +80,12 @@ function attachFile(file) {
attachments = attachments.filter(a => a !== attachment);
node.remove();
updateState();
+
+ if (typeof attachment.uuid !== "undefined") {
+ const cancel = new XMLHttpRequest();
+ cancel.open("POST", `/compose/attachment/${attachment.uuid}/remove`);
+ cancel.send();
+ }
});
let formData = new FormData();