From 1293adea79e1df4bfaeb14f427b698c59242d2ee Mon Sep 17 00:00:00 2001 From: dominic Date: Fri, 13 Oct 2023 15:51:15 +0100 Subject: [PATCH] refactor: replace number type with string type --- src/lib/chat/index.ts | 8 ++++---- src/lib/chat/matrix-client.test.ts | 4 ++-- src/lib/chat/matrix-client.ts | 4 ++-- src/lib/chat/sendbird-client.ts | 6 +++--- src/store/messages/saga.ts | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lib/chat/index.ts b/src/lib/chat/index.ts index 6d0b18008..53cf8c7b7 100644 --- a/src/lib/chat/index.ts +++ b/src/lib/chat/index.ts @@ -11,7 +11,7 @@ export interface RealtimeChatEvents { reconnectStart: () => void; reconnectStop: () => void; receiveNewMessage: (channelId: string, message: Message) => void; - receiveDeleteMessage: (channelId: string, messageId: number) => void; + receiveDeleteMessage: (roomId: string, messageId: string) => void; onMessageUpdated: (channelId: string, message: Message) => void; receiveUnreadCount: (channelId: string, unreadCount: number) => void; onUserReceivedInvitation: (channel) => void; @@ -54,7 +54,7 @@ export interface IChatClient { optimisticId?: string ) => Promise; fetchConversationsWithUsers: (users: User[]) => Promise[]>; - deleteMessageByRoomId: (channelId: string, messageId: number) => Promise; + deleteMessageByRoomId: (roomId: string, messageId: string) => Promise; } export class Chat { @@ -90,8 +90,8 @@ export class Chat { return this.client.createConversation(users, name, image, optimisticId); } - async deleteMessageByRoomId(channelId: string, messageId: number): Promise { - return this.client.deleteMessageByRoomId(channelId, messageId); + async deleteMessageByRoomId(roomId: string, messageId: string): Promise { + return this.client.deleteMessageByRoomId(roomId, messageId); } async searchMyNetworksByName(filter: string) { diff --git a/src/lib/chat/matrix-client.test.ts b/src/lib/chat/matrix-client.test.ts index a2c3fecb6..36ecfd962 100644 --- a/src/lib/chat/matrix-client.test.ts +++ b/src/lib/chat/matrix-client.test.ts @@ -513,7 +513,7 @@ describe('matrix client', () => { describe('deleteMessageByRoomId', () => { it('deletes a message by room ID and message ID', async () => { - const messageId = 123456; + const messageId = '123456'; const channelId = '!abcdefg'; const redactEvent = jest.fn().mockResolvedValue({}); @@ -524,7 +524,7 @@ describe('matrix client', () => { await client.connect(null, 'token'); await client.deleteMessageByRoomId(channelId, messageId); - expect(redactEvent).toHaveBeenCalledWith(channelId, messageId.toString()); + expect(redactEvent).toHaveBeenCalledWith(channelId, messageId); }); }); diff --git a/src/lib/chat/matrix-client.ts b/src/lib/chat/matrix-client.ts index 1efa3999c..fa4c31990 100644 --- a/src/lib/chat/matrix-client.ts +++ b/src/lib/chat/matrix-client.ts @@ -208,8 +208,8 @@ export class MatrixClient implements IChatClient { }; } - async deleteMessageByRoomId(channelId: string, messageId: number): Promise { - await this.matrix.redactEvent(channelId, messageId.toString()); + async deleteMessageByRoomId(roomId: string, messageId: string): Promise { + await this.matrix.redactEvent(roomId, messageId); } async fetchConversationsWithUsers(users: User[]) { diff --git a/src/lib/chat/sendbird-client.ts b/src/lib/chat/sendbird-client.ts index c76de04ec..746ed71cc 100644 --- a/src/lib/chat/sendbird-client.ts +++ b/src/lib/chat/sendbird-client.ts @@ -101,9 +101,9 @@ export class SendbirdClient implements IChatClient { return results.map((u) => ({ id: u.id, display: u.name, profileImage: u.profileImage })); } - async deleteMessageByRoomId(channelId: string, messageId: number): Promise { + async deleteMessageByRoomId(roomId: string, messageId: string): Promise { try { - await del(`/chatChannels/${channelId}/message`).send({ message: { id: messageId } }); + await del(`/chatChannels/${roomId}/message`).send({ message: { id: messageId } }); } catch (error: any) { console.log('Error occurred while deleting message', error?.response ?? error); } @@ -219,7 +219,7 @@ export class SendbirdClient implements IChatClient { onMessageDeleted: (channel, messageId) => { const channelId = this.getChannelId(channel); - events.receiveDeleteMessage(channelId, messageId); + events.receiveDeleteMessage(channelId, messageId.toString()); }, onChannelChanged: (channel) => { const channelId = this.getChannelId(channel); diff --git a/src/store/messages/saga.ts b/src/store/messages/saga.ts index fb048d77f..7abcac180 100644 --- a/src/store/messages/saga.ts +++ b/src/store/messages/saga.ts @@ -326,7 +326,7 @@ export function* deleteMessage(action) { const existingMessageIds = yield select(rawMessagesSelector(channelId)); const fullMessages = yield select((state) => denormalize(existingMessageIds, state)); - const messageIdsToDelete = fullMessages.filter((m) => m.rootMessageId === messageId.toString()).map((m) => m.id); // toString() because message ids are currently a number + const messageIdsToDelete = fullMessages.filter((m) => m.rootMessageId === messageId).map((m) => m.id); messageIdsToDelete.unshift(messageId); yield put(