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

fix: remove nin and ne operator usage in the SDK and the sample app #2672

Merged
merged 9 commits into from
Sep 18, 2024
25 changes: 7 additions & 18 deletions examples/SampleApp/src/hooks/usePaginatedUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ export const usePaginatedUsers = (): PaginatedUsers => {
try {
queryInProgress.current = true;
const filter: UserFilters = {
id: {
$nin: [chatClient?.userID],
},
role: 'user',
};

Expand All @@ -143,7 +140,7 @@ export const usePaginatedUsers = (): PaginatedUsers => {
return;
}

const res = await chatClient?.queryUsers(
const { users } = await chatClient?.queryUsers(
filter,
{ name: 1 },
{
Expand All @@ -153,33 +150,25 @@ export const usePaginatedUsers = (): PaginatedUsers => {
},
);

if (!res?.users) {
queryInProgress.current = false;
return;
}

// Dumb check to avoid duplicates
if (query === searchText && results.findIndex((r) => res?.users[0].id === r.id) > -1) {
queryInProgress.current = false;
return;
}
const usersWithoutClientUserId = users.filter((user) => user.id !== chatClient.userID);

setResults((r) => {
if (query !== searchText) {
return res?.users;
return usersWithoutClientUserId;
}
return r.concat(res?.users || []);
return r.concat(usersWithoutClientUserId);
});

if (res?.users.length < 10 && (offset.current === 0 || query === searchText)) {
if (usersWithoutClientUserId.length < 10 && (offset.current === 0 || query === searchText)) {
hasMoreResults.current = false;
}

if (!query && offset.current === 0) {
setInitialResults(res?.users || []);
setInitialResults(usersWithoutClientUserId);
}
} catch (e) {
// do nothing;
console.log('Error fetching users', e);
}
queryInProgress.current = false;
setLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ import {
} from '../../contexts/translationContext/TranslationContext';
import type { Emoji } from '../../emoji-data';
import type { DefaultStreamChatGenerics } from '../../types/types';
import { isCommandTrigger, isEmojiTrigger, isMentionTrigger } from '../../utils/utils';

import type { Trigger } from '../../utils/utils';
import {
isCommandTrigger,
isEmojiTrigger,
isMentionTrigger,
Trigger,
} from '../../utils/ACITriggerSettings';

const styles = StyleSheet.create({
inputBox: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useMockedApis } from '../../../mock-builders/api/useMockedApis';
import { generateChannelResponse } from '../../../mock-builders/generator/channel';
import { generateUser } from '../../../mock-builders/generator/user';
import { getTestClientWithUser } from '../../../mock-builders/mock';
import { ACITriggerSettings } from '../../../utils/utils';
import { ACITriggerSettings } from '../../../utils/ACITriggerSettings';
import { Chat } from '../../Chat/Chat';
import { AutoCompleteInput } from '../AutoCompleteInput';

Expand Down
47 changes: 27 additions & 20 deletions package/src/contexts/messageInputContext/MessageInputContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,19 @@ import {
ImageUpload,
UnknownType,
} from '../../types/types';
import { compressedImageURI } from '../../utils/compressImage';
import { removeReservedFields } from '../../utils/removeReservedFields';
import {
ACITriggerSettings,
ACITriggerSettingsParams,
TriggerSettings,
} from '../../utils/ACITriggerSettings';
import { compressedImageURI } from '../../utils/compressImage';
import { removeReservedFields } from '../../utils/removeReservedFields';
import {
FileState,
FileStateValue,
generateRandomId,
getFileNameFromPath,
isBouncedMessage,
TriggerSettings,
} from '../../utils/utils';
import { useAttachmentPickerContext } from '../attachmentPickerContext/AttachmentPickerContext';
import { ChannelContextValue, useChannelContext } from '../channelContext/ChannelContext';
Expand Down Expand Up @@ -1073,25 +1075,30 @@ export const MessageInputProvider = <
};

const getTriggerSettings = () => {
let triggerSettings: TriggerSettings<StreamChatGenerics> = {};
if (channel) {
if (value.autoCompleteTriggerSettings) {
triggerSettings = value.autoCompleteTriggerSettings({
channel,
client,
emojiSearchIndex: value.emojiSearchIndex,
onMentionSelectItem: onSelectItem,
});
} else {
triggerSettings = ACITriggerSettings<StreamChatGenerics>({
channel,
client,
emojiSearchIndex: value.emojiSearchIndex,
onMentionSelectItem: onSelectItem,
});
try {
let triggerSettings: TriggerSettings<StreamChatGenerics> = {};
if (channel) {
if (value.autoCompleteTriggerSettings) {
triggerSettings = value.autoCompleteTriggerSettings({
channel,
client,
emojiSearchIndex: value.emojiSearchIndex,
onMentionSelectItem: onSelectItem,
});
} else {
triggerSettings = ACITriggerSettings<StreamChatGenerics>({
channel,
client,
emojiSearchIndex: value.emojiSearchIndex,
onMentionSelectItem: onSelectItem,
});
}
}
return triggerSettings;
} catch (error) {
console.warn('Error in getting trigger settings', error);
throw error;
}
return triggerSettings;
};

const triggerSettings = getTriggerSettings();
Expand Down
3 changes: 3 additions & 0 deletions package/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ export * from './icons';

export * from './types/types';

export * from './utils/ACITriggerSettings';
export * from './utils/patchMessageTextCommand';
export * from './utils/i18n/Streami18n';
export * from './utils/queryMembers';
export * from './utils/queryUsers';
export * from './utils/utils';
export * from './utils/StreamChatRN';

Expand Down
Loading
Loading