Skip to content

Commit

Permalink
fix: chat.info changes (#1163)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 authored Mar 13, 2024
1 parent 59f4c77 commit b16b842
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
18 changes: 12 additions & 6 deletions packages/restapi/src/lib/chat/getChatInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getAPIBaseUrls } from '../helpers';
import Constants, { ENV } from '../constants';
import { axiosGet } from '../utils/axiosUtil';
import { handleError } from '../errors/ValidationError';
import { getUserDID } from './helpers';

/**
* Represents the response type for the chat status.
Expand All @@ -11,14 +12,16 @@ export interface ChatInfoResponse {
group: boolean;
};
list: string;
participants: string[];
chatId: string
}

/**
* Represents the input type for fetching chat status.
*/
export interface GetChatInfoType {
chatId: string;
address: string; // Ethereum address or similar
receipient: string;
sender: string; // Ethereum address or similar
env?: ENV;
}

Expand All @@ -28,15 +31,18 @@ export interface GetChatInfoType {
export const getChatInfo = async (
options: GetChatInfoType
): Promise<ChatInfoResponse> => {
const { chatId, address, env = Constants.ENV.PROD } = options;
const { receipient, sender, env = Constants.ENV.PROD } = options;

try {
if (!chatId || !address) {
throw new Error('chatId and address cannot be null or empty');
if (!receipient || !sender) {
throw new Error('receipient and sender cannot be null or empty');
}

const API_BASE_URL = getAPIBaseUrls(env);
const requestUrl = `${API_BASE_URL}/v1/chat/${chatId}/address/${address}`;
const requestUrl = `${API_BASE_URL}/v1/chat/${await getUserDID(
receipient,
env
)}/address/${await getUserDID(sender, env)}`;
const response = await axiosGet<ChatInfoResponse>(requestUrl);
return response.data;
} catch (err) {
Expand Down
6 changes: 3 additions & 3 deletions packages/restapi/src/lib/pushapi/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ export class Chat {
});
}

async info(chatId: string, address: string): Promise<ChatInfoResponse> {
async info(receipient: string): Promise<ChatInfoResponse> {
const options: PUSH_CHAT.GetChatInfoType = {
chatId: chatId,
address: address,
receipient: receipient,
sender: this.account,
env: this.env,
};

Expand Down

0 comments on commit b16b842

Please sign in to comment.