fix: delete locally only allowed for failed sogs message

pull/3061/head
Audric Ackermann 2 years ago
parent a52ed6490a
commit 3a1b811ba7

@ -3,11 +3,7 @@ import React from 'react';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import useKey from 'react-use/lib/useKey'; import useKey from 'react-use/lib/useKey';
import { import { deleteMessagesForX } from '../../../interactions/conversations/unsendingInteractions';
deleteMessagesById,
deleteMessagesByIdForEveryone,
deleteMessagesForX,
} from '../../../interactions/conversations/unsendingInteractions';
import { resetSelectedMessageIds } from '../../../state/ducks/conversations'; import { resetSelectedMessageIds } from '../../../state/ducks/conversations';
import { getSelectedMessageIds } from '../../../state/selectors/conversations'; import { getSelectedMessageIds } from '../../../state/selectors/conversations';
import { import {
@ -22,15 +18,6 @@ import {
} from '../../basic/SessionButton'; } from '../../basic/SessionButton';
import { SessionIconButton } from '../../icon'; import { SessionIconButton } from '../../icon';
function onDeleteSelectedMessagesForEveryone(
selectedConversationKey: string,
selectedMessageIds: Array<string>
) {
if (selectedConversationKey) {
void deleteMessagesByIdForEveryone(selectedMessageIds, selectedConversationKey);
}
}
export const SelectionOverlay = () => { export const SelectionOverlay = () => {
const selectedMessageIds = useSelector(getSelectedMessageIds); const selectedMessageIds = useSelector(getSelectedMessageIds);
const selectedConversationKey = useSelectedConversationKey(); const selectedConversationKey = useSelectedConversationKey();
@ -73,7 +60,11 @@ export const SelectionOverlay = () => {
} }
); );
const isOnlyServerDeletable = isPublic; // `enforceDeleteServerSide` should check for message statuses too, but when we have multiple selected,
// some might be sent and some in an error state. We default to trying to delete all of them server side first,
// which might fail. If that fails, the user will need to do a delete for all the ones sent already, and a manual delete
// for each ones which is in an error state.
const enforceDeleteServerSide = isPublic;
const classNameAndId = 'message-selection-overlay'; const classNameAndId = 'message-selection-overlay';
@ -90,16 +81,13 @@ export const SelectionOverlay = () => {
buttonShape={SessionButtonShape.Square} buttonShape={SessionButtonShape.Square}
buttonType={SessionButtonType.Solid} buttonType={SessionButtonType.Solid}
text={window.i18n('delete')} text={window.i18n('delete')}
onClick={() => { onClick={async () => {
if (selectedConversationKey) { if (selectedConversationKey) {
if (isOnlyServerDeletable) { await deleteMessagesForX(
void onDeleteSelectedMessagesForEveryone( selectedMessageIds,
selectedConversationKey, selectedConversationKey,
selectedMessageIds enforceDeleteServerSide
); );
} else {
void deleteMessagesById(selectedMessageIds, selectedConversationKey);
}
} }
}} }}
/> />

@ -91,12 +91,15 @@ const DeleteItem = ({ messageId }: { messageId: string }) => {
const isDeletable = useMessageIsDeletable(messageId); const isDeletable = useMessageIsDeletable(messageId);
const isDeletableForEveryone = useMessageIsDeletableForEveryone(messageId); const isDeletableForEveryone = useMessageIsDeletableForEveryone(messageId);
const messageStatus = useMessageStatus(messageId);
const enforceDeleteServerSide = isPublic && messageStatus !== 'error';
const onDelete = useCallback(() => { const onDelete = useCallback(() => {
if (convoId) { if (convoId) {
void deleteMessagesForX([messageId], convoId, isPublic); void deleteMessagesForX([messageId], convoId, enforceDeleteServerSide);
} }
}, [convoId, isPublic, messageId]); }, [convoId, enforceDeleteServerSide, messageId]);
if (!convoId || (isPublic && !isDeletableForEveryone) || (!isPublic && !isDeletable)) { if (!convoId || (isPublic && !isDeletableForEveryone) || (!isPublic && !isDeletable)) {
return null; return null;

@ -303,7 +303,7 @@ const doDeleteSelectedMessages = async ({
} }
const isAllOurs = selectedMessages.every(message => ourDevicePubkey === message.getSource()); const isAllOurs = selectedMessages.every(message => ourDevicePubkey === message.getSource());
if (conversation.isPublic()) { if (conversation.isPublic() && deleteForEveryone) {
await doDeleteSelectedMessagesInSOGS(selectedMessages, conversation, isAllOurs); await doDeleteSelectedMessagesInSOGS(selectedMessages, conversation, isAllOurs);
return; return;
} }
@ -341,14 +341,14 @@ const doDeleteSelectedMessages = async ({
export async function deleteMessagesForX( export async function deleteMessagesForX(
messageIds: Array<string>, messageIds: Array<string>,
conversationId: string, conversationId: string,
isPublic: boolean /** should only be enforced for messages successfully sent on communities */
enforceDeleteServerSide: boolean
) { ) {
if (conversationId) { if (conversationId) {
if (!isPublic) { if (enforceDeleteServerSide) {
void deleteMessagesById(messageIds, conversationId); await deleteMessagesByIdForEveryone(messageIds, conversationId);
} } else {
if (isPublic) { await deleteMessagesById(messageIds, conversationId);
void deleteMessagesByIdForEveryone(messageIds, conversationId);
} }
} }
} }

Loading…
Cancel
Save