Skip to content

Commit

Permalink
chore: resolve chat type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Jan 22, 2024
1 parent 27dadfc commit 8d43deb
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Action =
}
| {
type: 'delete_messages' | 'delete_new_messages';
value: { messageIds: number[]; reqIds: string[] };
value: { messageIds: (string | number)[]; reqIds: string[] };
};

type State = {
Expand Down Expand Up @@ -153,7 +153,7 @@ export const useChannelMessagesReducer = (sortComparator?: Options['sortComparat
const updateMessages = (messages: SendbirdBaseMessage[], clearBeforeAction: boolean, currentUserId?: string) => {
dispatch({ type: 'update_messages', value: { messages, clearBeforeAction, currentUserId } });
};
const deleteMessages = (messageIds: number[], reqIds: string[]) => {
const deleteMessages = (messageIds: (string | number)[], reqIds: string[]) => {
dispatch({ type: 'delete_messages', value: { messageIds, reqIds } });
};
const updateNewMessages = (messages: SendbirdBaseMessage[], clearBeforeAction: boolean, currentUserId?: string) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useRef } from 'react';

import type { PreviousMessageListQueryParams } from '@sendbird/chat/message';
import type { BaseMessage, PreviousMessageListQueryParams } from '@sendbird/chat/message';
import type {
SendbirdBaseChannel,
SendbirdGroupChannel,
Expand Down Expand Up @@ -116,7 +116,7 @@ export const useGroupChannelMessagesWithQuery: UseGroupChannelMessages = (sdk, c
channelUrl: channel.url,
channelType: channel.channelType,
});
if (message) updateMessages([message], false, sdk.currentUser?.userId);
if (message) updateMessages([message as BaseMessage], false, sdk.currentUser?.userId);
},
// Channels
onChannelChanged: channelUpdater,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const useOpenChannelMessagesWithQuery: UseOpenChannelMessages = (sdk, cha
const messageContext = {
updatedMessages: [] as SendbirdBaseMessage[],
addedMessages: [] as SendbirdBaseMessage[],
deletedMessageIds: [] as number[],
deletedMessageIds: [] as (number | string)[],
};
const changeLogsContext = {
hasMore: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { Pressable, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

import type { BaseMessage } from '@sendbird/chat/message';
import { useChannelHandler } from '@sendbird/uikit-chat-hooks';
import { Icon, Image, createStyleSheet, useUIKitTheme } from '@sendbird/uikit-react-native-foundation';
import { SendbirdBaseChannel, SendbirdBaseMessage, useUniqHandlerId } from '@sendbird/uikit-utils';
Expand All @@ -24,12 +25,12 @@ const BottomSheetReactionAddon = ({ onClose, message, channel }: Props) => {
useChannelHandler(sdk, handlerId, {
async onReactionUpdated(eventChannel, event) {
if (channel?.url === eventChannel.url && event.messageId === message?.messageId) {
const msg = await sdk.message.getMessage({
const msg = (await sdk.message.getMessage({
includeReactions: true,
messageId: message.messageId,
channelUrl: message.channelUrl,
channelType: message.channelType,
});
})) as null | BaseMessage;
if (msg) updateReactionFocusedItem({ message: msg });
}
},
Expand Down
2 changes: 2 additions & 0 deletions packages/uikit-testing-tools/src/mocks/createMockChannel.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
BannedUserListQuery,
ChannelType,
Expand Down Expand Up @@ -125,6 +126,7 @@ class MockChannel implements GetMockProps<Params, SendbirdBaseChannel & Sendbird
isOperator(): boolean {
throw new Error('Method not implemented.');
}
// @ts-ignore
refresh = jest.fn(async (): Promise<this> => {
this.params.sdk?.__throwIfFailureTest();
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import { ChannelType } from '@sendbird/chat';
import {
GroupChannel,
Expand Down
28 changes: 27 additions & 1 deletion packages/uikit-testing-tools/src/mocks/createMockMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-nocheck
import { ChannelType } from '@sendbird/chat';
import { NotificationData } from '@sendbird/chat/feedChannel';
import { MessageType, SendingStatus } from '@sendbird/chat/message';
import { Form } from '@sendbird/chat/lib/__definition';
import { AdminMessage, Feedback, FeedbackStatus, MessageType, SendingStatus } from '@sendbird/chat/message';
import type {
SendbirdAdminMessage,
SendbirdBaseMessage,
Expand Down Expand Up @@ -67,6 +69,10 @@ class MockMessage implements GetMockProps<Params, SendbirdBaseMessage> {
scheduledInfo = null;
extendedMessage = {};
notificationData: NotificationData | null = null;
forms: Form[] | null = null;
myFeedback: Feedback | null = null;
myFeedbackStatus: FeedbackStatus = 'NO_FEEDBACK';
suggestedReplies: string[] | null = null;

isFileMessage(): this is SendbirdFileMessage {
return this.messageType === MessageType.FILE && !Object.prototype.hasOwnProperty.call(this, 'fileInfoList');
Expand Down Expand Up @@ -109,6 +115,26 @@ class MockMessage implements GetMockProps<Params, SendbirdBaseMessage> {
return Object.assign({}, this);
}

deleteFeedback(_: number): Promise<void> {
return Promise.resolve(undefined);
}

hasForm(): this is AdminMessage {
return this.forms !== null;
}

submitFeedback(_: Pick<Feedback, 'rating' | 'comment'>): Promise<void> {
return Promise.resolve(undefined);
}

submitForm(_: { formId?: string; answers?: Record<string, string> }): Promise<void> {
return Promise.resolve(undefined);
}

updateFeedback(_: Feedback): Promise<void> {
return Promise.resolve(undefined);
}

asFileMessage(): SendbirdFileMessage {
return this as unknown as SendbirdFileMessage;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
MessageCollectionEventHandler,
MessageCollectionInitHandler,
Expand All @@ -6,7 +7,7 @@ import {
MessageCollectionParams,
MessageFilter,
} from '@sendbird/chat/groupChannel';
import { SendingStatus } from '@sendbird/chat/message';
import { BaseMessage, SendingStatus } from '@sendbird/chat/message';
import type {
SendbirdBaseMessage,
SendbirdGroupChannel,
Expand Down Expand Up @@ -57,7 +58,7 @@ class MockMessageCollection implements GetMockProps<Params, Omit<SendbirdMessage
});

initialize = jest.fn((_policy: MessageCollectionInitPolicy) => {
const initHandler: MessageCollectionInitHandler = {
const initHandler: MessageCollectionInitHandler<BaseMessage> = {
onCacheResult: jest.fn((handler: MessageCollectionInitResultHandler) => {
this.__cacheInitHandler = handler;
return initHandler;
Expand Down
1 change: 1 addition & 0 deletions packages/uikit-testing-tools/src/mocks/createMockQuery.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import { ChannelType } from '@sendbird/chat';

import type { GetMockParams } from '../types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import {
ApplicationUserListQueryParams,
ChannelType,
Expand Down
1 change: 1 addition & 0 deletions packages/uikit-testing-tools/src/mocks/createMockUser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import { UserOnlineState } from '@sendbird/chat';
import type { Sender } from '@sendbird/chat/message';
import type {
Expand Down

0 comments on commit 8d43deb

Please sign in to comment.