-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat_message.ml
43 lines (39 loc) · 1.11 KB
/
chat_message.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
type t = {
id: int option;
peer_id: int option;
time: int;
text: string option;
from: string option;
first_name: string option;
last_name: string option;
photo: string option;
};;
let create json =
let open Yojson.Basic.Util in
{
id = json |> index 1 |> to_int_option;
peer_id = json |> index 3 |> to_int_option;
time = json |> index 4 |> to_int;
text = json |> index 6 |> to_string_option;
from = json |> index 7 |> member "from" |> to_string_option;
first_name = None;
last_name = None;
photo = None;
};;
let test_peer_id msg test =
match msg.peer_id with
| Some peer_id_-> Some (test peer_id_)
| None -> None
let get_time msg = msg.time;;
let get_from msg = msg.from;;
let get_text msg = msg.text;;
let get_first_name msg = msg.first_name;;
let get_last_name msg = msg.last_name;;
let get_photo msg = msg.photo;;
let fill_user_info ~first_name ~last_name ~photo msg =
{
msg with
first_name = Some first_name;
last_name = Some last_name;
photo = Some photo
}