Skip to content

Commit c284cbb

Browse files
committed
Add first "batch" of state events.
- This includes new interfaces and extraction of some records for shared usage. - This commit deprecates the sendStateEvent - RoomMessageEvent has been moved
1 parent c1b2fa8 commit c284cbb

33 files changed

Lines changed: 416 additions & 67 deletions

src/main/java/io/github/hikingc/matrixsdk/api/Event.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.hikingc.matrixsdk.api;
22

33
import io.github.hikingc.matrixsdk.api.events.*;
4+
import io.github.hikingc.matrixsdk.api.events.messages.RoomMessageEvent;
45
import io.github.hikingc.matrixsdk.api.identifiers.RoomID;
56
import io.github.hikingc.matrixsdk.exceptions.MatrixIOException;
67
import io.github.hikingc.matrixsdk.exceptions.MatrixNetworkException;
@@ -97,7 +98,7 @@ public interface Event {
9798
/// **This cannot be undone.**
9899
///
99100
/// If the server advertises support for sending a state event using `m.room.redact`,
100-
/// use [#sendStateEvent(RoomID, String, String, RoomStateEvent)]
101+
/// use [#sendStateEvent(RoomID, String, String, DeserializedEvent)]
101102
///
102103
/// @param roomId the room ID where to redact the event.
103104
/// @param eventId the event ID of the event to target and redact.

src/main/java/io/github/hikingc/matrixsdk/api/events/ClientEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ public record ClientEvent(@JsonProperty(required = true) Map<String, Object> con
3030
String stateKey,
3131
@JsonProperty(required = true) String type,
3232
UnsignedData unsigned
33-
) implements RoomStateEvent<Map<String, Object>> {
33+
) implements DeserializedEvent<Map<String, Object>> {
3434
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.github.hikingc.matrixsdk.api.events;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
5+
6+
/// Interface that enforces fields required by both State and Message events when the event is retrieved from the server.
7+
///
8+
/// @param <T> the event `m.` type
9+
/// @see <a href="https://spec.matrix.org/latest/client-server-api/#room-event-format">The room event format as defined in the specification.</a>
10+
@JsonInclude(JsonInclude.Include.NON_ABSENT)
11+
public sealed interface DeserializedEvent<T> permits ClientEvent, SingletonStateEvent {
12+
13+
/// @return the body of this event, as created by the user which sent it.
14+
T content();
15+
16+
/// @return the globally unique identifier for this event.
17+
String eventId();
18+
19+
20+
/// @return timestamp (in milliseconds since the Unix epoch) on originating homeserver when this event
21+
/// was sent.
22+
Long originServerTs();
23+
24+
/// @return the ID of the room associated with this event.
25+
String roomId();
26+
27+
/// @return contains the fully-qualified ID of the user who sent this event.
28+
String sender();
29+
30+
/// @return present if, and only if, this event is a state event. The key making this piece of state
31+
/// unique in the room. Note that it is often an empty string.
32+
/// State keys starting with an @ are reserved for referencing user IDs, such as room members. Except a few events,
33+
/// state events set with a given user’s ID as the state key MUST only be set by that user.
34+
String stateKey();
35+
36+
/// @return the type of the event.
37+
String type();
38+
39+
/// @return optional extra information about the event.
40+
UnsignedData unsigned();
41+
42+
}

src/main/java/io/github/hikingc/matrixsdk/api/events/EncryptedFile.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.hikingc.matrixsdk.api.events;
22

3+
import io.github.hikingc.matrixsdk.api.events.messages.RoomMessageEvent;
4+
35
import java.util.Map;
46

57
/// Holds information of an encrypted file as the extension to [RoomMessageEvent].
Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package io.github.hikingc.matrixsdk.api.events;
22

3-
import com.fasterxml.jackson.annotation.JsonProperty;
4-
53
import java.net.URI;
6-
import java.util.Map;
74

85
/// Represents the contents of an event
96
///
@@ -27,21 +24,4 @@ public record EventContent(URI avatarUrl,
2724
ThirdPartyInvite thirdPartyInvite) {
2825

2926

30-
/// @param displayName a name which can be displayed to represent the user instead of their third-party identifier
31-
/// @param signed a block of content which has been signed by the identity server, which homeservers can use to verify the event. Clients should ignore this.
32-
public record ThirdPartyInvite(@JsonProperty(required = true) String displayName,
33-
@JsonProperty(required = true) SignedThirdPartyInvite signed) {
34-
35-
/// @param mxid the user ID that has been bound to the third-party identifier.
36-
/// @param signatures the identity server signatures for this block. This is a map of identity server name to signing key identifier to base64-encoded signature.
37-
/// @param token The token generated by the identity server at the `/store_invite` endpoint.
38-
///
39-
/// It matches the `state_key` of the corresponding `m.room.third_party_invite` event.
40-
/// @see <a href="https://spec.matrix.org/v1.19/appendices/#signing-json">documentation about Signing JSON</a>
41-
/// @see <a href="https://spec.matrix.org/v1.19/identity-service-api/#post_matrixidentityv2store-invite">Identity Service API</a>
42-
public record SignedThirdPartyInvite(@JsonProperty(required = true) String mxid,
43-
@JsonProperty(required = true) Map<String, Map<String, String>> signatures,
44-
@JsonProperty(required = true) String token) {
45-
}
46-
}
4727
}

src/main/java/io/github/hikingc/matrixsdk/api/events/RoomInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import io.github.hikingc.matrixsdk.api.Room;
5+
import io.github.hikingc.matrixsdk.api.events.messages.RoomMessageEvent;
56
import io.github.hikingc.matrixsdk.api.identifiers.RoomID;
67
import io.github.hikingc.matrixsdk.api.rooms.PublicRoomRequest;
78

@@ -24,7 +25,7 @@ public record RoomInfo(List<Event> accountData,
2425
List<ClientEvent> state,
2526
String visibility) {
2627

27-
/// Holds a Matrix event, which can then be serialized as one of either [RoomStateEvent] or [RoomMessageEvent] for example.
28+
/// Holds a Matrix event, which can then be serialized as one of either [DeserializedEvent] or [RoomMessageEvent] for example.
2829
///
2930
/// @param content the fields of an event.
3031
/// @param type the type of the event, for example, `m.tag`

src/main/java/io/github/hikingc/matrixsdk/api/events/RoomStateEvent.java

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.github.hikingc.matrixsdk.api.events;
2+
3+
import io.github.hikingc.matrixsdk.api.events.states.*;
4+
5+
/// Interface that represents all state events which hold an empty `state_key` [String].
6+
///
7+
/// @param <C> a Record that represents the `content` of the event.
8+
public sealed interface SingletonStateEvent<C> extends DeserializedEvent<C> permits RoomAvatarEvent, RoomCanonicalAliasEvent, RoomCreateEvent, RoomGuestAcessEvent, RoomHistoryVisibilityEvent, RoomJoinRulesEvent, RoomMemberEvent, RoomNameEvent, RoomPinnedEventEvents, RoomPowerLevelsEvent, RoomTopicEvent {
9+
10+
default String stateKey() {
11+
return "";
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.github.hikingc.matrixsdk.api.events;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.util.Map;
6+
7+
/// @param displayName a name which can be displayed to represent the user instead of their third-party identifier
8+
/// @param signed a block of content which has been signed by the identity server, which homeservers can use to verify the event. Clients should ignore this.
9+
public record ThirdPartyInvite(@JsonProperty(required = true) String displayName,
10+
@JsonProperty(required = true) SignedThirdPartyInvite signed) {
11+
12+
/// @param mxid the user ID that has been bound to the third-party identifier.
13+
/// @param signatures the identity server signatures for this block. This is a map of identity server name to signing key identifier to base64-encoded signature.
14+
/// @param token The token generated by the identity server at the `/store_invite` endpoint.
15+
///
16+
/// It matches the `state_key` of the corresponding `m.room.third_party_invite` event.
17+
/// @see <a href="https://spec.matrix.org/v1.19/appendices/#signing-json">documentation about Signing JSON</a>
18+
/// @see <a href="https://spec.matrix.org/v1.19/identity-service-api/#post_matrixidentityv2store-invite">Identity Service API</a>
19+
public record SignedThirdPartyInvite(@JsonProperty(required = true) String mxid,
20+
@JsonProperty(required = true) Map<String, Map<String, String>> signatures,
21+
@JsonProperty(required = true) String token) {
22+
}
23+
}

src/main/java/io/github/hikingc/matrixsdk/api/events/messages/HasInfo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.hikingc.matrixsdk.api.events.messages;
22

3+
import io.github.hikingc.matrixsdk.api.events.states.RoomAvatar;
4+
35
/// Marks event content that includes file metadata such as a MIME type
46
/// and size in bytes, as described by the Matrix specification's
57
/// `info` object.
@@ -8,8 +10,7 @@
810
/// @see Image.ImageInfo
911
/// @see File.FileInfo
1012
/// @see Video.VideoInfo
11-
public sealed interface HasInfo permits Audio.AudioInfo, File.FileInfo, Image.ImageInfo,
12-
Video.VideoInfo {
13+
public sealed interface HasInfo permits Audio.AudioInfo, File.FileInfo, Image.ImageInfo, Video.VideoInfo, RoomAvatar.AvatarInfo {
1314
/// @return the mimetype of the corresponding input resource
1415
String mimetype();
1516

0 commit comments

Comments
 (0)