mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-11-16 21:07:07 +00:00
added group bans list message
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
handleAccount,
|
||||
handleAccountBalance,
|
||||
handleActiveChat,
|
||||
handleGroupBansMessage,
|
||||
handleGroupsMessage,
|
||||
handleLastReference,
|
||||
handleNamesMessage,
|
||||
@@ -17,6 +18,7 @@ import {
|
||||
createGetAccountBalancePayload,
|
||||
createGetAccountMessagePayload,
|
||||
createGetAddressNamesPayload,
|
||||
createGetBansPayload,
|
||||
createGetGroupPayload,
|
||||
createGetGroupsPayload,
|
||||
createGetLastReferencePayload,
|
||||
@@ -87,6 +89,20 @@ export async function getGroup(groupId: number): Promise<any> {
|
||||
throw new Error('No group data');
|
||||
}
|
||||
|
||||
export async function getBans(groupId: number): Promise<any> {
|
||||
const client = getRandomClient();
|
||||
if (!client) throw new Error('No available peers');
|
||||
|
||||
const res: Buffer = await client.sendRequest(
|
||||
MessageType.GET_GROUP_BANS,
|
||||
createGetBansPayload(groupId)
|
||||
);
|
||||
|
||||
const data = handleGroupBansMessage(res);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getLastReference(address: string): Promise<any> {
|
||||
const client = getRandomClient();
|
||||
if (!client) throw new Error('No available peers');
|
||||
|
||||
@@ -4,6 +4,7 @@ import { WebSocketServer } from 'ws';
|
||||
import {
|
||||
getAccount,
|
||||
getAccountBalance,
|
||||
getBans,
|
||||
getGroup,
|
||||
getGroups,
|
||||
getLastReference,
|
||||
@@ -90,6 +91,17 @@ export async function createHttpServer() {
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/groups/bans/:groupId', async (req, res) => {
|
||||
try {
|
||||
const groupId = req.params.groupId;
|
||||
|
||||
const bans = await getBans(groupId);
|
||||
res.json(bans);
|
||||
} catch (err: any) {
|
||||
res.status(500).type('text').send(`Error: ${err.message}`);
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/groups/:groupId', async (req, res) => {
|
||||
try {
|
||||
const groupId = req.params.groupId;
|
||||
|
||||
@@ -447,3 +447,56 @@ export function handleGroupsMessage(buffer) {
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
export function handleGroupBansMessage(buffer) {
|
||||
let offset = 0;
|
||||
|
||||
const { value: count, size: countSize } = readInt(buffer, offset);
|
||||
offset += countSize;
|
||||
|
||||
const bans = [];
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const { value: groupId, size: s1 } = readInt(buffer, offset);
|
||||
offset += s1;
|
||||
|
||||
const offenderBytes = buffer.subarray(offset, offset + 25);
|
||||
const offender = bs58.encode(offenderBytes);
|
||||
offset += 25;
|
||||
|
||||
const adminBytes = buffer.subarray(offset, offset + 25);
|
||||
const admin = bs58.encode(adminBytes);
|
||||
offset += 25;
|
||||
|
||||
const { value: banned, size: s2 } = readLong(buffer, offset);
|
||||
offset += s2;
|
||||
|
||||
const { value: reason, size: s3 } = readNullableString(buffer, offset);
|
||||
offset += s3;
|
||||
|
||||
const { value: hasExpiry, size: s4 } = readInt(buffer, offset);
|
||||
offset += s4;
|
||||
|
||||
let expiry = null;
|
||||
if (hasExpiry === 1) {
|
||||
const { value, size } = readLong(buffer, offset);
|
||||
expiry = value;
|
||||
offset += size;
|
||||
}
|
||||
|
||||
const referenceBytes = buffer.subarray(offset, offset + 64);
|
||||
const reference = bs58.encode(referenceBytes);
|
||||
offset += 64;
|
||||
|
||||
bans.push({
|
||||
groupId,
|
||||
offender,
|
||||
admin,
|
||||
banned,
|
||||
reason,
|
||||
expiry,
|
||||
});
|
||||
}
|
||||
|
||||
return bans;
|
||||
}
|
||||
|
||||
@@ -29,4 +29,6 @@ export enum MessageType {
|
||||
GROUPS = 310,
|
||||
GET_GROUPS = 311,
|
||||
GET_GROUP = 312,
|
||||
GROUP_BANS = 313,
|
||||
GET_GROUP_BANS = 314,
|
||||
}
|
||||
|
||||
@@ -130,6 +130,12 @@ export function createGetGroupPayload(groupId: number): Buffer {
|
||||
return groupIdBuffer;
|
||||
}
|
||||
|
||||
export function createGetBansPayload(groupId: number): Buffer {
|
||||
const groupIdBuffer = Buffer.alloc(4);
|
||||
groupIdBuffer.writeInt32BE(groupId);
|
||||
return groupIdBuffer;
|
||||
}
|
||||
|
||||
export function createGetLastReferencePayload(address: string): Buffer {
|
||||
const addressBytes = bs58.decode(address);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user