diff --git a/src/Scylla/AccountData.elm b/src/Scylla/AccountData.elm index 0137e7b..54e90eb 100644 --- a/src/Scylla/AccountData.elm +++ b/src/Scylla/AccountData.elm @@ -1,10 +1,21 @@ module Scylla.AccountData exposing (..) import Scylla.Sync exposing (SyncResponse, AccountData, JoinedRoom, roomAccountData) import Json.Decode as Decode +import Json.Encode as Encode import Dict exposing (Dict) type NotificationSetting = Normal | MentionsOnly | None +encodeNotificationSetting : NotificationSetting -> Decode.Value +encodeNotificationSetting ns = + let + string = case ns of + Normal -> "Normal" + MentionsOnly -> "MentionsOnly" + None -> "None" + in + Encode.string string + notificationSettingDecoder : Decode.Decoder NotificationSetting notificationSettingDecoder = let diff --git a/src/Scylla/Http.elm b/src/Scylla/Http.elm index 641fe0a..912f287 100644 --- a/src/Scylla/Http.elm +++ b/src/Scylla/Http.elm @@ -149,7 +149,7 @@ userData apiUrl token username = request , tracker = Nothing } -setReadMarkers : ApiUrl -> ApiToken -> String -> RoomId -> Maybe String -> Cmd Msg +setReadMarkers : ApiUrl -> ApiToken -> RoomId -> String -> Maybe String -> Cmd Msg setReadMarkers apiUrl token roomId fullyRead readReceipt = let readReciptFields = case readReceipt of @@ -176,3 +176,14 @@ sendTypingIndicator apiUrl token room user isTyping timeout = request , timeout = Nothing , tracker = Nothing } + +setRoomAccountData : ApiUrl -> ApiToken -> Username -> RoomId -> String -> Decode.Value -> Msg -> Cmd Msg +setRoomAccountData apiUrl token user roomId key value msg = request + { method = "PUT" + , headers = authenticatedHeaders token + , url = (fullClientUrl apiUrl) ++ "/user/" ++ user ++ "/rooms/" ++ roomId ++ "/account_data/" ++ key + , body = jsonBody value + , expect = expectWhatever (\_ -> msg) + , timeout = Nothing + , tracker = Nothing + } diff --git a/src/Scylla/Notification.elm b/src/Scylla/Notification.elm index 258dfc5..62f3bd2 100644 --- a/src/Scylla/Notification.elm +++ b/src/Scylla/Notification.elm @@ -18,7 +18,6 @@ producesNotification ns re = case ns of Normal -> True _ -> False - notificationText : RoomEvent -> String notificationText re = case (Decode.decodeValue (field "msgtype" string) re.content) of Ok "m.text" -> Result.withDefault "" <| (Decode.decodeValue (field "body" string) re.content)