Start working towards setting notification settings

This commit is contained in:
Danila Fedorin 2019-09-07 18:03:38 -07:00
parent 360b7be281
commit 1d50c5b1e4
3 changed files with 23 additions and 2 deletions

View File

@ -1,10 +1,21 @@
module Scylla.AccountData exposing (..) module Scylla.AccountData exposing (..)
import Scylla.Sync exposing (SyncResponse, AccountData, JoinedRoom, roomAccountData) import Scylla.Sync exposing (SyncResponse, AccountData, JoinedRoom, roomAccountData)
import Json.Decode as Decode import Json.Decode as Decode
import Json.Encode as Encode
import Dict exposing (Dict) import Dict exposing (Dict)
type NotificationSetting = Normal | MentionsOnly | None 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 : Decode.Decoder NotificationSetting
notificationSettingDecoder = notificationSettingDecoder =
let let

View File

@ -149,7 +149,7 @@ userData apiUrl token username = request
, tracker = Nothing , 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 = setReadMarkers apiUrl token roomId fullyRead readReceipt =
let let
readReciptFields = case readReceipt of readReciptFields = case readReceipt of
@ -176,3 +176,14 @@ sendTypingIndicator apiUrl token room user isTyping timeout = request
, timeout = Nothing , timeout = Nothing
, tracker = 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
}

View File

@ -18,7 +18,6 @@ producesNotification ns re = case ns of
Normal -> True Normal -> True
_ -> False _ -> False
notificationText : RoomEvent -> String notificationText : RoomEvent -> String
notificationText re = case (Decode.decodeValue (field "msgtype" string) re.content) of notificationText re = case (Decode.decodeValue (field "msgtype" string) re.content) of
Ok "m.text" -> Result.withDefault "" <| (Decode.decodeValue (field "body" string) re.content) Ok "m.text" -> Result.withDefault "" <| (Decode.decodeValue (field "body" string) re.content)