Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Oct 28, 2024
1 parent 1b64604 commit 49fb6a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions src/os_fcm_notif.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module Options = struct
end

module Data = struct
type t = (string * [`String of string | `Int of int]) list
type t = (string * [`String of string]) list

let to_list t = t
let to_json t = `Assoc (t : t :> (string * Yojson.Safe.t) list)
Expand All @@ -101,16 +101,18 @@ module Data = struct
let add_raw_json key value data =
(key, `String (Yojson.Safe.to_string value)) :: data

let add_int key value data = add_raw_string key (string_of_int value) data

module PhoneGap = struct
let add_message str t = add_raw_string "message" str t
let add_title str t = add_raw_string "title" str t
let add_image str t = add_raw_string "image" str t
let add_soundname str t = add_raw_string "soundname" str t

let add_notification_channel_id id t =
("android_channel_id", `String id) :: t
add_raw_string "android_channel_id" id t

let add_notification_id id t = ("notId", `String (string_of_int id)) :: t
let add_notification_id id t = add_int "notId" id t
let add_summary_text str t = add_raw_string "summaryText" str t

module Style = struct
Expand Down Expand Up @@ -138,20 +140,18 @@ module Data = struct

let add_actions left right t =
let actions_list = `List [Action.to_json left; Action.to_json right] in
("actions", `String (Yojson.Safe.to_string actions_list)) :: t
add_raw_json "actions" actions_list t

let add_led_color a r g b t =
let json_int_list = `List [`Int a; `Int r; `Int g; `Int b] in
("ledColor", `String (Yojson.Safe.to_string json_int_list)) :: t
add_raw_json "ledColor" json_int_list t

let add_vibration_pattern pattern t =
( "vibrationPattern"
, `String
(Yojson.Safe.to_string (`List (List.map (fun x -> `Int x) pattern)))
)
:: t
add_raw_json "vibrationPattern"
(`List (List.map (fun x -> `Int x) pattern))
t

let add_badge nb t = ("badge", `Int nb) :: t
let add_badge nb t = add_int "badge" nb t

module Priority = struct
type t = Minimum | Low | Default | High | Maximum
Expand All @@ -166,7 +166,7 @@ module Data = struct
| Priority.High -> 1
| Priority.Maximum -> 2
in
("priority", `Int int_of_priority) :: t
add_int "priority" int_of_priority t

(** NOTE: we don't add automatically the value picture to style because we
* don't know if we can mix Inbox and Picture at the same time. In general,
Expand All @@ -177,7 +177,7 @@ module Data = struct
let add_picture picture t = add_raw_string "picture" picture t

let add_info info t =
("info", `String info) :: ("content-available", `Int 1) :: t
("info", `String info) :: add_int "content-available" 1 t

module Visibility = struct
type t = Secret | Private | Public
Expand All @@ -190,7 +190,7 @@ module Data = struct
| Visibility.Private -> 0
| Visibility.Public -> 1
in
("visibility", `Int visibility_to_int) :: t
add_int "visibility" visibility_to_int t
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/os_fcm_notif.eliomi
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ module Data : sig

val to_json : t -> Yojson.Safe.t

val to_list : t -> (string * [`String of string | `Int of int]) list
val to_list : t -> (string * [`String of string]) list
(** [to_list data] returns the representation of the data as a list of
tuples [(data_key, json_value)]. *)

Expand Down

0 comments on commit 49fb6a2

Please sign in to comment.