|
1 | 1 | package io.github.hikingc.matrixsdk.api; |
2 | 2 |
|
3 | 3 | import io.github.hikingc.matrixsdk.api.events.*; |
4 | | -import io.github.hikingc.matrixsdk.api.events.messages.RoomMessageEvent; |
5 | | -import io.github.hikingc.matrixsdk.api.events.types.RoomMemberEvent; |
| 4 | +import io.github.hikingc.matrixsdk.api.events.content.StateEventContent; |
| 5 | +import io.github.hikingc.matrixsdk.api.events.model.RoomMemberEvent; |
| 6 | +import io.github.hikingc.matrixsdk.api.events.queries.ChronologicalDirection; |
| 7 | +import io.github.hikingc.matrixsdk.api.events.queries.Membership; |
| 8 | +import io.github.hikingc.matrixsdk.api.events.queries.QueryParametersMessages; |
| 9 | +import io.github.hikingc.matrixsdk.api.events.queries.QueryParametersSync; |
| 10 | +import io.github.hikingc.matrixsdk.api.events.sync.Sync; |
6 | 11 | import io.github.hikingc.matrixsdk.api.identifiers.RoomID; |
7 | 12 | import io.github.hikingc.matrixsdk.exceptions.MatrixIOException; |
8 | 13 | import io.github.hikingc.matrixsdk.exceptions.MatrixNetworkException; |
9 | | - |
10 | 14 | import java.nio.file.Path; |
11 | 15 | import java.util.List; |
12 | 16 |
|
13 | 17 | /// Core interface for executing protocol operations against Room events. |
14 | 18 | /// |
15 | | -/// All operations in this interface are blocking. Implementations must ensure |
16 | | -/// thread safety and avoid synchronization blocks that cause carrier thread pinning |
17 | | -/// during network I/O. |
| 19 | +/// All operations in this interface are blocking. Implementations must ensure thread safety and |
| 20 | +/// avoid synchronization blocks that cause carrier thread pinning during network I/O. |
18 | 21 | /// |
19 | | -/// @see <a href="https://spec.matrix.org/v1.19/client-server-api/#events">Matrix Client-Server API Specification for Events</a> |
| 22 | +/// @see <a href="https://spec.matrix.org/v1.19/client-server-api/#events">Matrix Client-Server API |
| 23 | +/// Specification for Events</a> |
20 | 24 | public interface Event { |
21 | 25 |
|
22 | | - /// Gets an event from a room. |
23 | | - /// |
24 | | - /// @param roomId the room ID where the event is. |
25 | | - /// @param eventId the event ID to retrieve. |
26 | | - /// @return the full event. |
27 | | - DeserializedEvent getEvent(RoomID roomId, String eventId); |
28 | | - |
29 | | - /// Returns currently-joined members |
30 | | - /// |
31 | | - /// @param roomId the room ID to fetch data from. |
32 | | - /// @return a list of room members. |
33 | | - RoomMembers getJoinedMembers(RoomID roomId); |
34 | | - |
35 | | - /// Returns a filterable list of members and their current membership state in a room. |
36 | | - /// |
37 | | - /// @param roomId the room ID to fetch data from. |
38 | | - /// @param at the point in time (pagination token) to return members for in the room. This token can be obtained from a `prev_batch` token returned for each room by the sync API. |
39 | | - /// @param membership the kind of membership to filter for. When specified alongside notMembership, the two parameters create an `or` condition |
40 | | - /// @param notMembership the kind of membership to exclude from the results. Defaults to no filtering if unspecified. |
41 | | - /// @return a list of [DeserializedEvent]s with the membership information of room members. |
42 | | - List<RoomMemberEvent> getMembers(RoomID roomId, String at, Membership membership, Membership notMembership); |
43 | | - |
44 | | - /// Get the state events for the current state of a room. |
45 | | - /// |
46 | | - /// @param roomId the room ID to fetch data from. |
47 | | - /// @return the current state of the room |
48 | | - List<DeserializedEvent<?>> getStateEvents(RoomID roomId); |
49 | | - |
50 | | - /// Looks up the contents of a state event in a room. If the user is joined to the room then the state is taken from the current state of the room. |
51 | | - /// If the user has left the room then the state is taken from the state of the room when they left. |
52 | | - /// |
53 | | - /// @param roomId the room ID to fetch data from. |
54 | | - /// @param eventType the type of state to look up. |
55 | | - /// @param stateKey the room to look up the state in. |
56 | | - /// @return the content of the event, including all additional metadata fields. |
57 | | - DeserializedEvent getStateEvent(RoomID roomId, String eventType, String stateKey); |
58 | | - |
59 | | - /// Returns a list of message and state events for a room. It uses pagination query parameters to paginate |
60 | | - /// history in the room. |
61 | | - /// The content is not parsed or escaped which means newlines (`\n`) and such escape sequences will not be parsed. |
62 | | - /// |
63 | | - /// @param roomId the room ID to fetch data from. |
64 | | - /// @param params the [QueryParametersMessages] for the operation. |
65 | | - /// @param dir the [ChronologicalDirection] in which to search |
66 | | - /// @return [Messages] with available data. |
67 | | - /// @throws MatrixIOException when the payload cannot be processed. |
68 | | - /// @throws NullPointerException when the roomId is null. |
69 | | - Messages getMessages(RoomID roomId, ChronologicalDirection dir, QueryParametersMessages params); |
70 | | - |
71 | | - /// Gets an event from a room closest to the given timestamp, in the direction specified by the `dir` parameter. |
72 | | - /// |
73 | | - /// @param roomId the room ID to fetch data from. |
74 | | - /// @param dir the [ChronologicalDirection] in which to search |
75 | | - /// @param timestamp the timestamp to search from, as given in milliseconds since the Unix epoch. |
76 | | - /// @return [EventMetadata] if an event was found. |
77 | | - EventMetadata getEventClosestToTimestamp(RoomID roomId, ChronologicalDirection dir, int timestamp); |
78 | | - |
79 | | - /// Get a copy of the current state and the most recent messages in a room. |
80 | | - /// Exclusively used for "peeking", otherwise use [#sync(QueryParametersSync)]. |
81 | | - /// |
82 | | - /// @param roomId the room ID to fetch data from. |
83 | | - /// @return [RoomInfo] with current state of the room. |
84 | | - RoomInfo getInitialSync(RoomID roomId); |
85 | | - |
86 | | - /// @deprecated Experimental API that will suffer changes. It is likely this method will be deprecated |
87 | | - @Deprecated(since = "2026-07-31") |
88 | | - String sendStateEvent(RoomID roomId, String eventType, String stateKey, DeserializedEvent<?> matrixRoomMessageEvent); |
89 | | - |
90 | | - /// Creates a `m.room.message` event to a Matrix room. |
91 | | - /// |
92 | | - /// @param roomId the room ID where to send the event. |
93 | | - /// @param roomMessageEvent a well constructed [RoomMessageEvent]. |
94 | | - /// @return a [String] representing a unique identifier of the event. |
95 | | - /// @throws MatrixIOException when the payload cannot be processed. |
96 | | - /// @throws MatrixNetworkException when the response status is not successful. |
97 | | - String sendMessageEvent(RoomID roomId, RoomMessageEvent roomMessageEvent); |
98 | | - |
99 | | - /// Strips all information out of an event which isn’t critical to the integrity of the server-side representation of the room. |
100 | | - /// |
101 | | - /// **This cannot be undone.** |
102 | | - /// |
103 | | - /// If the server advertises support for sending a state event using `m.room.redact`, |
104 | | - /// use [#sendStateEvent(RoomID, String, String, DeserializedEvent)] |
105 | | - /// |
106 | | - /// @param roomId the room ID where to redact the event. |
107 | | - /// @param eventId the event ID of the event to target and redact. |
108 | | - /// @param txnId the transaction ID of the event. |
109 | | - /// @param reason the reason of the redaction. |
110 | | - /// @return a [String] representing a unique identifier of the event. |
111 | | - String redactEvent(RoomID roomId, String eventId, String txnId, String reason); |
112 | | - |
113 | | - /// Synchronously uploads a local multimedia resource to the Matrix media server. |
114 | | - /// |
115 | | - /// @param resource the [Path] of the resource to upload. |
116 | | - /// @return a [String] containing the MXC upon a successful upload. |
117 | | - String uploadResource(Path resource); |
118 | | - |
119 | | - /// Sends a `/sync` request, this method is not responsible for any type of HTTP Polling. |
120 | | - /// |
121 | | - /// @param params the [QueryParametersSync] for the query, not all are required. |
122 | | - /// @return [Sync] with all the corresponding information. |
123 | | - /// @throws MatrixIOException when the payload cannot be processed. |
124 | | - /// @throws MatrixNetworkException when the response status is not successful. |
125 | | - Sync sync(QueryParametersSync params); |
126 | | - |
127 | | - |
| 26 | + /// Gets an event from a room. |
| 27 | + /// |
| 28 | + /// @param roomId the room ID where the event is. |
| 29 | + /// @param eventId the event ID to retrieve. |
| 30 | + /// @return the full event. |
| 31 | + ClientEvent getEvent(RoomID roomId, String eventId); |
| 32 | + |
| 33 | + /// Returns currently-joined members |
| 34 | + /// |
| 35 | + /// @param roomId the room ID to fetch data from. |
| 36 | + /// @return a list of room members. |
| 37 | + RoomMembers getJoinedMembers(RoomID roomId); |
| 38 | + |
| 39 | + /// Returns a filterable list of members and their current membership state in a room. |
| 40 | + /// |
| 41 | + /// @param roomId the room ID to fetch data from. |
| 42 | + /// @param at the point in time (pagination token) to return members for in the room. This token |
| 43 | + /// can be obtained from a `prev_batch` token returned for each room by the sync API. |
| 44 | + /// @param membership the kind of membership to filter for. When specified alongside |
| 45 | + /// notMembership, the two parameters create an `or` condition |
| 46 | + /// @param notMembership the kind of membership to exclude from the results. Defaults to no |
| 47 | + /// filtering if unspecified. |
| 48 | + /// @return a list of [ClientEvent]s with the membership information of room members. |
| 49 | + List<RoomMemberEvent> getMembers( |
| 50 | + RoomID roomId, String at, Membership membership, Membership notMembership); |
| 51 | + |
| 52 | + /// Get the state events for the current state of a room. |
| 53 | + /// |
| 54 | + /// @param roomId the room ID to fetch data from. |
| 55 | + /// @return the current state of the room |
| 56 | + List<ClientEvent<?>> getStateEvents(RoomID roomId); |
| 57 | + |
| 58 | + /// Looks up the contents of a state event in a room. If the user is joined to the room then the |
| 59 | + /// state is taken from the current state of the room. If the user has left the room then the |
| 60 | + /// state is taken from the state of the room when they left. |
| 61 | + /// |
| 62 | + /// @param roomId the room ID to fetch data from. |
| 63 | + /// @param eventType the type of state to look up. |
| 64 | + /// @param stateKey the room to look up the state in. |
| 65 | + /// @return the content of the event, including all additional metadata fields. |
| 66 | + @SuppressWarnings("java:S1452") |
| 67 | + // Caller doesn't know content type ahead of time; polymorphic dispatch via @JsonTypeInfo resolves |
| 68 | + // it |
| 69 | + ClientEvent<?> getStateEvent(RoomID roomId, String eventType, String stateKey); |
| 70 | + |
| 71 | + /// Returns a list of message and state events for a room. It uses pagination query parameters to |
| 72 | + /// paginate history in the room. The content is not parsed or escaped which means newlines (`\n`) |
| 73 | + /// and such escape sequences will not be parsed. |
| 74 | + /// |
| 75 | + /// @param roomId the room ID to fetch data from. |
| 76 | + /// @param params the [QueryParametersMessages] for the operation. |
| 77 | + /// @param dir the [ChronologicalDirection] in which to search |
| 78 | + /// @return [Messages] with available data. |
| 79 | + /// @throws MatrixIOException when the payload cannot be processed. |
| 80 | + /// @throws NullPointerException when the roomId is null. |
| 81 | + Messages getMessages(RoomID roomId, ChronologicalDirection dir, QueryParametersMessages params); |
| 82 | + |
| 83 | + /// Gets an event from a room closest to the given timestamp, in the direction specified by the |
| 84 | + /// `dir` parameter. |
| 85 | + /// |
| 86 | + /// @param roomId the room ID to fetch data from. |
| 87 | + /// @param dir the [ChronologicalDirection] in which to search |
| 88 | + /// @param timestamp the timestamp to search from, as given in milliseconds since the Unix epoch. |
| 89 | + /// @return [EventMetadata] if an event was found. |
| 90 | + EventMetadata getEventClosestToTimestamp( |
| 91 | + RoomID roomId, ChronologicalDirection dir, int timestamp); |
| 92 | + |
| 93 | + /// Get a copy of the current state and the most recent messages in a room. Exclusively used for |
| 94 | + /// "peeking", otherwise use [#sync(QueryParametersSync)]. |
| 95 | + /// |
| 96 | + /// @param roomId the room ID to fetch data from. |
| 97 | + /// @return [RoomInfo] with current state of the room. |
| 98 | + RoomInfo getInitialSync(RoomID roomId); |
| 99 | + |
| 100 | + /// @param roomId the room ID where to send the event. |
| 101 | + /// @param stateKey if required to be set the state key, otherwise an empty [String] (""). |
| 102 | + /// @param roomStateContent any type of state event. |
| 103 | + /// @return a [String] representing a unique identifier of the event. |
| 104 | + /// @throws MatrixIOException when the payload cannot be processed. |
| 105 | + /// @throws MatrixNetworkException when the response status is not successful. |
| 106 | + String sendStateEvent(RoomID roomId, String stateKey, StateEventContent roomStateContent); |
| 107 | + |
| 108 | + String sendEvent(RoomID roomId, MessageEventContent content, String txnId); |
| 109 | + |
| 110 | + /// Strips all information out of an event which isn’t critical to the integrity of the |
| 111 | + /// server-side representation of the room. |
| 112 | + /// |
| 113 | + /// **This cannot be undone.** |
| 114 | + /// |
| 115 | + /// If the server advertises support for sending a state event using `m.room.redact`, use |
| 116 | + /// [#sendEvent(RoomID, MessageEventContent , String)] |
| 117 | + /// |
| 118 | + /// @param roomId the room ID where to redact the event. |
| 119 | + /// @param eventId the event ID of the event to target and redact. |
| 120 | + /// @param txnId the transaction ID of the event. |
| 121 | + /// @param reason the reason of the redaction. |
| 122 | + /// @return a [String] representing a unique identifier of the event. |
| 123 | + String redactEvent(RoomID roomId, String eventId, String txnId, String reason); |
| 124 | + |
| 125 | + /// Synchronously uploads a local multimedia resource to the Matrix media server. |
| 126 | + /// |
| 127 | + /// @param resource the [Path] of the resource to upload. |
| 128 | + /// @return a [String] containing the MXC upon a successful upload. |
| 129 | + String uploadResource(Path resource); |
| 130 | + |
| 131 | + /// Sends a `/sync` request, this method is not responsible for any type of HTTP Polling. |
| 132 | + /// |
| 133 | + /// @param params the [QueryParametersSync] for the query, not all are required. |
| 134 | + /// @return [Sync] with all the corresponding information. |
| 135 | + /// @throws MatrixIOException when the payload cannot be processed. |
| 136 | + /// @throws MatrixNetworkException when the response status is not successful. |
| 137 | + Sync sync(QueryParametersSync params); |
128 | 138 | } |
0 commit comments