Skip to content

Commit

Permalink
refactor: replace number type with string type
Browse files Browse the repository at this point in the history
  • Loading branch information
domw30 committed Oct 13, 2023
1 parent 24c1b12 commit 1293ade
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/lib/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,7 +54,7 @@ export interface IChatClient {
optimisticId?: string
) => Promise<MessagesResponse>;
fetchConversationsWithUsers: (users: User[]) => Promise<Partial<Channel>[]>;
deleteMessageByRoomId: (channelId: string, messageId: number) => Promise<any>;
deleteMessageByRoomId: (roomId: string, messageId: string) => Promise<void>;
}

export class Chat {
Expand Down Expand Up @@ -90,8 +90,8 @@ export class Chat {
return this.client.createConversation(users, name, image, optimisticId);
}

async deleteMessageByRoomId(channelId: string, messageId: number): Promise<any> {
return this.client.deleteMessageByRoomId(channelId, messageId);
async deleteMessageByRoomId(roomId: string, messageId: string): Promise<void> {
return this.client.deleteMessageByRoomId(roomId, messageId);
}

async searchMyNetworksByName(filter: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/chat/matrix-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({});

Expand All @@ -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);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/lib/chat/matrix-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ export class MatrixClient implements IChatClient {
};
}

async deleteMessageByRoomId(channelId: string, messageId: number): Promise<any> {
await this.matrix.redactEvent(channelId, messageId.toString());
async deleteMessageByRoomId(roomId: string, messageId: string): Promise<void> {
await this.matrix.redactEvent(roomId, messageId);
}

async fetchConversationsWithUsers(users: User[]) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/chat/sendbird-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
async deleteMessageByRoomId(roomId: string, messageId: string): Promise<void> {
try {
await del<any>(`/chatChannels/${channelId}/message`).send({ message: { id: messageId } });
await del<any>(`/chatChannels/${roomId}/message`).send({ message: { id: messageId } });
} catch (error: any) {
console.log('Error occurred while deleting message', error?.response ?? error);
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/store/messages/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1293ade

Please sign in to comment.