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
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.1'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation 'org.apache.commons:commons-lang3:3.12.0'
compileOnly 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'

testCompileOnly 'org.projectlombok:lombok:1.18.20'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
testCompileOnly 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
}

def localProperties = new Properties()
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/io/getstream/chat/java/models/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -1531,4 +1531,48 @@ public static FlagMessageQueryRequest queryFlags() {
public static MessagePartialUpdateRequest partialUpdate(@NotNull String id) {
return new MessagePartialUpdateRequest(id);
}

/**
* Creates a pin message request without expiration. It invokes message partial update under the
* hood.
*
* @param id the message id
* @param userId id of the user who pins the message
* @return the created request
*/
@NotNull
public static MessagePartialUpdateRequest pinMessage(@NotNull String id, @NotNull String userId) {
return new MessagePartialUpdateRequest(id).setValue("pinned", true).userId(userId);
}

/**
* Creates a pin message request with expiration. It invokes message partial update under the
* hood.
*
* @param id the message id
* @param userId id of the user who pins the message
* @param expiration expiration of the pin
* @return the created request
*/
@NotNull
public static MessagePartialUpdateRequest pinMessage(
@NotNull String id, @NotNull String userId, @NotNull Date expiration) {
return new MessagePartialUpdateRequest(id)
.setValue("pinned", true)
.setValue("pin_expires", expiration)
.userId(userId);
}

/**
* Creates an unpin message request. It invokes message partial update under the hood.
*
* @param id the message id
* @param userId id of the user who unpins the message
* @return the created request
*/
@NotNull
public static MessagePartialUpdateRequest unpinMessage(
@NotNull String id, @NotNull String userId) {
return new MessagePartialUpdateRequest(id).setValue("pinned", false).userId(userId);
}
}
30 changes: 28 additions & 2 deletions src/main/java/io/getstream/chat/java/models/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,8 @@ public static class UserUnbanRequest extends StreamRequest<StreamResponseObject>

@Nullable private String id;

@Nullable private Boolean shadow;

@NotNull
public UserUnbanRequest type(@NotNull String type) {
this.type = type;
Expand All @@ -1027,9 +1029,15 @@ public UserUnbanRequest id(@NotNull String id) {
return this;
}

@NotNull
public UserUnbanRequest shadow(@NotNull Boolean shadow) {
this.shadow = shadow;
return this;
}

@Override
protected Call<StreamResponseObject> generateCall(Client client) {
return client.create(UserService.class).unban(targetUserId, type, id);
return client.create(UserService.class).unban(targetUserId, type, id, shadow);
}
}

Expand Down Expand Up @@ -1213,7 +1221,15 @@ public static UserPartialUpdateRequest partialUpdate() {
public static UserBanRequest ban() {
return new UserBanRequest();
}

/**
* Creates a shadow ban request
*
* @return the created request
*/
@NotNull
public static UserBanRequest shadowBan() {
return new UserBanRequest().shadow(true);
}
/**
* Creates a query banned request
*
Expand Down Expand Up @@ -1342,6 +1358,16 @@ public static UserUnbanRequest unban(@NotNull String targetUserId) {
return new UserUnbanRequest(targetUserId);
}

/**
* Creates a remove shadow ban request
*
* @param targetUserId the user id to unban
* @return the created request
*/
@NotNull
public static UserUnbanRequest removeShadowBan(@NotNull String targetUserId) {
return new UserUnbanRequest(targetUserId).shadow(true);
}
/**
* Creates a revoke token request
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ Call<UserCreateGuestResponse> createGuest(
Call<StreamResponseObject> unban(
@NotNull @Query("target_user_id") String targetUserId,
@Nullable @Query("type") String channelType,
@Nullable @Query("id") String channelId);
@Nullable @Query("id") String channelId,
@Nullable @Query("shadow") Boolean shadow);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this param doesn't have any effect. It removes 2 types of bans. @ferhatelmas

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting. I couldn't find it in the REST docs, but Python/Ruby etc has it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see go sdk has it too 🤔. Alright, let's keep it for consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the tests succeed as well, so.. 🤔

}
26 changes: 26 additions & 0 deletions src/test/java/io/getstream/chat/java/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,30 @@ void whenPartiallyUpdatingAMessage_thenIsUpdated() {
.getMessage();
Assertions.assertEquals(updatedText, updatedMessage.getText());
}

@DisplayName("Can pin a message")
@Test
void whenPinningAMessage_thenIsPinned() {
Message message = Assertions.assertDoesNotThrow(() -> sendTestMessage());
Message updatedMessage =
Assertions.assertDoesNotThrow(
() -> Message.pinMessage(message.getId(), testUserRequestObject.getId()).request())
.getMessage();
Assertions.assertTrue(updatedMessage.getPinned());
}

@DisplayName("Can unpin a message")
@Test
void whenUnpinningAMessage_thenIsUnpinned() {
Message message = Assertions.assertDoesNotThrow(() -> sendTestMessage());
Assertions.assertDoesNotThrow(
() -> Message.pinMessage(message.getId(), testUserRequestObject.getId()).request())
.getMessage();
var unPinnedMessage =
Assertions.assertDoesNotThrow(
() ->
Message.unpinMessage(message.getId(), testUserRequestObject.getId()).request())
.getMessage();
Assertions.assertFalse(unPinnedMessage.getPinned());
}
}
33 changes: 33 additions & 0 deletions src/test/java/io/getstream/chat/java/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ void whenBanUser_thenIsBanned() {
Assertions.assertTrue(bans.stream().anyMatch(ban -> ban.getUser().getId().equals(userId)));
}

@DisplayName("Can shadow ban user")
@Test
void whenShadowBanUser_thenIsShadowBanned() {
String userId = RandomStringUtils.randomAlphabetic(10);
UserUpsertRequest usersUpsertRequest = User.upsert();
usersUpsertRequest.user(
UserRequestObject.builder().id(userId).name("User to shadowban").build());
Assertions.assertDoesNotThrow(() -> usersUpsertRequest.request());
Assertions.assertDoesNotThrow(
() ->
User.shadowBan().userId(testUserRequestObject.getId()).targetUserId(userId).request());
List<Ban> bans = Assertions.assertDoesNotThrow(() -> User.queryBanned().request()).getBans();
var banned =
bans.stream().filter(ban -> ban.getUser().getId().equals(userId)).findFirst().get();
Assertions.assertTrue(banned.getShadow());
}

@DisplayName("Can list banned user")
@Test
void whenListingBannedUsers_thenContainsBanned() {
Expand Down Expand Up @@ -235,6 +252,22 @@ void whenUnbanUser_thenIsNotBannedAnymore() {
Assertions.assertFalse(bans.stream().anyMatch(ban -> ban.getUser().getId().equals(userId)));
}

@DisplayName("Can remove a shadow ban")
@Test
void whenRemovingShadowBan_thenIsRemoved() {
String userId = RandomStringUtils.randomAlphabetic(10);
UserUpsertRequest usersUpsertRequest = User.upsert();
usersUpsertRequest.user(
UserRequestObject.builder().id(userId).name("User to shadowban").build());
Assertions.assertDoesNotThrow(() -> usersUpsertRequest.request());
Assertions.assertDoesNotThrow(
() ->
User.shadowBan().userId(testUserRequestObject.getId()).targetUserId(userId).request());
Assertions.assertDoesNotThrow(() -> User.removeShadowBan(userId).request());
List<Ban> bans = Assertions.assertDoesNotThrow(() -> User.queryBanned().request()).getBans();
Assertions.assertFalse(bans.stream().anyMatch(ban -> ban.getUser().getId().equals(userId)));
}

@SuppressWarnings("unchecked")
@DisplayName("Can create a OwnUserRequestObject from OwnUser")
@Test
Expand Down