Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement fetch unban requests via graphql #525

Merged
merged 1 commit into from Feb 10, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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()
);
}

}