Add retrieving account data, namely the notification setting.
This commit is contained in:
parent
490d0eff2c
commit
50701e1885
|
@ -12,6 +12,7 @@ import Scylla.UserData exposing (..)
|
||||||
import Scylla.Notification exposing (..)
|
import Scylla.Notification exposing (..)
|
||||||
import Scylla.Storage exposing (..)
|
import Scylla.Storage exposing (..)
|
||||||
import Scylla.Markdown exposing (..)
|
import Scylla.Markdown exposing (..)
|
||||||
|
import Scylla.AccountData exposing (..)
|
||||||
import Url exposing (Url)
|
import Url exposing (Url)
|
||||||
import Url.Parser exposing (parse)
|
import Url.Parser exposing (parse)
|
||||||
import Url.Builder
|
import Url.Builder
|
||||||
|
|
22
src/Scylla/AccountData.elm
Normal file
22
src/Scylla/AccountData.elm
Normal 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"
|
Loading…
Reference in New Issue
Block a user