Add retrieving account data, namely the notification setting.

This commit is contained in:
Danila Fedorin 2018-12-22 21:42:51 -08:00
parent 490d0eff2c
commit 50701e1885
2 changed files with 23 additions and 0 deletions

View File

@ -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

View File

@ -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"