Matrix protocol in OCaml, Eio specialised
1(** Eio-idiomatic relation operations (reactions, edits, threads, replies). *)
2
3(** Send a reaction to an event.
4
5 @param room_id The room containing the event
6 @param event_id The event to react to
7 @param key The reaction key (usually an emoji)
8 @return The reaction event ID
9 @raise Eio.Io on failure *)
10let send_reaction client ~room_id ~event_id ~key =
11 Error.unwrap (Matrix_client.Relations.send_reaction (Client.base client)
12 ~room_id ~event_id ~key)
13
14(** Send an edit to a message.
15
16 @param room_id The room containing the event
17 @param event_id The event to edit
18 @param new_body The new message body
19 @return The edit event ID
20 @raise Eio.Io on failure *)
21let edit_message client ~room_id ~event_id ~new_body =
22 Error.unwrap (Matrix_client.Relations.edit_message (Client.base client)
23 ~room_id ~event_id ~new_body)
24
25(** Send a reply to a message.
26
27 @param room_id The room containing the event
28 @param event_id The event to reply to
29 @param body The reply body
30 @return The reply event ID
31 @raise Eio.Io on failure *)
32let send_reply client ~room_id ~event_id ~body =
33 Error.unwrap (Matrix_client.Relations.send_reply (Client.base client)
34 ~room_id ~event_id ~body)
35
36(** Send a message in a thread.
37
38 @param room_id The room containing the thread
39 @param thread_root_id The root event of the thread
40 @param body The message body
41 @param reply_to_id Optional event to reply to within the thread
42 @return The message event ID
43 @raise Eio.Io on failure *)
44let send_in_thread client ~room_id ~thread_root_id ?reply_to_id ~body () =
45 Error.unwrap (Matrix_client.Relations.send_in_thread (Client.base client)
46 ~room_id ~thread_root_id ?reply_to_id ~body ())
47
48(** Relation type *)
49type relation_type = Matrix_client.Relations.relation_type =
50 | Annotation (** m.annotation - reactions *)
51 | Reference (** m.reference - generic reference *)
52 | Replace (** m.replace - edits *)
53 | Thread (** m.thread - threads *)
54
55(** Aggregation result *)
56type aggregation = Matrix_client.Relations.aggregation = {
57 event_id : Matrix_proto.Id.Event_id.t;
58 origin_server_ts : int64;
59 sender : Matrix_proto.Id.User_id.t;
60}
61
62(** Relations response *)
63type relations_response = Matrix_client.Relations.relations_response = {
64 chunk : aggregation list;
65 next_batch : string option;
66 prev_batch : string option;
67}
68
69(** Get events related to a given event.
70
71 @param room_id The room containing the event
72 @param event_id The event to get relations for
73 @param rel_type Optional relation type filter
74 @param event_type Optional event type filter
75 @param limit Maximum number of events
76 @param from Pagination token
77 @raise Eio.Io on failure *)
78let get_relations client ~room_id ~event_id ?rel_type ?event_type ?limit ?from () =
79 Error.unwrap (Matrix_client.Relations.get_relations (Client.base client)
80 ~room_id ~event_id ?rel_type ?event_type ?limit ?from ())
81
82(** Get reactions for an event.
83 @raise Eio.Io on failure *)
84let get_reactions client ~room_id ~event_id =
85 Error.unwrap (Matrix_client.Relations.get_reactions (Client.base client) ~room_id ~event_id)