disable unsend request on the UI for now (#1934)

* disable unsend request on the UI too

* do not stop propagation of events for message ctx menu
pull/1932/head
Audric Ackermann 4 years ago committed by GitHub
parent ffecc1bcd0
commit 4e30614077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -119,8 +119,6 @@ export const GenericReadableMessage = (props: Props) => {
const handleContextMenu = useCallback(
(e: React.MouseEvent<HTMLElement>) => {
e.preventDefault();
e.stopPropagation();
const enableContextMenu = !multiSelectMode && !msgProps?.isKickedFromGroup;
if (enableContextMenu) {

@ -64,38 +64,33 @@ export const LeftPaneSectionHeader = (props: Props) => {
);
};
export const LeftPaneBanner = () => {
const BannerInner = () => {
const dispatch = useDispatch();
const section = useSelector(getFocusedSection);
const showRecoveryPhraseModal = () => {
dispatch(
recoveryPhraseModal({
onClickOk: () => {
dispatch(disableRecoveryPhrasePrompt());
},
})
);
dispatch(disableRecoveryPhrasePrompt());
dispatch(recoveryPhraseModal({}));
};
return (
<StyledBannerInner>
<p>{window.i18n('recoveryPhraseRevealMessage')}</p>
<SessionButton
buttonType={SessionButtonType.Default}
text={window.i18n('recoveryPhraseRevealButtonText')}
onClick={showRecoveryPhraseModal}
/>
</StyledBannerInner>
);
};
export const LeftPaneBanner = () => {
const section = useSelector(getFocusedSection);
if (section !== SectionType.Message) {
return null;
}
const BannerInner = () => {
return (
<StyledBannerInner>
<p>{window.i18n('recoveryPhraseRevealMessage')}</p>
<SessionButton
buttonType={SessionButtonType.Default}
text={window.i18n('recoveryPhraseRevealButtonText')}
onClick={showRecoveryPhraseModal}
/>
</StyledBannerInner>
);
};
return (
<StyledLeftPaneBanner>
<StyledProgressBarContainer>

@ -171,7 +171,6 @@ class SessionMessagesListContainerInner extends React.Component<Props> {
}
if (
conversation.unreadCount ||
(conversation.unreadCount && conversation.unreadCount <= 0) ||
firstUnreadOnOpen === undefined
) {

@ -435,6 +435,104 @@ export async function uploadOurAvatar(newAvatarDecrypted?: ArrayBuffer) {
}
}
/**
* Deletes messages for everyone in a 1-1 or closed group conversation
* @param msgsToDelete Messages to delete
*/
async function deleteForAll(conversation: ConversationModel, msgsToDelete: Array<MessageModel>) {
window?.log?.warn('Deleting messages for all users in this conversation');
const result = await conversation.unsendMessages(msgsToDelete);
// TODO: may need to specify deletion for own device as well.
window.inboxStore?.dispatch(resetSelectedMessageIds());
if (result) {
ToastUtils.pushDeleted();
} else {
ToastUtils.someDeletionsFailed();
}
}
/**
*
* @param toDeleteLocallyIds Messages to delete for just this user. Still sends an unsend message to sync
* with other devices
*/
async function deleteForJustThisUser(
conversation: ConversationModel,
msgsToDelete: Array<MessageModel>
) {
window?.log?.warn('Deleting messages just for this user');
// is deleting on swarm sufficient or does it need to be unsent as well?
const deleteResult = await conversation.deleteMessages(msgsToDelete);
// Update view and trigger update
window.inboxStore?.dispatch(resetSelectedMessageIds());
if (deleteResult) {
ToastUtils.pushDeleted();
} else {
ToastUtils.someDeletionsFailed();
}
}
const doDeleteMessagesById = async (
selectedMessages: Array<MessageModel>,
conversation: ConversationModel,
deleteForEveryone: boolean = true
) => {
let toDeleteLocallyIds: Array<string>;
const ourDevicePubkey = UserUtils.getOurPubKeyStrFromCache();
if (!ourDevicePubkey) {
return;
}
const isServerDeletable = conversation.isPublic();
const isAllOurs = selectedMessages.every(message => ourDevicePubkey === message.getSource());
if (isServerDeletable) {
//#region open group v2 deletion
// Get our Moderator status
const isAdmin = conversation.isAdmin(ourDevicePubkey);
if (!isAllOurs && !isAdmin) {
ToastUtils.pushMessageDeleteForbidden();
window.inboxStore?.dispatch(resetSelectedMessageIds());
return;
}
toDeleteLocallyIds = await deleteOpenGroupMessages(selectedMessages, conversation);
if (toDeleteLocallyIds.length === 0) {
// Message failed to delete from server, show error?
return;
}
// successful deletion
ToastUtils.pushDeleted();
window.inboxStore?.dispatch(resetSelectedMessageIds());
//#endregion
} else {
//#region deletion for 1-1 and closed groups
if (!isAllOurs) {
ToastUtils.pushMessageDeleteForbidden();
window.inboxStore?.dispatch(resetSelectedMessageIds());
return;
}
if (window.lokiFeatureFlags?.useUnsendRequests) {
if (deleteForEveryone) {
void deleteForAll(conversation, selectedMessages);
} else {
void deleteForJustThisUser(conversation, selectedMessages);
}
} else {
//#region to remove once unsend enabled
const messageIds = selectedMessages.map(m => m.id) as Array<string>;
await Promise.all(messageIds.map(msgId => conversation.removeMessage(msgId)));
ToastUtils.pushDeleted();
window.inboxStore?.dispatch(resetSelectedMessageIds());
//#endregion
}
//#endregion
}
};
// tslint:disable-next-line: max-func-body-length
export async function deleteMessagesById(
messageIds: Array<string>,
@ -453,60 +551,6 @@ export async function deleteMessagesById(
// future reference
const isServerDeletable = conversation.isPublic();
const doDelete = async (deleteForEveryone: boolean = true) => {
let toDeleteLocallyIds: Array<string>;
const ourDevicePubkey = UserUtils.getOurPubKeyStrFromCache();
if (!ourDevicePubkey) {
return;
}
const isAllOurs = selectedMessages.every(message => ourDevicePubkey === message.getSource());
if (isServerDeletable) {
//#region open group v2 deletion
// Get our Moderator status
const isAdmin = conversation.isAdmin(ourDevicePubkey);
if (!isAllOurs && !isAdmin) {
ToastUtils.pushMessageDeleteForbidden();
window.inboxStore?.dispatch(resetSelectedMessageIds());
return;
}
toDeleteLocallyIds = await deleteOpenGroupMessages(selectedMessages, conversation);
if (toDeleteLocallyIds.length === 0) {
// Message failed to delete from server, show error?
return;
}
// successful deletion
ToastUtils.pushDeleted();
window.inboxStore?.dispatch(resetSelectedMessageIds());
//#endregion
} else {
//#region deletion for 1-1 and closed groups
if (!isAllOurs) {
ToastUtils.pushMessageDeleteForbidden();
window.inboxStore?.dispatch(resetSelectedMessageIds());
return;
}
if (window.lokiFeatureFlags?.useUnsendRequests) {
if (deleteForEveryone) {
void deleteForAll(selectedMessages);
} else {
void deleteForJustThisUser(selectedMessages);
}
} else {
//#region to remove once unsend enabled
await Promise.all(messageIds.map(msgId => conversation.removeMessage(msgId)));
ToastUtils.pushDeleted();
window.inboxStore?.dispatch(resetSelectedMessageIds());
//#endregion
}
//#endregion
}
};
if (askUserForConfirmation) {
let title = '';
@ -532,15 +576,19 @@ export async function deleteMessagesById(
window.inboxStore?.dispatch(updateConfirmModal(null));
window.inboxStore?.dispatch(
updateConfirmModal({
showExitIcon: true,
title: window.i18n('deletionTypeTitle'),
okText: window.i18n('deleteMessageForEveryoneLowercase'),
okTheme: SessionButtonColor.Danger,
onClickOk: async () => {
await doDelete(true);
await doDeleteMessagesById(selectedMessages, conversation, true);
},
cancelText: window.i18n('deleteJustForMe'),
onClickCancel: async () => {
await doDelete(false);
await doDeleteMessagesById(selectedMessages, conversation, false);
},
onClickClose: () => {
window.inboxStore?.dispatch(updateConfirmModal(null));
},
})
);
@ -556,11 +604,16 @@ export async function deleteMessagesById(
onClickOk: async () => {
if (isServerDeletable) {
// unsend logic
await doDelete(true);
await doDeleteMessagesById(selectedMessages, conversation, true);
// explicity close modal for this case.
window.inboxStore?.dispatch(updateConfirmModal(null));
} else {
showDeletionTypeModal();
if (window.lokiFeatureFlags?.useUnsendRequests) {
showDeletionTypeModal();
} else {
await doDeleteMessagesById(selectedMessages, conversation, false);
window.inboxStore?.dispatch(updateConfirmModal(null));
}
}
},
closeAfterInput: false,
@ -568,41 +621,7 @@ export async function deleteMessagesById(
);
//#endregion
} else {
void doDelete();
}
/**
* Deletes messages for everyone in a 1-1 or closed group conversation
* @param msgsToDelete Messages to delete
*/
async function deleteForAll(msgsToDelete: Array<MessageModel>) {
window?.log?.warn('Deleting messages for all users in this conversation');
const result = await conversation.unsendMessages(msgsToDelete);
// TODO: may need to specify deletion for own device as well.
window.inboxStore?.dispatch(resetSelectedMessageIds());
if (result) {
ToastUtils.pushDeleted();
} else {
ToastUtils.someDeletionsFailed();
}
}
/**
*
* @param toDeleteLocallyIds Messages to delete for just this user. Still sends an unsend message to sync
* with other devices
*/
async function deleteForJustThisUser(msgsToDelete: Array<MessageModel>) {
window?.log?.warn('Deleting messages just for this user');
// is deleting on swarm sufficient or does it need to be unsent as well?
const deleteResult = await conversation.deleteMessages(msgsToDelete);
// Update view and trigger update
window.inboxStore?.dispatch(resetSelectedMessageIds());
if (deleteResult) {
ToastUtils.pushDeleted();
} else {
ToastUtils.someDeletionsFailed();
}
void doDeleteMessagesById(selectedMessages, conversation);
}
}

@ -162,8 +162,6 @@ export async function TEST_sendMessageToSnode(
try {
const firstSuccessSnode = await firstTrue(promises);
snode = firstSuccessSnode;
// console.warn({successHash: });
} catch (e) {
const snodeStr = snode ? `${snode.ip}:${snode.port}` : 'null';
window?.log?.warn(

Loading…
Cancel
Save