Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable unsend request on the UI for now #1934

Merged
merged 2 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ts/components/conversation/message/GenericReadableMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
41 changes: 18 additions & 23 deletions ts/components/session/LeftPaneSectionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class SessionMessagesListContainerInner extends React.Component<Props> {
}

if (
conversation.unreadCount ||
(conversation.unreadCount && conversation.unreadCount <= 0) ||
firstUnreadOnOpen === undefined
) {
Expand Down
205 changes: 112 additions & 93 deletions ts/interactions/conversationInteractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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 = '';

Expand All @@ -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));
},
})
);
Expand All @@ -556,53 +604,24 @@ 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,
})
);
//#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);
}
}

Expand Down
2 changes: 0 additions & 2 deletions ts/session/sending/MessageSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down