Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions examples/SampleApp/src/utils/DraftsManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { DraftFilters, DraftResponse, DraftSort, Pager, StateStore, StreamChat } from 'stream-chat';
import { DraftFilters, DraftResponse, SortParamRequest, StateStore, StreamChat } from 'stream-chat';

import { WithSubscriptions } from './WithSubscription';

export type QueryDraftOptions = Pager & {
export type QueryDraftOptions = {
limit?: number;
next?: string;
prev?: string;
filter?: DraftFilters;
sort?: DraftSort;
sort?: SortParamRequest[];
user_id?: string;
};

Expand Down
4 changes: 2 additions & 2 deletions package/src/__tests__/offline-support/offline-feature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
Channel as ChannelLLC,
ChannelFilters,
ChannelMemberResponse,
ChannelSort,
SortParamRequest,
Event,
LocalMessage,
MessageResponse,
Expand Down Expand Up @@ -255,7 +255,7 @@ export const Generic = () => {
foo: 'bar',
type: 'messaging',
} as ChannelFilters;
const sort: ChannelSort = [{ direction: 1, field: 'last_updated' }];
const sort: SortParamRequest[] = [{ direction: 1, field: 'last_updated' }];

const renderComponent = async () => {
const result = render(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from 'react';
import { StyleSheet, View } from 'react-native';

import { CommandVariants } from 'stream-chat';

import { useComponentsContext } from '../../contexts/componentsContext/ComponentsContext';
import { useTheme } from '../../contexts/themeContext/ThemeContext';

export const SuggestionCommandIcon = ({ name }: { name: CommandVariants }) => {
export const SuggestionCommandIcon = ({ name }: { name: string }) => {
const {
theme: { semantics },
} = useTheme();
Expand All @@ -31,7 +29,7 @@ export const SuggestionCommandIcon = ({ name }: { name: CommandVariants }) => {
}
};

export const AutoCompleteSuggestionCommandIcon = ({ name }: { name: CommandVariants }) => {
export const AutoCompleteSuggestionCommandIcon = ({ name }: { name: string }) => {
const {
theme: {
messageComposer: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React, { useCallback, useMemo } from 'react';
import { Pressable, StyleSheet, Text, View } from 'react-native';

import type {
CommandSuggestion,
CommandVariants,
MentionSuggestion,
TextComposerSuggestion,
} from 'stream-chat';
import type { CommandSuggestion, MentionSuggestion, TextComposerSuggestion } from 'stream-chat';

import { AutoCompleteSuggestionCommandIcon } from './AutoCompleteSuggestionCommandIcon';
import {
Expand Down Expand Up @@ -93,7 +88,7 @@ export const CommandSuggestionItem = (item: CommandSuggestion) => {

return (
<View style={[styles.commandContainer, commandContainer]}>
{name ? <AutoCompleteSuggestionCommandIcon name={name as CommandVariants} /> : null}
{name ? <AutoCompleteSuggestionCommandIcon name={name} /> : null}
<Text
style={[
styles.title,
Expand Down
2 changes: 1 addition & 1 deletion package/src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
/**
* Overrides the Stream default update message request (Advanced usage only)
* @param channelId
* @param updatedMessage UpdatedMessage object
* @param updatedMessage The update-message request payload
*/
doUpdateMessageRequest?: (
channelId: string,
Expand Down
6 changes: 3 additions & 3 deletions package/src/components/ChannelList/ChannelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react';
import { StyleSheet, View } from 'react-native';
import type { FlatList } from 'react-native-gesture-handler';

import { Channel, ChannelFilters, ChannelOptions, ChannelSort } from 'stream-chat';
import { Channel, ChannelFilters, ChannelOptions, SortParamRequest } from 'stream-chat';

import { ChannelListView } from './ChannelListView';
import { useCreateChannelsContext } from './hooks/useCreateChannelsContext';
Expand Down Expand Up @@ -61,7 +61,7 @@ export type ChannelListProps = Partial<
* Object containing channel sort parameters
* @see See [Channel query documentation](https://getstream.io/chat/docs/query_channels) for a list of available sorting fields
* */
sort?: ChannelSort;
sort?: SortParamRequest[];

/**
* A custom request implementation for this list's `ChannelPaginator` (its `doRequest`). Use it to
Expand All @@ -77,7 +77,7 @@ export type ChannelListProps = Partial<

const DEFAULT_FILTERS = {};
const DEFAULT_OPTIONS = {};
const DEFAULT_SORT: ChannelSort = [];
const DEFAULT_SORT: SortParamRequest[] = [];

/**
* This component fetches a list of channels, allowing you to select the channel you want to open.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ChannelPaginator,
ChannelPaginatorState,
ChannelQueryShape,
ChannelSort,
SortParamRequest,
PaginatorOptions,
} from 'stream-chat';

Expand All @@ -31,7 +31,7 @@ export type ChannelListQueryChannelsOverride = PaginatorOptions<
type Parameters = {
filters: ChannelFilters;
options: ChannelOptions;
sort: ChannelSort;
sort: SortParamRequest[];
lockChannelOrder?: boolean;
queryChannelsOverride?: ChannelListQueryChannelsOverride;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const useMessageActionHandlers = ({

try {
if (isMuted) {
await client.unmuteUser(message.user.id);
await client.moderation.unmute({ target_ids: [message.user.id] });
addNotification({
message: t('message.userUnmuted.text', '{{ user }} has been unmuted', {
user: message.user?.name || message.user?.id,
Expand All @@ -179,7 +179,7 @@ export const useMessageActionHandlers = ({
origin: { context: { message }, emitter: 'MessageActions' },
});
} else {
await client.muteUser(message.user.id);
await client.moderation.mute({ target_ids: [message.user.id] });
addNotification({
message: t('message.userMuted.text', '{{ user }} has been muted', {
user: message.user?.name || message.user?.id,
Expand Down Expand Up @@ -215,7 +215,7 @@ export const useMessageActionHandlers = ({
if (messageUser.banned) {
await client.unbanUser(messageUser.id);
} else {
await client.banUser(messageUser.id);
await client.moderation.ban({ target_user_id: messageUser.id });
}
});

Expand Down Expand Up @@ -274,7 +274,7 @@ export const useMessageActionHandlers = ({
{
onPress: async () => {
try {
await client.flagMessage(message.id);
await client.moderation.flagMessage(message.id);
addNotification({
message: t('message.flagged.text', 'Message has been successfully flagged'),
options: { severity: 'success', type: 'api:message:flag:success' },
Expand Down
4 changes: 2 additions & 2 deletions package/src/components/MessageMenu/MessageUserReactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FlatList } from 'react-native-gesture-handler';

import Animated, { FadeIn, FadeOut } from 'react-native-reanimated';

import { ReactionSort } from 'stream-chat';
import { SortParamRequest } from 'stream-chat';

import { EmojiPickerList } from './EmojiPickerList';
import { useFetchReactions } from './hooks/useFetchReactions';
Expand Down Expand Up @@ -51,7 +51,7 @@ export type MessageUserReactionsProps = Partial<Pick<MessagesContextValue, 'supp
selectedReaction?: string;
};

const sort: ReactionSort = [{ direction: -1, field: 'created_at' }];
const sort: SortParamRequest[] = [{ direction: -1, field: 'created_at' }];

export type ReactionSelectorItemType = ReactionData & {
onSelectReaction: (type: string) => void;
Expand Down
4 changes: 2 additions & 2 deletions package/src/components/MessageMenu/hooks/useFetchReactions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useState } from 'react';

import { LocalMessage, ReactionResponse, ReactionSort } from 'stream-chat';
import { LocalMessage, ReactionResponse, SortParamRequest } from 'stream-chat';

import { useChatContext } from '../../../contexts/chatContext/ChatContext';
import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext';
Expand All @@ -10,7 +10,7 @@ export type UseFetchReactionParams = {
limit?: number;
message?: LocalMessage;
reactionType?: string;
sort?: ReactionSort;
sort?: SortParamRequest[];
};

const isSameReaction = (left: ReactionResponse, right: ReactionResponse) =>
Expand Down
5 changes: 2 additions & 3 deletions package/src/components/Poll/hooks/usePollState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useCallback } from 'react';

import {
APIResponse,
PollOptionData,
PollOptionResponseData,
PollResponse,
Expand Down Expand Up @@ -37,9 +36,9 @@ export type UsePollStateSelectorReturnType = {
};

export type UsePollStateReturnType = UsePollStateSelectorReturnType & {
addComment: (answerText: string) => Promise<APIResponse & PollVoteResponse>;
addComment: (answerText: string) => Promise<PollVoteResponse>;
addOption: (optionText: string) => Promise<void>;
endVote: () => Promise<APIResponse & PollResponse>;
endVote: () => Promise<PollResponse>;
};

const selector = (nextValue: PollState): UsePollStateSelectorReturnType => ({
Expand Down
7 changes: 3 additions & 4 deletions package/src/hooks/actions/__tests__/useUserActions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ describe('useUserActions', () => {
({
client: {
blockUser,
muteUser,
moderation: { mute: muteUser, unmute: unmuteUser },
unBlockUser,
unmuteUser,
},
}) as unknown as ChatContext.ChatContextValue,
);
Expand Down Expand Up @@ -75,7 +74,7 @@ describe('useUserActions', () => {

await result.current.muteUser({ onSuccess });

expect(muteUser).toHaveBeenCalledWith('target-user-id');
expect(muteUser).toHaveBeenCalledWith({ target_ids: ['target-user-id'] });
expect(onSuccess).toHaveBeenCalledTimes(1);
expect(addNotification).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down Expand Up @@ -119,7 +118,7 @@ describe('useUserActions', () => {

await result.current.unmuteUser({ onSuccess });

expect(unmuteUser).toHaveBeenCalledWith('target-user-id');
expect(unmuteUser).toHaveBeenCalledWith({ target_ids: ['target-user-id'] });
expect(onSuccess).toHaveBeenCalledTimes(1);
expect(addNotification).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down
4 changes: 2 additions & 2 deletions package/src/hooks/actions/useChannelActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export const useChannelActions = (channel: Channel) => {

try {
if (otherUser?.user?.id) {
await client.muteUser(otherUser.user.id);
await client.moderation.mute({ target_ids: [otherUser.user.id] });
addNotification({
message: t('message.userMuted.text', '{{ user }} has been muted', {
user: otherUser.user.name || otherUser.user.id,
Expand Down Expand Up @@ -329,7 +329,7 @@ export const useChannelActions = (channel: Channel) => {

try {
if (otherUser?.user?.id) {
await client.unmuteUser(otherUser.user.id);
await client.moderation.unmute({ target_ids: [otherUser.user.id] });
addNotification({
message: t('message.userUnmuted.text', '{{ user }} has been unmuted', {
user: otherUser.user.name || otherUser.user.id,
Expand Down
4 changes: 2 additions & 2 deletions package/src/hooks/actions/useUserActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useUserActions = (user: UserResponse | undefined): UserActions => {
}

try {
await client.muteUser(user.id);
await client.moderation.mute({ target_ids: [user.id] });
addNotification({
message: t('message.userMuted.text', '{{ user }} has been muted', {
user: user.name || user.id,
Expand Down Expand Up @@ -59,7 +59,7 @@ export const useUserActions = (user: UserResponse | undefined): UserActions => {
}

try {
await client.unmuteUser(user.id);
await client.moderation.unmute({ target_ids: [user.id] });
addNotification({
message: t('message.userUnmuted.text', '{{ user }} has been unmuted', {
user: user.name || user.id,
Expand Down
11 changes: 5 additions & 6 deletions package/src/hooks/messagePreview/useMessagePreviewText.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dayjs from 'dayjs';
import {
DraftMessage,
LiveLocationPayload,
SharedLocation,
LocalMessage,
MessageResponse,
PollState,
Expand Down Expand Up @@ -46,11 +46,10 @@ export const useMessagePreviewText = ({
}

if (message?.shared_location) {
if (
// There is a problem with types in Draft Message, and its not able to infer the type of `end_at` correctly, so the `as` is used.
(message?.shared_location as LiveLocationPayload)?.end_at &&
new Date((message?.shared_location as LiveLocationPayload)?.end_at) > new Date()
) {
// Draft messages type `shared_location` loosely, hence the cast. `end_at` is optional
// because a static location has no expiry — only a live one does.
const { end_at: endAt } = message.shared_location as SharedLocation;
if (endAt && new Date(endAt) > new Date()) {
return t('messagePreview.liveLocation.label', 'Live Location');
}
return t('messagePreview.location.label', 'Location');
Expand Down
6 changes: 3 additions & 3 deletions package/src/mock-builders/api/channelMocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const CHANNEL_WITH_MESSAGES_TEXT = {
deleted_at: new Date('2021-02-12T12:12:35.862Z'),
id: 'ljkblk',
text: 'jkbkbiubicbi',
type: 'MessageLabel',
type: 'regular',
user: mockUser({ id: 'okechukwu' }),
}),
mockMessage({
Expand All @@ -50,7 +50,7 @@ const CHANNEL_WITH_MESSAGES_TEXT = {
deleted_at: new Date('2021-02-12T12:12:35.862Z'),
id: 'jbkjb',
text: 'jkbkbiubicbi',
type: 'MessageLabel',
type: 'regular',
user: mockUser({ id: 'okechukwu' }),
}),
],
Expand Down Expand Up @@ -149,7 +149,7 @@ const LATEST_MESSAGE = mockMessage({
deleted_at: new Date('2021-02-12T12:12:35.862Z'),
id: 'string',
text: 'jkbkbiubicbi',
type: 'MessageLabel',
type: 'regular',
user: mockUser({ id: 'okechukwu' }),
});

Expand Down
4 changes: 2 additions & 2 deletions package/src/mock-builders/generator/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const defaultCapabilities: ChannelOwnCapability[] = [
];

const defaultConfig = {
automod: 'disabled',
automod_behavior: 'flag',
automod: 'disabled' as const,
automod_behavior: 'flag' as const,
commands: [
{
args: '[text]',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, renderHook } from '@testing-library/react-native';

import type { Channel, ChannelData } from 'stream-chat';
import type { Channel, ChannelInput } from 'stream-chat';

import { generateChannelResponse } from '../../mock-builders/generator/channel';
import { getTestClientWithUser } from '../../mock-builders/mock';
Expand All @@ -26,7 +26,7 @@ const createChannel = async (data: { image?: string; name?: string } = {}) => {
return client.channel(
'messaging',
response.channel.id,
response.channel as unknown as ChannelData,
response.channel as unknown as ChannelInput,
) as Channel;
};

Expand Down
4 changes: 2 additions & 2 deletions package/src/store/apis/getChannelsForFilterSort.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
ChannelFilters,
ChannelOptions,
ChannelSort,
SortParamRequest,
ChannelStateResponseFields,
} from 'stream-chat';

Expand Down Expand Up @@ -29,7 +29,7 @@ export const getChannelsForFilterSort = async ({
currentUserId: string;
filters?: ChannelFilters;
options?: ChannelOptions;
sort?: ChannelSort;
sort?: SortParamRequest[];
}): Promise<Omit<ChannelStateResponseFields, 'duration'>[] | null> => {
if (!filters && !sort && !options?.predefined_filter) {
console.warn(
Expand Down
Loading
Loading