-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: optimization fixes * fix: minor issues --------- Co-authored-by: aman035 <[email protected]>
- Loading branch information
1 parent
c4766c6
commit 3175ff3
Showing
10 changed files
with
180 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/restapi/src/lib/chat/getAllGroupMembersPublicKeys.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { getChatMemberCount } from './getChatMemberCount'; | ||
import { EnvOptionsType } from '../types'; | ||
import { getGroupMembersPublicKeys } from './getGroupMembersPublicKeys'; | ||
|
||
export const getAllGroupMembersPublicKeys = async (options: { | ||
chatId: string; | ||
env: EnvOptionsType['env']; | ||
}): Promise<{ did: string; publicKey: string }[]> => { | ||
const { chatId, env } = options; | ||
const count = await getChatMemberCount({ chatId, env }); | ||
const overallCount = count.approvedCount; | ||
const limit = 5000; | ||
const totalPages = Math.ceil(overallCount / limit); | ||
const pageNumbers = Array.from({ length: totalPages }, (_, i) => i + 1); | ||
const groupMembers: { did: string; publicKey: string }[] = []; | ||
|
||
const memberFetchPromises = pageNumbers.map((page) => | ||
getGroupMembersPublicKeys({ chatId, env, page, limit }) | ||
); | ||
|
||
const membersResults = await Promise.all(memberFetchPromises); | ||
membersResults.forEach((result) => { | ||
if (result.members.length > 0) { | ||
groupMembers.push(...result.members); | ||
} | ||
}); | ||
|
||
return groupMembers; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/restapi/src/lib/chat/getGroupMembersPublicKeys.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import axios from 'axios'; | ||
import { getAPIBaseUrls } from '../helpers'; | ||
import Constants, { ENV } from '../constants'; | ||
import { ChatMemberCounts, ChatMemberProfile } from '../types'; | ||
import { FetchChatGroupInfoType } from './getGroupMembers'; | ||
|
||
/** | ||
* GET /v1/chat/:chatId/members/public/keys | ||
*/ | ||
|
||
export const getGroupMembersPublicKeys = async ( | ||
options: FetchChatGroupInfoType | ||
): Promise<{ members: [{ did: string; publicKey: string }] }> => { | ||
const { chatId, page = 1, limit = 20, env = Constants.ENV.PROD } = options; | ||
|
||
try { | ||
if (!chatId) { | ||
throw new Error('Chat ID is required.'); | ||
} | ||
|
||
const API_BASE_URL = getAPIBaseUrls(env); | ||
const requestUrl = `${API_BASE_URL}/v1/chat/groups/${chatId}/members/public/keys?pageNumber=${page}&pageSize=${limit}`; | ||
|
||
const response = await axios.get(requestUrl); | ||
return response.data; | ||
} catch (error) { | ||
console.error( | ||
`[Push SDK] - API - Error - API ${getGroupMembersPublicKeys.name} -: `, | ||
error | ||
); | ||
throw new Error( | ||
`[Push SDK] - API - Error - API ${getGroupMembersPublicKeys.name} -: ${error}` | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters