Skip to content

Commit

Permalink
feat: add gql fetch unban requests (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy committed Feb 10, 2022
1 parent 0b75072 commit 94dca2b
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
@@ -0,0 +1,37 @@
query fetchUnbanRequests($channelLogin: String!, $after: Cursor, $first: Int = 25, $order: UnbanRequestsSortOrder = NEWEST, $status: UnbanRequestStatus = PENDING, $userId: ID) {
channel(name: $channelLogin) {
id
unbanRequests(after: $after, first: $first, options: {order: $order, status: $status, userID: $userId}) {
edges {
cursor
node {
createdAt
id
requester {
id
login
displayName
profileImageURL(width: 50)
}
requesterMessage
resolvedAt
resolvedBy {
id
login
displayName
}
resolverMessage
status
}
}
pageInfo {
hasNextPage
}
totalCount(status: $status)
}
unbanRequestsSettings {
cooldownMinutes
isEnabled
}
}
}
Expand Up @@ -13,6 +13,8 @@
import com.github.twitch4j.graphql.internal.type.CreateCommunityPointsCommunityGoalInput;
import com.github.twitch4j.graphql.internal.type.CreatePollInput;
import com.github.twitch4j.graphql.internal.type.CreatePredictionEventInput;
import com.github.twitch4j.graphql.internal.type.UnbanRequestStatus;
import com.github.twitch4j.graphql.internal.type.UnbanRequestsSortOrder;
import com.github.twitch4j.graphql.internal.type.UpdateCommunityPointsCommunityGoalInput;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
Expand Down Expand Up @@ -289,6 +291,10 @@ public CommandDenyUnbanRequest denyUnbanRequest(OAuth2Credential auth, String id
return new CommandDenyUnbanRequest(getApolloClient(auth), id, message);
}

public CommandFetchUnbanRequests fetchUnbanRequests(OAuth2Credential auth, String channelLogin, String cursor, Integer limit, UnbanRequestsSortOrder order, UnbanRequestStatus status, String userId) {
return new CommandFetchUnbanRequests(getApolloClient(auth), channelLogin, cursor, limit, order, status, userId);
}

@Deprecated
public CommandBanUser banUser(OAuth2Credential auth, String channelId, String targetUserLogin, String reason) {
return new CommandBanUser(getApolloClient(auth), channelId, targetUserLogin, reason);
Expand Down
@@ -0,0 +1,55 @@
package com.github.twitch4j.graphql.command;

import com.apollographql.apollo.ApolloCall;
import com.apollographql.apollo.ApolloClient;
import com.github.twitch4j.graphql.internal.FetchUnbanRequestsQuery;
import com.github.twitch4j.graphql.internal.type.UnbanRequestStatus;
import com.github.twitch4j.graphql.internal.type.UnbanRequestsSortOrder;
import lombok.NonNull;
import org.jetbrains.annotations.Nullable;

public class CommandFetchUnbanRequests extends BaseCommand<FetchUnbanRequestsQuery.Data> {

private final String channelLogin;
private final String cursor;
private final Integer limit;
private final UnbanRequestsSortOrder order;
private final UnbanRequestStatus status;
private final String userId;

/**
* Constructor
*
* @param apolloClient Required: Apollo Client
* @param channelLogin Required: The name of the channel where the ban took place
* @param cursor Optional: Cursor for forward pagination
* @param limit Optional: The number of elements to request in a single query (default: 25)
* @param order Optional: Whether unban requests should be returned by most recent or oldest (default: NEWEST)
* @param status Optional: The status of unban requests to query from (default: PENDING)
* @param userId Optional: Whether the unban request of a specific user should be queried
*/
public CommandFetchUnbanRequests(@NonNull ApolloClient apolloClient, @NonNull String channelLogin, @Nullable String cursor, @Nullable Integer limit, @Nullable UnbanRequestsSortOrder order, @Nullable UnbanRequestStatus status, @Nullable String userId) {
super(apolloClient);
this.channelLogin = channelLogin;
this.cursor = cursor;
this.limit = limit;
this.order = order == null ? UnbanRequestsSortOrder.NEWEST : order;
this.status = status == null ? UnbanRequestStatus.PENDING : status;
this.userId = userId;
}

@Override
protected ApolloCall<FetchUnbanRequestsQuery.Data> getGraphQLCall() {
return apolloClient.query(
FetchUnbanRequestsQuery.builder()
.channelLogin(channelLogin)
.after(cursor)
.first(limit)
.order(order)
.status(status)
.userId(userId)
.build()
);
}

}

0 comments on commit 94dca2b

Please sign in to comment.