import querystring from 'querystring' import * as Sendbird from './sendbird' import { GetUsersParameters, UserResource, ChannelMember } from './types' export function markAllUserMessagesAsRead({ userId, channelUrls, }: { userId: string channelUrls?: string[] }) { return Sendbird.doPut( `/users/${userId}/mark_as_read_all${ channelUrls && channelUrls.length > 0 ? `?channel_urls=${channelUrls.join(',')}` : '' }`, { channel_urls: channelUrls, } ) } export function createUser({ userId, nickname, profileUrl, }: { userId: string nickname: string profileUrl: string }): Promise { return Sendbird.doPost('/users', { user_id: userId, nickname, profile_url: profileUrl }) } export function getUser(userId: string): Promise { return Sendbird.doGet(`/users/${userId}`) } export function getUsers( args: GetUsersParameters ): Promise<{ users: ChannelMember[]; next: string }> { return Sendbird.doGet( `${Sendbird.SENDBIRD_BASE_URL}/users?${querystring.stringify({ ...args, })}` ) } export function updateUser({ userId, nickname, profileUrl, }: { userId: string nickname: string profileUrl: string }): Promise { return Sendbird.doPut(`/users/${userId}`, { nickname, profile_url: profileUrl, }) } export function deleteUser(userId: string): Promise { return Sendbird.doDelete(`/users/${userId}`) }