Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/io/getstream/chat/java/models/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,10 @@ public static class GetChannelRequestData {
@JsonProperty("messages_id_around")
private String messagesIdAround;

@Nullable
@JsonProperty("include_soft_deleted_channel")
private Boolean includeSoftDeletedChannel;

public static class GetChannelRequest extends StreamRequest<ChannelGetResponse> {
@NotNull private String channelType;

Expand Down Expand Up @@ -1761,7 +1765,9 @@ public static ChannelGetRequest getOrCreate(@NotNull String type) {
/**
* Creates a get channel request. The channel is never created: a missing, deleted or disabled
* channel yields a 404, so this request doubles as an existence check. The messages of the
* channel are paged with the messagesId* parameters, which need state to be true.
* channel are paged with the messagesId* parameters, which need state to be true. Set
* includeSoftDeletedChannel to read a soft-deleted channel and the messages its deletion hid; its
* members are not returned.
*
* @param type the channel type
* @param id the channel id
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/io/getstream/chat/java/ChannelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,42 @@ private List<String> messageIds(ChannelGetResponse response) {
return response.getMessages().stream().map(Message::getId).collect(Collectors.toList());
}

@DisplayName("Can get a soft-deleted channel and its messages")
@Test
void whenGettingSoftDeletedChannelWithInclude_thenReturnsChannelAndMessages() {
var channelId = RandomStringUtils.randomAlphabetic(12);
Assertions.assertDoesNotThrow(
() ->
Channel.getOrCreate(testChannel.getType(), channelId)
.data(
ChannelRequestObject.builder()
.createdBy(testUserRequestObject)
.members(buildChannelMembersList())
.build())
.request());

var first = sendMessageToChannel(channelId, "first");
var second = sendMessageToChannel(channelId, "second");

Assertions.assertDoesNotThrow(() -> Channel.delete(testChannel.getType(), channelId).request());

var notFound =
Assertions.assertThrows(
StreamException.class,
() -> Channel.getChannel(testChannel.getType(), channelId).state(true).request());
Assertions.assertEquals(404, notFound.getResponseData().getStatusCode());

var response =
Assertions.assertDoesNotThrow(
() ->
Channel.getChannel(testChannel.getType(), channelId)
.state(true)
.includeSoftDeletedChannel(true)
.request());
Assertions.assertNotNull(response.getChannel().getDeletedAt());
Assertions.assertEquals(Arrays.asList(first, second), messageIds(response));
}

@DisplayName("Get channel does not create a missing channel")
@Test
void whenGettingMissingChannel_thenNotFound() {
Expand Down
Loading