Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group scalability #810

Merged
merged 20 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"scripts": {
"prepare": "husky install",
"test:restapi": "cd packages/restapi && TS_NODE_PROJECT='./tsconfig.mocha.json' NODE_OPTIONS='--loader ts-node/esm' mocha -r ts-node/register 'tests/**/*.test.ts' --timeout 12000 --require tests/root.ts --serial",
"test:restapi": "cd packages/restapi && TS_NODE_PROJECT='./tsconfig.mocha.json' NODE_OPTIONS='--loader ts-node/esm' mocha -r ts-node/register 'tests/**/*.test.ts' --timeout 1200000 --require tests/root.ts --serial",
"cleanbuild": "rimraf ./dist && rimraf ./tmp"
},
"config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ const ChatTest = () => {
<Link to="/getGroupMemberStatus" className="nav-button">
CHAT.GETGROUPMEMBERSTATUS
</Link>
<Link to="/getChatMemberCountTest" className="nav-button">
CHAT.GetChatMemberCountTest
</Link>
<Link to="/getGroupInfoTest" className="nav-button">
CHAT.GetGroupInfoTest
</Link>
<Link to="/getGroupMembersTest" className="nav-button">
CHAT.GetGroupMembersTest
</Link>
<Link to="/searchGroups" className="nav-button">
CHAT.SEARCHGROUPS
</Link>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { useState, useContext } from 'react';
import { Section, SectionItem, CodeFormatter, SectionButton } from '../components/StyledComponents';
import Loader from '../components/Loader';
import { EnvContext } from '../context';
import * as PushAPI from '@pushprotocol/restapi';

const GetChatMemberCountTest = () => {
const { env } = useContext<any>(EnvContext);
const [isLoading, setLoading] = useState(false);
const [chatId, setChatId] = useState<string>('');
const [totalMembersCount, setTotalMembersCount] = useState<PushAPI.ChatMemberCounts | null>(null);

const updateChatId = (e: React.ChangeEvent<HTMLInputElement>) => {
setChatId(e.target.value);
};

const fetchMemberCount = async () => {
try {
setLoading(true);
const counts = await PushAPI.chat.getChatMemberCount({ chatId, env });
setTotalMembersCount(counts);
} catch (error) {
console.error('Failed to fetch chat member count:', error);
} finally {
setLoading(false);
}
};

return (
<div>
<h2>Get Chat Member Count Test Page</h2>
<Loader show={isLoading} />
<Section>
<SectionItem>
<label>Chat ID:</label>
<input
type="text"
onChange={updateChatId}
value={chatId}
style={{ width: 400, height: 30 }}
/>
</SectionItem>
<SectionItem>
<SectionButton onClick={fetchMemberCount}>Fetch Member Count</SectionButton>
</SectionItem>
{totalMembersCount && (
<SectionItem>
<div>
<CodeFormatter>
{JSON.stringify(totalMembersCount, null, 2)}
</CodeFormatter>
</div>
</SectionItem>
)}
</Section>
</div>
);
};

export default GetChatMemberCountTest;
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { useState, useContext } from 'react';
import { EnvContext } from '../context';
import * as PushAPI from '@pushprotocol/restapi';
import Loader from '../components/Loader';
import { Section, SectionItem, CodeFormatter, SectionButton } from '../components/StyledComponents';

const GetGroupInfoTest = () => {
const { env } = useContext<any>(EnvContext);
const [chatId, setChatId] = useState('');
const [sendResponse, setSendResponse] = useState<any>('');
const [isLoading, setLoading] = useState(false);

const updateChatId = (e: React.ChangeEvent<HTMLInputElement>) => {
setChatId(e.target.value);
};

const fetchGroupInfo = async () => {
setLoading(true);
try {
const groupInfo = await PushAPI.chat.getGroupInfo({ chatId, env });
setSendResponse(groupInfo);
} catch (error) {
console.error('Error fetching group info:', error);
} finally {
setLoading(false);
}
};

return (
<div>
<h2>Get Group Info Test</h2>
<Loader show={isLoading} />
<Section>
<SectionItem>
<label htmlFor="chatId">Chat ID:</label>
<input
id="chatId"
type="text"
onChange={updateChatId}
value={chatId}
placeholder="Enter chat ID"
style={{ width: '100%', height: 30 }}
/>
</SectionItem>
<SectionItem>
<SectionButton onClick={fetchGroupInfo}>
Fetch Group Info
</SectionButton>
</SectionItem>
{sendResponse && (
<SectionItem>
<h3>Group Information:</h3>
<CodeFormatter>
{JSON.stringify(sendResponse, null, 2)}
</CodeFormatter>
</SectionItem>
)}
</Section>
</div>
);
};

export default GetGroupInfoTest;
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { useState, useContext, useEffect } from 'react';
import { Section, SectionItem, CodeFormatter, SectionButton } from '../components/StyledComponents';
import Loader from '../components/Loader';
import { EnvContext } from '../context';
import * as PushAPI from '@pushprotocol/restapi';

const GetGroupMembersTest = () => {
const { env } = useContext<any>(EnvContext);
const [isLoading, setLoading] = useState(false);
const [chatId, setChatId] = useState<string>('');
const [pageNumber, setPageNumber] = useState<number>(1);
const [pageSize, setPageSize] = useState<number>(20);
const [sendResponse, setSendResponse] = useState<any>('');


const updateChatId = (e: React.ChangeEvent<HTMLInputElement>) => {
setChatId(e.target.value);
};

const updatePageNumber = (e: React.ChangeEvent<HTMLInputElement>) => {
setPageNumber(parseInt(e.target.value));
};

const updatePageSize = (e: React.ChangeEvent<HTMLInputElement>) => {
setPageSize(parseInt(e.target.value));
};

const fetchGroupMembers = async () => {
setLoading(true);
try {
const result = await PushAPI.chat.getGroupMembers({
chatId,
page: pageNumber,
limit: pageSize,
env,
});
setSendResponse(result);
} catch (error) {
console.error('Failed to fetch group members:', error);
} finally {
setLoading(false);
}
};

// Fetch members when component mounts
useEffect(() => {
fetchGroupMembers();
}, []);

return (
<div>
<h2>Get Group Members Test Page</h2>
<Loader show={isLoading} />
<Section>
<SectionItem>
<label>Chat ID:</label>
<input
type="text"
onChange={updateChatId}
value={chatId}
placeholder="Enter chat ID"
style={{ width: '100%', height: 30 }}
/>
</SectionItem>
<SectionItem>
<label>Page Number:</label>
<input
type="number"
onChange={updatePageNumber}
value={pageNumber}
style={{ width: '100%', height: 30 }}
/>
</SectionItem>
<SectionItem>
<label>Page Size:</label>
<input
type="number"
onChange={updatePageSize}
value={pageSize}
style={{ width: '100%', height: 30 }}
/>
</SectionItem>
<SectionItem>
<SectionButton onClick={fetchGroupMembers}>Fetch Group Members</SectionButton>
</SectionItem>
{sendResponse && (
<SectionItem>
<CodeFormatter>
{JSON.stringify(sendResponse, null, 2)}
</CodeFormatter>
</SectionItem>
)}
</Section>
</div>
);
};

export default GetGroupMembersTest;
Loading