Skip to content

Commit

Permalink
feat: allow sending invites when creating a channel (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaljam authored Nov 2, 2023
1 parent 2d40d2f commit 937dc3a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/io/getstream/chat/java/models/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ public static class ChannelRequestObject {
@JsonProperty("members")
private List<ChannelMemberRequestObject> members;

@Singular
@Nullable
@JsonProperty("invites")
private List<ChannelMemberRequestObject> invites;

@Nullable
@JsonProperty("config_overrides")
private ConfigOverridesRequestObject configOverrides;
Expand Down Expand Up @@ -259,6 +264,7 @@ private ChannelRequestObject(
@Nullable Language autoTranslationLanguage,
@Nullable Boolean frozen,
@Nullable List<ChannelMemberRequestObject> members,
@Nullable List<ChannelMemberRequestObject> invites,
@Nullable ConfigOverridesRequestObject configOverrides,
Map<String, Object> additionalFields) {
this.createdBy = createdBy;
Expand All @@ -267,6 +273,7 @@ private ChannelRequestObject(
this.autoTranslationLanguage = autoTranslationLanguage;
this.frozen = frozen;
this.members = members;
this.invites = invites;
this.configOverrides = configOverrides;
this.additionalFields = new HashMap<String, Object>(additionalFields);
}
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/io/getstream/chat/java/ChannelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -32,6 +33,39 @@ void whenRetrievingChannel_thenNoException() {
.request());
}

@DisplayName("Can create channel with invites")
@Test
void whenCreatingChannelWithInvites_thenNoException() {
var lastUser = testUsersRequestObjects.get(testUsersRequestObjects.size() - 1);
// invite last user and add the rest as members
var channelReq =
ChannelRequestObject.builder()
.createdBy(testUserRequestObject)
.members(
testUsersRequestObjects.stream()
.limit(testUsersRequestObjects.size() - 1)
.map(user -> ChannelMemberRequestObject.builder().user(user).build())
.collect(Collectors.toList()))
.invite(ChannelMemberRequestObject.builder().user(lastUser).build())
.build();
var channel =
Assertions.assertDoesNotThrow(
() -> Channel.getOrCreate(testChannel.getType()).data(channelReq).request());

var invitedMember =
channel.getMembers().stream()
.filter(
channelMember -> {
var invited = channelMember.getInvited();
return invited != null && invited;
})
.findFirst()
.get();

Assertions.assertNotNull(invitedMember);
Assertions.assertEquals(invitedMember.getUserId(), lastUser.getId());
}

@DisplayName("Can set custom field on channel")
@Test
void whenSettingCustomField_thenNoException() {
Expand Down

0 comments on commit 937dc3a

Please sign in to comment.