Skip to content

Commit 77de3ea

Browse files
committed
Expose channel history through the Java server SDK
This adds a thin getChannelHistory helper over the existing\nsigned get() surface so durable channel history queries match the\nrest of the phase-2 server SDK contract. Constraint: Must preserve the existing SDK style and thin request shape where appropriate Rejected: Leave history/recovery access as manual path construction only | inconsistent public surface Confidence: medium Scope-risk: moderate Reversibility: clean Directive: Keep payload names aligned exactly with server event and query contracts Tested: ./gradlew test Not-tested: none
1 parent 1d3998b commit 77de3ea

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,20 @@ This library supports end-to-end encryption of private channels. Only you and yo
273273

274274
**Note:** A single `trigger` call cannot target both encrypted and unencrypted channels simultaneously.
275275

276+
### Channel history
277+
278+
```java
279+
Map<String, String> params = new HashMap<>();
280+
params.put("limit", "50");
281+
params.put("direction", "newest_first");
282+
283+
Result page = sockudo.getChannelHistory("my-channel", params);
284+
Result nextPage = sockudo.getChannelHistory(
285+
"my-channel",
286+
Collections.singletonMap("cursor", "opaque-cursor-from-previous-page")
287+
);
288+
```
289+
276290
## License
277291

278292
This code is free to use under the terms of the MIT license.

src/main/java/io/sockudo/rest/SockudoAbstract.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,30 @@ public T get(final String path, final Map<String, String> parameters) {
512512
return doGet(uri);
513513
}
514514

515+
/**
516+
* Fetch durable history for a specific channel.
517+
*
518+
* @param channelName the channel to query
519+
* @param parameters history query parameters such as limit, direction, cursor,
520+
* start_serial, end_serial, start_time_ms, end_time_ms
521+
* @return a {@link Result} object encapsulating the success state and response
522+
*/
523+
public T getChannelHistory(final String channelName, final Map<String, String> parameters) {
524+
Prerequisites.nonEmpty("channelName", channelName);
525+
Prerequisites.isValidChannel(channelName);
526+
return get("/channels/" + channelName + "/history", parameters);
527+
}
528+
529+
/**
530+
* Fetch durable history for a specific channel without additional query parameters.
531+
*
532+
* @param channelName the channel to query
533+
* @return a {@link Result} object encapsulating the success state and response
534+
*/
535+
public T getChannelHistory(final String channelName) {
536+
return getChannelHistory(channelName, Collections.<String, String>emptyMap());
537+
}
538+
515539
protected abstract T doGet(final URI uri);
516540

517541
/**

src/test/java/io/sockudo/rest/SockudoTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,24 @@ public void reservedParameter() {
241241
});
242242
}
243243

244+
@Test
245+
public void getChannelHistory() throws Exception {
246+
context.checking(new Expectations() {{
247+
oneOf(httpClient).execute(with(path("/apps/" + APP_ID + "/channels/history-room/history")));
248+
}});
249+
250+
p.getChannelHistory("history-room");
251+
}
252+
253+
@Test
254+
public void getChannelHistoryWithParams() throws Exception {
255+
context.checking(new Expectations() {{
256+
oneOf(httpClient).execute(with(path("/apps/" + APP_ID + "/channels/history-room/history")));
257+
}});
258+
259+
p.getChannelHistory("history-room", Collections.singletonMap("direction", "newest_first"));
260+
}
261+
244262
@Test
245263
public void testTriggerOnEncryptedChannel() throws IOException {
246264
final Sockudo pe = new Sockudo(APP_ID, KEY, SECRET, VALID_MASTER_KEY);

0 commit comments

Comments
 (0)