adding Ban user and delete all his messages to the menu for moderators
This commit is contained in:
parent
c415c715a5
commit
2c6821097d
|
@ -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,7 @@ 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,7 @@ 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 +24,12 @@ 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: title,
|
||||
message: message,
|
||||
onClickClose,
|
||||
onClickOk: async () => {
|
||||
const conversation = getConversationController().get(conversationId);
|
||||
|
@ -40,7 +43,7 @@ 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: endPoint,
|
||||
};
|
||||
const banResult = await exports.sendApiV2Request(request);
|
||||
const isOk = parseStatusCodeFromOnionRequest(banResult) === 200;
|
||||
|
|
Loading…
Reference in New Issue