From e7b81c701f78b985cad0bfb74b637ca50d13e3e8 Mon Sep 17 00:00:00 2001
From: Eike Kettner <eike.kettner@posteo.de>
Date: Tue, 21 Apr 2020 18:01:11 +0200
Subject: [PATCH] Better handle no connections

---
 .../docspell/restserver/routes/NotifyDueItemsRoutes.scala | 2 +-
 modules/webapp/src/main/elm/Comp/NotificationForm.elm     | 8 +++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala
index 76ac9e20..e2496a7d 100644
--- a/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala
+++ b/modules/restserver/src/main/scala/docspell/restserver/routes/NotifyDueItemsRoutes.scala
@@ -79,7 +79,7 @@ object NotifyDueItemsRoutes {
     } yield NotificationSettings(
       task.id,
       task.enabled,
-      conn.getOrElse(Ident.unsafe("none")),
+      conn.getOrElse(Ident.unsafe("")),
       task.args.recipients,
       task.timer,
       task.args.remindDays,
diff --git a/modules/webapp/src/main/elm/Comp/NotificationForm.elm b/modules/webapp/src/main/elm/Comp/NotificationForm.elm
index 58d3e5bd..a9e1cfcd 100644
--- a/modules/webapp/src/main/elm/Comp/NotificationForm.elm
+++ b/modules/webapp/src/main/elm/Comp/NotificationForm.elm
@@ -24,6 +24,7 @@ import Html.Attributes exposing (..)
 import Html.Events exposing (onCheck, onClick)
 import Http
 import Util.Http
+import Util.Maybe
 import Util.Tag
 import Util.Update
 
@@ -271,9 +272,14 @@ update flags msg model =
 
         SetNotificationSettings (Ok s) ->
             let
+                smtp =
+                    Util.Maybe.fromString s.smtpConnection
+                        |> Maybe.map List.singleton
+                        |> Maybe.withDefault []
+
                 ( nm, nc ) =
                     Util.Update.andThen1
-                        [ update flags (ConnMsg (Comp.Dropdown.SetSelection [ s.smtpConnection ]))
+                        [ update flags (ConnMsg (Comp.Dropdown.SetSelection smtp))
                         , update flags (TagIncMsg (Comp.Dropdown.SetSelection s.tagsInclude))
                         , update flags (TagExcMsg (Comp.Dropdown.SetSelection s.tagsExclude))
                         ]