Skip to content

Commit 316fafd

Browse files
committed
Sync: Cleanup tree to make it more type safe and consistent with the new record tree.
1 parent bcd20c3 commit 316fafd

1 file changed

Lines changed: 16 additions & 62 deletions

File tree

  • src/main/java/io/github/hikingc/matrixsdk/api/events/sync

src/main/java/io/github/hikingc/matrixsdk/api/events/sync/Sync.java

Lines changed: 16 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package io.github.hikingc.matrixsdk.api.events.sync;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import io.github.hikingc.matrixsdk.api.events.ClientEvent;
5+
import io.github.hikingc.matrixsdk.api.events.EphemeralEvent;
6+
import io.github.hikingc.matrixsdk.api.events.matrix.ephemeral.EphemeralPresence;
47
import java.util.List;
58
import java.util.Map;
6-
7-
// If we make an interface for all message content types we can get rid of these Objects and make
8-
// serialization more
9-
// performant with the addition of type safety
10-
// 7/July/2026
9+
import org.jspecify.annotations.NonNull;
1110

1211
/// Represents the response body of a `/sync` request against a Matrix homeserver.
1312
///
@@ -32,12 +31,12 @@ public record Sync(
3231
/// A batch of account-data events.
3332
///
3433
/// @param events the account data events.
35-
public record AccountData(List<Event> events) {}
34+
public record AccountData(List<ClientEvent<?>> events) {}
3635

3736
/// A batch of presence events.
3837
///
3938
/// @param events the presence events.
40-
public record Presence(List<Event> events) {}
39+
public record Presence(List<EphemeralEvent<EphemeralPresence>> events) {}
4140

4241
/// Devices whose identity or cross-signing keys changed, relevant for E2EE.
4342
///
@@ -48,7 +47,7 @@ public record DeviceLists(List<String> changed, List<String> left) {}
4847
/// A batch of to-device events.
4948
///
5049
/// @param events the to-device events.
51-
public record ToDevice(List<Event> events) {}
50+
public record ToDevice(List<Object> events) {}
5251

5352
/// Room updates grouped by the client's membership state in each room.
5453
///
@@ -97,7 +96,7 @@ public record JoinedRoom(
9796
/// A batch of ephemeral events for a joined room.
9897
///
9998
/// @param events the ephemeral events.
100-
public record Ephemeral(List<Event> events) {}
99+
public record Ephemeral(List<EphemeralEvent<?>> events) {}
101100

102101
/// Summary information about a room, used to render it without loading full state.
103102
///
@@ -145,52 +144,6 @@ public record LeftRoom(
145144
AccountData accountData, State state, State stateAfter, Timeline timeline) {}
146145
}
147146

148-
/// A minimal event with no room, sender, or metadata context — used for account data, presence,
149-
/// and to-device events.
150-
///
151-
/// @param content the event content, shape depends on `type`.
152-
/// @param type the event type, e.g. `m.typing`.
153-
public record Event(
154-
@JsonProperty(required = true) Object content, @JsonProperty(required = true) String type) {}
155-
156-
/// A client-facing event as it appears in room timelines and state, excluding the room ID (since
157-
/// it is already known from context).
158-
///
159-
/// @param content the event content, shape depends on `type`.
160-
/// @param eventId the globally unique event identifier.
161-
/// @param originServerTs the timestamp, in milliseconds since the Unix epoch, when this event was
162-
/// sent.
163-
/// @param sender the user ID of the event's sender.
164-
/// @param stateKey the state key, present only if this is a state event.
165-
/// @param type the event type, e.g. `m.room.message`.
166-
/// @param unsigned additional metadata not covered by the event's signature.
167-
public record ClientEventWithoutRoomID(
168-
Object content,
169-
String eventId,
170-
Long originServerTs,
171-
String sender,
172-
String stateKey,
173-
String type,
174-
UnsignedData unsigned) {
175-
176-
/// Additional, unsigned metadata about an event.
177-
///
178-
/// @param age the time in milliseconds since this event was sent.
179-
/// @param membership the sender's membership at the time of this event, if applicable.
180-
/// @param prevContent the previous content for this state key, if this is a state event
181-
/// replacing one.
182-
/// @param redactedBecause the redaction event responsible for redacting this event, if it was
183-
/// redacted.
184-
/// @param transactionId the transaction ID set by the sending client, if the current client was
185-
/// the sender.
186-
public record UnsignedData(
187-
Long age,
188-
String membership,
189-
Object prevContent,
190-
ClientEventWithoutRoomID redactedBecause,
191-
String transactionId) {}
192-
}
193-
194147
/// A reduced-detail state event included in invite or knock previews, omitting fields such as
195148
/// `event_id` and timestamps that are not part of the stripped-state contract.
196149
///
@@ -199,22 +152,23 @@ public record UnsignedData(
199152
/// @param stateKey the state key for this event.
200153
/// @param type the event type, e.g. `m.room.member`.
201154
public record StrippedStateEvent(
202-
@JsonProperty(required = true) Object content,
203-
@JsonProperty(required = true) String sender,
204-
@JsonProperty(required = true) String stateKey,
205-
@JsonProperty(required = true) String type) {}
155+
@NonNull @JsonProperty(required = true) Object content,
156+
@NonNull @JsonProperty(required = true) String sender,
157+
@NonNull @JsonProperty(required = true) String stateKey,
158+
@NonNull @JsonProperty(required = true) String type) {}
206159

207160
/// A batch of room state events.
208161
///
209162
/// @param events the state events.
210-
public record State(List<ClientEventWithoutRoomID> events) {}
163+
public record State(List<ClientEvent<?>> events) {}
211164

212165
/// A paginated batch of timeline events for a room.
213166
///
167+
/// @apiNote The event list contains a `null` Room ID field
168+
///
214169
/// @param events the timeline events, in chronological order.
215170
/// @param limited whether the timeline was truncated, requiring further pagination to retrieve
216171
/// earlier events.
217172
/// @param prevBatch a pagination token for retrieving events older than this batch.
218-
public record Timeline(
219-
List<ClientEventWithoutRoomID> events, Boolean limited, String prevBatch) {}
173+
public record Timeline(List<ClientEvent<?>> events, Boolean limited, String prevBatch) {}
220174
}

0 commit comments

Comments
 (0)