mirror of
https://github.com/Qortal/chrome-extension.git
synced 2025-02-11 17:55:49 +00:00
added kick and ban qortalRequests
This commit is contained in:
parent
e69563ee39
commit
b70a1f6773
@ -2535,7 +2535,7 @@ async function removeAdmin({ groupId, qortalAddress }) {
|
||||
return res;
|
||||
}
|
||||
|
||||
async function banFromGroup({
|
||||
export async function banFromGroup({
|
||||
groupId,
|
||||
qortalAddress,
|
||||
rBanReason = "",
|
||||
@ -2569,7 +2569,7 @@ async function banFromGroup({
|
||||
return res;
|
||||
}
|
||||
|
||||
async function kickFromGroup({ groupId, qortalAddress, rBanReason = "" }) {
|
||||
export async function kickFromGroup({ groupId, qortalAddress, rBanReason = "" }) {
|
||||
const lastReference = await getLastRef();
|
||||
const resKeyPair = await getKeyPair();
|
||||
const parsedData = JSON.parse(resKeyPair);
|
||||
|
@ -243,7 +243,7 @@ const UIQortalRequests = [
|
||||
'GET_TX_ACTIVITY_SUMMARY', 'GET_FOREIGN_FEE', 'UPDATE_FOREIGN_FEE',
|
||||
'GET_SERVER_CONNECTION_HISTORY', 'SET_CURRENT_FOREIGN_SERVER',
|
||||
'ADD_FOREIGN_SERVER', 'REMOVE_FOREIGN_SERVER', 'GET_DAY_SUMMARY', 'CREATE_TRADE_BUY_ORDER',
|
||||
'CREATE_TRADE_SELL_ORDER', 'CANCEL_TRADE_SELL_ORDER', 'IS_USING_GATEWAY', 'ADMIN_ACTION', 'SIGN_TRANSACTION', 'DECRYPT_QORTAL_GROUP_DATA', 'DELETE_HOSTED_DATA', 'GET_HOSTED_DATA', 'DECRYPT_DATA_WITH_SHARING_KEY', 'SHOW_ACTIONS', 'REGISTER_NAME', 'UPDATE_NAME', 'LEAVE_GROUP', 'INVITE_TO_GROUP'
|
||||
'CREATE_TRADE_SELL_ORDER', 'CANCEL_TRADE_SELL_ORDER', 'IS_USING_GATEWAY', 'ADMIN_ACTION', 'SIGN_TRANSACTION', 'DECRYPT_QORTAL_GROUP_DATA', 'DELETE_HOSTED_DATA', 'GET_HOSTED_DATA', 'DECRYPT_DATA_WITH_SHARING_KEY', 'SHOW_ACTIONS', 'REGISTER_NAME', 'UPDATE_NAME', 'LEAVE_GROUP', 'INVITE_TO_GROUP', 'KICK_FROM_GROUP', 'BAN_FROM_GROUP'
|
||||
];
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { gateways, getApiKeyFromStorage } from "./background";
|
||||
import { addForeignServer, addListItems, adminAction, cancelSellOrder, createBuyOrder, createPoll, createSellOrder, decryptData, decryptDataWithSharingKey, decryptQortalGroupData, deleteHostedData, deleteListItems, deployAt, encryptData, encryptDataWithSharingKey, encryptQortalGroupData, getCrossChainServerInfo, getDaySummary, getForeignFee, getHostedData, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, inviteToGroupRequest, joinGroup, leaveGroupRequest, publishMultipleQDNResources, publishQDNResource, registerNameRequest, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, updateNameRequest, voteOnPoll } from "./qortalRequests/get";
|
||||
import { banFromGroup, gateways, getApiKeyFromStorage } from "./background";
|
||||
import { addForeignServer, addListItems, adminAction, cancelSellOrder, createBuyOrder, createPoll, createSellOrder, decryptData, decryptDataWithSharingKey, decryptQortalGroupData, deleteHostedData, deleteListItems, deployAt, encryptData, encryptDataWithSharingKey, encryptQortalGroupData, getCrossChainServerInfo, getDaySummary, getForeignFee, getHostedData, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, inviteToGroupRequest, joinGroup, kickFromGroupRequest, leaveGroupRequest, publishMultipleQDNResources, publishQDNResource, registerNameRequest, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, updateNameRequest, voteOnPoll } from "./qortalRequests/get";
|
||||
|
||||
const listOfAllQortalRequests = [
|
||||
'GET_USER_ACCOUNT', 'DECRYPT_DATA', 'SEND_COIN', 'GET_LIST_ITEMS',
|
||||
@ -672,7 +672,30 @@ chrome?.runtime?.onMessage.addListener((request, sender, sendResponse) => {
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "KICK_FROM_GROUP" : {
|
||||
const data = request.payload;
|
||||
|
||||
kickFromGroupRequest(data, isFromExtension)
|
||||
.then((res) => {
|
||||
sendResponse(res);
|
||||
})
|
||||
.catch((error) => {
|
||||
sendResponse({ error: error.message });
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "BAN_FROM_GROUP" : {
|
||||
const data = request.payload;
|
||||
|
||||
banFromGroup(data, isFromExtension)
|
||||
.then((res) => {
|
||||
sendResponse(res);
|
||||
})
|
||||
.catch((error) => {
|
||||
sendResponse({ error: error.message });
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,9 @@ import {
|
||||
registerName,
|
||||
getNameInfoForOthers,
|
||||
leaveGroup,
|
||||
inviteToGroup
|
||||
inviteToGroup,
|
||||
banFromGroup,
|
||||
kickFromGroup
|
||||
} from "../background";
|
||||
import { decryptGroupEncryption, getNameInfo, uint8ArrayToObject } from "../backgroundFunctions/encryption";
|
||||
import { QORT_DECIMALS } from "../constants/constants";
|
||||
@ -2646,6 +2648,7 @@ export const sendCoin = async (data, isFromExtension) => {
|
||||
text1: "Do you give this application permission to send coins?",
|
||||
text2: `To: ${recipient}`,
|
||||
highlightedText: `${amount} ${checkCoin}`,
|
||||
fee: fee
|
||||
}, isFromExtension);
|
||||
const { accepted } = resPermission;
|
||||
|
||||
@ -3986,3 +3989,102 @@ export const inviteToGroupRequest = async (data, isFromExtension) => {
|
||||
throw new Error("User declined request");
|
||||
}
|
||||
};
|
||||
|
||||
export const kickFromGroupRequest = async (data, isFromExtension) => {
|
||||
const requiredFields = ["groupId", "qortalAddress"];
|
||||
const missingFields: string[] = [];
|
||||
requiredFields.forEach((field) => {
|
||||
if (!data[field]) {
|
||||
missingFields.push(field);
|
||||
}
|
||||
});
|
||||
const groupId = data.groupId
|
||||
const qortalAddress = data?.qortalAddress
|
||||
const reason = data?.reason
|
||||
|
||||
let groupInfo = null;
|
||||
try {
|
||||
const url = await createEndpoint(`/groups/${groupId}`);
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) throw new Error("Failed to fetch group");
|
||||
|
||||
groupInfo = await response.json();
|
||||
} catch (error) {
|
||||
const errorMsg = (error && error.message) || "Group not found";
|
||||
throw new Error(errorMsg);
|
||||
}
|
||||
|
||||
const displayInvitee = await getNameInfoForOthers(qortalAddress)
|
||||
|
||||
const fee = await getFee("GROUP_KICK");
|
||||
const resPermission = await getUserPermission(
|
||||
{
|
||||
text1: `Do you give this application permission to kick ${displayInvitee || qortalAddress} from the group?`,
|
||||
highlightedText: `Group: ${groupInfo.groupName}`,
|
||||
fee: fee.fee,
|
||||
},
|
||||
isFromExtension
|
||||
);
|
||||
const { accepted } = resPermission;
|
||||
if (accepted) {
|
||||
const response = await kickFromGroup({
|
||||
groupId,
|
||||
qortalAddress,
|
||||
rBanReason: reason
|
||||
})
|
||||
return response
|
||||
|
||||
} else {
|
||||
throw new Error("User declined request");
|
||||
}
|
||||
};
|
||||
|
||||
export const banFromGroupRequest = async (data, isFromExtension) => {
|
||||
const requiredFields = ["groupId", "qortalAddress"];
|
||||
const missingFields: string[] = [];
|
||||
requiredFields.forEach((field) => {
|
||||
if (!data[field]) {
|
||||
missingFields.push(field);
|
||||
}
|
||||
});
|
||||
const groupId = data.groupId
|
||||
const qortalAddress = data?.qortalAddress
|
||||
const rBanTime = data?.banTime
|
||||
const reason = data?.reason
|
||||
let groupInfo = null;
|
||||
try {
|
||||
const url = await createEndpoint(`/groups/${groupId}`);
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) throw new Error("Failed to fetch group");
|
||||
|
||||
groupInfo = await response.json();
|
||||
} catch (error) {
|
||||
const errorMsg = (error && error.message) || "Group not found";
|
||||
throw new Error(errorMsg);
|
||||
}
|
||||
|
||||
const displayInvitee = await getNameInfoForOthers(qortalAddress)
|
||||
|
||||
const fee = await getFee("GROUP_BAN");
|
||||
const resPermission = await getUserPermission(
|
||||
{
|
||||
text1: `Do you give this application permission to ban ${displayInvitee || qortalAddress} from the group?`,
|
||||
highlightedText: `Group: ${groupInfo.groupName}`,
|
||||
fee: fee.fee,
|
||||
},
|
||||
isFromExtension
|
||||
);
|
||||
const { accepted } = resPermission;
|
||||
if (accepted) {
|
||||
const response = await banFromGroup({
|
||||
groupId,
|
||||
qortalAddress,
|
||||
rBanTime,
|
||||
rBanReason: reason
|
||||
})
|
||||
return response
|
||||
|
||||
} else {
|
||||
throw new Error("User declined request");
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user