Skip to content

Commit

Permalink
Merge pull request #87 from bevzaanton/feature/ban_user
Browse files Browse the repository at this point in the history
Add ban/unban user
  • Loading branch information
tbarbugli committed Oct 3, 2019
2 parents d9c0c5d + b00d26b commit 4e5fa5d
Show file tree
Hide file tree
Showing 9 changed files with 390 additions and 173 deletions.
29 changes: 26 additions & 3 deletions library/src/main/java/com/getstream/sdk/chat/model/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.getstream.sdk.chat.rest.interfaces.QueryChannelCallback;
import com.getstream.sdk.chat.rest.interfaces.QueryWatchCallback;
import com.getstream.sdk.chat.rest.interfaces.SendFileCallback;
import com.getstream.sdk.chat.rest.interfaces.ShowHideChannelCallback;
import com.getstream.sdk.chat.rest.interfaces.CompletableCallback;
import com.getstream.sdk.chat.rest.request.ChannelQueryRequest;
import com.getstream.sdk.chat.rest.request.ChannelWatchRequest;
import com.getstream.sdk.chat.rest.request.MarkReadRequest;
Expand Down Expand Up @@ -757,6 +757,29 @@ public void onError(String errMsg, int errCode) {
});
}

/**
* bans a user from this channel
*
* @param targetUserId the ID of the user to ban
* @param reason the reason the ban was created
* @param timeout the timeout in minutes until the ban is automatically expired
* @param callback the result callback
*/
public void banUser(@NotNull String targetUserId, @Nullable String reason, @Nullable Integer timeout,
@NotNull CompletableCallback callback) {
client.banUser(targetUserId, this, reason, timeout, callback);
}

/**
* removes the ban for a user on this channel
*
* @param targetUserId the ID of the user to remove the ban
* @param callback the result callback
*/
public void unBanUser(@NotNull String targetUserId, @NotNull CompletableCallback callback) {
client.unBanUser(targetUserId, this, callback);
}

public void handleChannelUpdated(Channel channel) {
extraData = channel.extraData;
getClient().storage().insertChannel(channel);
Expand Down Expand Up @@ -852,7 +875,7 @@ public void onError(String errMsg, int errCode) {
*
* @param callback the result callback
*/
public void hide(@NotNull ShowHideChannelCallback callback) {
public void hide(@NotNull CompletableCallback callback) {
client.hideChannel(this, callback);
}

Expand All @@ -861,7 +884,7 @@ public void hide(@NotNull ShowHideChannelCallback callback) {
*
* @param callback the result callback
*/
public void show(@NotNull ShowHideChannelCallback callback) {
public void show(@NotNull CompletableCallback callback) {
client.showChannel(this, callback);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.getstream.sdk.chat.rest.controller;

import com.getstream.sdk.chat.rest.request.AddDeviceRequest;
import com.getstream.sdk.chat.rest.request.BanUserRequest;
import com.getstream.sdk.chat.rest.request.ChannelQueryRequest;
import com.getstream.sdk.chat.rest.request.MarkReadRequest;
import com.getstream.sdk.chat.rest.request.ReactionRequest;
Expand All @@ -18,7 +19,7 @@
import com.getstream.sdk.chat.rest.response.MuteUserResponse;
import com.getstream.sdk.chat.rest.response.QueryChannelsResponse;
import com.getstream.sdk.chat.rest.response.QueryUserListResponse;
import com.getstream.sdk.chat.rest.response.ShowHideChannelResponse;
import com.getstream.sdk.chat.rest.response.CompletableResponse;

import org.json.JSONObject;

Expand Down Expand Up @@ -59,10 +60,10 @@ public interface APIService {
Call<ChannelState> rejectInvite(@Path("type") String channelType, @Path("id") String channelId, @Query("api_key") String apiKey, @Query("user_id") String userId, @Query("client_id") String clientID, @Body Map<String, Object> body);

@POST("/channels/{type}/{id}/show")
Call<ShowHideChannelResponse> showChannel(@Path("type") String channelType, @Path("id") String channelId, @Query("api_key") String apiKey, @Query("client_id") String clientID, @Body Map body);
Call<CompletableResponse> showChannel(@Path("type") String channelType, @Path("id") String channelId, @Query("api_key") String apiKey, @Query("client_id") String clientID, @Body Map body);

@POST("/channels/{type}/{id}/hide")
Call<ShowHideChannelResponse> hideChannel(@Path("type") String channelType, @Path("id") String channelId, @Query("api_key") String apiKey, @Query("client_id") String clientID, @Body Map body);
Call<CompletableResponse> hideChannel(@Path("type") String channelType, @Path("id") String channelId, @Query("api_key") String apiKey, @Query("client_id") String clientID, @Body Map body);
// endregion

// region User
Expand All @@ -83,6 +84,12 @@ public interface APIService {

@POST("/moderation/unflag")
Call<FlagResponse> unFlag(@Query("api_key") String apiKey, @Query("user_id") String userId, @Query("client_id") String connectionId, @Body Map<String, String> body);

@POST("/moderation/ban")
Call<CompletableResponse> banUser(@Query("api_key") String apiKey, @Query("client_id") String connectionId, @Body BanUserRequest body);

@DELETE("/moderation/ban")
Call<CompletableResponse> unBanUser(@Query("api_key") String apiKey, @Query("client_id") String connectionId, @Query("target_user_id") String targetUserId, @Query("type") String channelType, @Query("id") String channelId);
// endregion

// region Message
Expand Down
Loading

0 comments on commit 4e5fa5d

Please sign in to comment.