mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
Merge pull request #1819 from Brice-W/ban-and-delete-messages
'Ban user and delete all messages' added to menu
This commit is contained in:
commit
7365cb2291
|
@ -255,6 +255,8 @@
|
|||
"userUnbanFailed": "Unban failed!",
|
||||
"banUser": "Ban User",
|
||||
"banUserConfirm": "Are you sure you want to ban the user?",
|
||||
"banUserAndDeleteAll": "Ban and Delete All",
|
||||
"banUserAndDeleteAllConfirm": "Are you sure you want to ban the user and delete all his messages?",
|
||||
"userBanned": "Banned successfully",
|
||||
"userBanFailed": "Ban failed!",
|
||||
"leaveGroup": "Leave Group",
|
||||
|
|
|
@ -260,6 +260,8 @@
|
|||
"userUnbanFailed": "Le débannissement a échoué !",
|
||||
"banUser": "Bannir l'utilisateur",
|
||||
"banUserConfirm": "Êtes-vous sûr de vouloir bannir cet utilisateur ?",
|
||||
"banUserAndDeleteAll": "Bannir et tout supprimer",
|
||||
"banUserAndDeleteAllConfirm": "Êtes-vous sûr de vouloir bannir cet utilisateur et supprimer tous ses messages ?",
|
||||
"userBanned": "Utilisateur banni",
|
||||
"userBanFailed": "Le bannissement a échoué",
|
||||
"leaveGroup": "Quitter le groupe",
|
||||
|
|
|
@ -131,6 +131,10 @@ export const MessageContextMenu = (props: PropsForMessageContextMenu) => {
|
|||
MessageInteraction.banUser(authorPhoneNumber, convoId);
|
||||
}, [authorPhoneNumber, convoId]);
|
||||
|
||||
const onBanAndDeleteAll = useCallback(() => {
|
||||
MessageInteraction.banUser(authorPhoneNumber, convoId, true);
|
||||
}, [authorPhoneNumber, convoId]);
|
||||
|
||||
const onUnban = useCallback(() => {
|
||||
MessageInteraction.unbanUser(authorPhoneNumber, convoId);
|
||||
}, [authorPhoneNumber, convoId]);
|
||||
|
@ -165,6 +169,9 @@ export const MessageContextMenu = (props: PropsForMessageContextMenu) => {
|
|||
</>
|
||||
) : null}
|
||||
{weAreAdmin && isPublic ? <Item onClick={onBan}>{window.i18n('banUser')}</Item> : null}
|
||||
{weAreAdmin && isPublic ? (
|
||||
<Item onClick={onBanAndDeleteAll}>{window.i18n('banUserAndDeleteAll')}</Item>
|
||||
) : null}
|
||||
{weAreAdmin && isOpenGroupV2 ? (
|
||||
<Item onClick={onUnban}>{window.i18n('unbanUser')}</Item>
|
||||
) : null}
|
||||
|
|
|
@ -10,7 +10,11 @@ import { ToastUtils } from '../session/utils';
|
|||
|
||||
import { updateConfirmModal } from '../state/ducks/modalDialog';
|
||||
|
||||
export function banUser(userToBan: string, conversationId: string) {
|
||||
export function banUser(
|
||||
userToBan: string,
|
||||
conversationId: string,
|
||||
deleteAllMessages: boolean = false
|
||||
) {
|
||||
let pubKeyToBan: PubKey;
|
||||
try {
|
||||
pubKeyToBan = PubKey.cast(userToBan);
|
||||
|
@ -24,9 +28,14 @@ export function banUser(userToBan: string, conversationId: string) {
|
|||
window.inboxStore?.dispatch(updateConfirmModal(null));
|
||||
};
|
||||
|
||||
const title = deleteAllMessages ? window.i18n('banUserAndDeleteAll') : window.i18n('banUser');
|
||||
const message = deleteAllMessages
|
||||
? window.i18n('banUserAndDeleteAllConfirm')
|
||||
: window.i18n('banUserConfirm');
|
||||
|
||||
const confirmationModalProps = {
|
||||
title: window.i18n('banUser'),
|
||||
message: window.i18n('banUserConfirm'),
|
||||
title,
|
||||
message,
|
||||
onClickClose,
|
||||
onClickOk: async () => {
|
||||
const conversation = getConversationController().get(conversationId);
|
||||
|
@ -40,7 +49,11 @@ export function banUser(userToBan: string, conversationId: string) {
|
|||
if (!roomInfos) {
|
||||
window.log.warn('banUser room not found');
|
||||
} else {
|
||||
success = await ApiV2.banUser(pubKeyToBan, _.pick(roomInfos, 'serverUrl', 'roomId'));
|
||||
success = await ApiV2.banUser(
|
||||
pubKeyToBan,
|
||||
_.pick(roomInfos, 'serverUrl', 'roomId'),
|
||||
deleteAllMessages
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw new Error('V1 opengroup are not supported');
|
||||
|
|
|
@ -264,16 +264,18 @@ export const postMessage = async (
|
|||
|
||||
export const banUser = async (
|
||||
userToBan: PubKey,
|
||||
roomInfos: OpenGroupRequestCommonType
|
||||
roomInfos: OpenGroupRequestCommonType,
|
||||
deleteAllMessages: boolean
|
||||
): Promise<boolean> => {
|
||||
const queryParams = { public_key: userToBan.key };
|
||||
const endpoint = deleteAllMessages ? 'ban_and_delete_all' : 'block_list';
|
||||
const request: OpenGroupV2Request = {
|
||||
method: 'POST',
|
||||
room: roomInfos.roomId,
|
||||
server: roomInfos.serverUrl,
|
||||
isAuthRequired: true,
|
||||
queryParams,
|
||||
endpoint: 'block_list',
|
||||
endpoint,
|
||||
};
|
||||
const banResult = await exports.sendApiV2Request(request);
|
||||
const isOk = parseStatusCodeFromOnionRequest(banResult) === 200;
|
||||
|
|
Loading…
Reference in a new issue