Skip to content
Merged
Changes from 2 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
48 changes: 48 additions & 0 deletions src/moderation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { normalizeQuerySort } from './utils';
export const MODERATION_ENTITY_TYPES = {
user: 'stream:user',
message: 'stream:chat:v1:message',
userprofile: 'stream:v1:user_profile',
};

// Moderation class provides all the endpoints related to moderation v2.
Expand Down Expand Up @@ -247,6 +248,7 @@ export class Moderation<StreamChatGenerics extends ExtendableGenerics = DefaultG
configKey: string,
options?: {
force_sync?: boolean;
test_mode?: boolean;
},
) {
return await this.client.post(this.client.baseURL + `/api/v2/moderation/check`, {
Expand All @@ -259,6 +261,52 @@ export class Moderation<StreamChatGenerics extends ExtendableGenerics = DefaultG
});
}

/**
* Experimental: Check user profile
*
* Warning: This is an experimental feature and the API is subject to change.
*
* This function is used to check a user profile for moderation.
* This will not create any review queue items for the user profile.
* You can just use this to check weather to allow certain user profile to be created or not.
*
* Example:
*
* ```ts
* const res = await client.moderation.checkUserProfile(userId, { username: "fuck_boy_001", profileImage: "https://example.com/profile.jpg" });
* if (res.recommended_action === "remove") {
* // Block the user profile from being created
* } else {
* // Allow the user profile to be created
* }
* ```
*
* @param userId
* @param username
* @param profileImage
* @returns
*/
async checkUserProfile(userId: string, profile: { profileImage?: string; username?: string } = {}) {
if (!profile.username && !profile.profileImage) {
throw new Error('Either username or profileImage must be provided');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make it partially required for TS users, I'll leave the runtime check for the JS users. :)

Suggested change
async checkUserProfile(userId: string, profile: { profileImage?: string; username?: string } = {}) {
if (!profile.username && !profile.profileImage) {
throw new Error('Either username or profileImage must be provided');
}
async checkUserProfile(userId: string, profile: RequireAtLeastOne<{ profile: string; image: string }>) {
if (!profile.username && !profile.image) {
throw new Error('Either profile.username or profile.image must be provided');
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Also - nit; changed profileImage to image


return await this.check(
MODERATION_ENTITY_TYPES.userprofile,
userId,
userId,
{
texts: [profile.username as string],
images: [profile.profileImage as string],
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
texts: [profile.username as string],
images: [profile.profileImage as string],
texts: [profile.username as string],
images: [profile.profileImage as string],

One of these might become: [undefined] - is that okay?

},
'user_profile:default',
{
force_sync: true,
test_mode: true,
},
);
}

/**
*
* @param {string} entityType string Type of entity to be checked E.g., stream:user, stream:chat:v1:message, or any custom string
Expand Down
Loading