added get join requests message

This commit is contained in:
2025-08-02 17:34:02 +03:00
parent 1062f382d7
commit 3ae82e4781
5 changed files with 64 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ import {
handleActiveChat,
handleAddressGroupInvitesMessage,
handleGroupBansMessage,
handleGroupJoinRequestsMessage,
handleGroupsMessage,
handleLastReference,
handleNamesMessage,
@@ -22,6 +23,7 @@ import {
createGetAddressNamesPayload,
createGetBansPayload,
createGetGroupInvitesPayload,
createGetGroupJoinRequestsPayload,
createGetGroupPayload,
createGetGroupsPayload,
createGetLastReferencePayload,
@@ -132,6 +134,20 @@ export async function getGroupInvites(groupId: number): Promise<any> {
return data;
}
export async function getGroupJoinRequests(groupId: number): Promise<any> {
const client = getRandomClient();
if (!client) throw new Error('No available peers');
const res: Buffer = await client.sendRequest(
MessageType.GET_GROUP_JOIN_REQUESTS,
createGetGroupJoinRequestsPayload(groupId)
);
const data = handleGroupJoinRequestsMessage(res);
return data;
}
export async function getLastReference(address: string): Promise<any> {
const client = getRandomClient();
if (!client) throw new Error('No available peers');

View File

@@ -8,6 +8,7 @@ import {
getBans,
getGroup,
getGroupInvites,
getGroupJoinRequests,
getGroups,
getLastReference,
getNameInfo,
@@ -134,6 +135,16 @@ export async function createHttpServer() {
}
});
app.get('/groups/joinrequests/:groupId', async (req, res) => {
const groupId = req.params.groupId;
try {
const joinRequests = await getGroupJoinRequests(groupId);
res.json(joinRequests);
} catch (err: any) {
res.status(500).type('text').send(`Error: ${err.message}`);
}
});
app.get('/transactions/unitfee', async (req, res) => {
try {
const txType = req.query.txType as string;

View File

@@ -545,3 +545,32 @@ export function handleAddressGroupInvitesMessage(buffer) {
return invites;
}
export function handleGroupJoinRequestsMessage(buffer) {
let offset = 0;
const { value: count, size: countSize } = readInt(buffer, offset);
offset += countSize;
const joinRequests = [];
for (let i = 0; i < count; i++) {
const { value: groupId, size: s1 } = readInt(buffer, offset);
offset += s1;
const joinerBytes = buffer.subarray(offset, offset + 25);
const joiner = bs58.encode(joinerBytes);
offset += 25;
const referenceBytes = buffer.subarray(offset, offset + 64);
const reference = bs58.encode(referenceBytes);
offset += 64;
joinRequests.push({
groupId,
joiner,
});
}
return joinRequests;
}

View File

@@ -34,4 +34,6 @@ export enum MessageType {
GROUP_INVITES = 315,
GET_ADDRESS_GROUP_INVITES = 316,
GET_GROUP_INVITES = 317,
GROUP_JOIN_REQUESTS = 318,
GET_GROUP_JOIN_REQUESTS = 319,
}

View File

@@ -153,6 +153,12 @@ export function createGetGroupInvitesPayload(groupId: number): Buffer {
return groupIdBuffer;
}
export function createGetGroupJoinRequestsPayload(groupId: number): Buffer {
const groupIdBuffer = Buffer.alloc(4);
groupIdBuffer.writeInt32BE(groupId);
return groupIdBuffer;
}
export function createGetLastReferencePayload(address: string): Buffer {
const addressBytes = bs58.decode(address);