From 50701e18850ac2de9d79e61894c41a87aae05866 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 22 Dec 2018 21:42:51 -0800 Subject: [PATCH] Add retrieving account data, namely the notification setting. --- src/Main.elm | 1 + src/Scylla/AccountData.elm | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/Scylla/AccountData.elm diff --git a/src/Main.elm b/src/Main.elm index a6dfe27..dbc447f 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -12,6 +12,7 @@ import Scylla.UserData exposing (..) import Scylla.Notification exposing (..) import Scylla.Storage exposing (..) import Scylla.Markdown exposing (..) +import Scylla.AccountData exposing (..) import Url exposing (Url) import Url.Parser exposing (parse) import Url.Builder diff --git a/src/Scylla/AccountData.elm b/src/Scylla/AccountData.elm new file mode 100644 index 0000000..25cb133 --- /dev/null +++ b/src/Scylla/AccountData.elm @@ -0,0 +1,22 @@ +module Scylla.AccountData exposing (..) +import Scylla.Sync exposing (AccountData, JoinedRoom, roomAccountData) +import Json.Decode as Decode + +type NotificationSetting = Normal | MentionsOnly | None + +notificationSettingDecoder : Decode.Decoder NotificationSetting +notificationSettingDecoder = + let + checkString s = case s of + "Normal" -> Decode.succeed Normal + "MentionsOnly" -> Decode.succeed MentionsOnly + "None" -> Decode.succeed None + _ -> Decode.fail "Not a valid notification setting" + in + Decode.andThen checkString Decode.string + +roomNotificationSetting : JoinedRoom -> NotificationSetting +roomNotificationSetting jr = Maybe.withDefault Normal + <| Maybe.andThen Result.toMaybe + <| Maybe.map (Decode.decodeValue notificationSettingDecoder) + <| roomAccountData jr "com.danilafe.scylla.notifications"