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

Display link preview popup only once #1757

Merged
merged 2 commits into from
Jul 2, 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
5 changes: 0 additions & 5 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,6 @@
window.libsession.Utils.ToastUtils.pushSpellCheckDirty();
};

window.toggleLinkPreview = () => {
const newValue = !window.getSettingValue('link-preview-setting');
window.setSettingValue('link-preview-setting', newValue);
};

window.toggleMediaPermissions = () => {
const value = window.getMediaPermissions();
window.setMediaPermissions(!value);
Expand Down
17 changes: 14 additions & 3 deletions ts/components/session/conversation/SessionCompositionBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ import { getMentionsInput } from '../../../state/selectors/mentionsInput';
import { updateConfirmModal } from '../../../state/ducks/modalDialog';
import { SessionButtonColor } from '../SessionButton';
import { SessionConfirmDialogProps } from '../SessionConfirm';
import {
createOrUpdateItem,
getItemById,
hasLinkPreviewPopupBeenDisplayed,
} from '../../../data/data';

export interface ReplyingToMessageProps {
convoId: string;
Expand Down Expand Up @@ -218,7 +223,7 @@ export class SessionCompositionBox extends React.Component<Props, State> {
imgBlob = item.getAsFile();
break;
case 'text':
this.showLinkSharingConfirmationModalDialog(e);
void this.showLinkSharingConfirmationModalDialog(e);
break;
default:
}
Expand All @@ -237,18 +242,24 @@ export class SessionCompositionBox extends React.Component<Props, State> {
* Check if what is pasted is a URL and prompt confirmation for a setting change
* @param e paste event
*/
private showLinkSharingConfirmationModalDialog(e: any) {
private async showLinkSharingConfirmationModalDialog(e: any) {
const pastedText = e.clipboardData.getData('text');
if (this.isURL(pastedText)) {
const alreadyDisplayedPopup =
(await getItemById(hasLinkPreviewPopupBeenDisplayed))?.value || false;
window.inboxStore?.dispatch(
updateConfirmModal({
shouldShowConfirm: () => !window.getSettingValue('link-preview-setting'),
shouldShowConfirm: () =>
!window.getSettingValue('link-preview-setting') && !alreadyDisplayedPopup,
title: window.i18n('linkPreviewsTitle'),
message: window.i18n('linkPreviewsConfirmMessage'),
okTheme: SessionButtonColor.Danger,
onClickOk: () => {
window.setSettingValue('link-preview-setting', true);
},
onClickClose: async () => {
await createOrUpdateItem({ id: hasLinkPreviewPopupBeenDisplayed, value: true });
},
})
);
}
Expand Down
14 changes: 12 additions & 2 deletions ts/components/session/settings/SessionSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { StateType } from '../../../state/reducer';
import { getConversationController } from '../../../session/conversations';
import { getConversationLookup } from '../../../state/selectors/conversations';
import { connect, useSelector } from 'react-redux';
import { getPasswordHash } from '../../../../ts/data/data';
import {
createOrUpdateItem,
getPasswordHash,
hasLinkPreviewPopupBeenDisplayed,
} from '../../../../ts/data/data';
import { SpacerLG, SpacerXS } from '../../basic/Text';
import { shell } from 'electron';
import { SessionConfirmDialogProps } from '../SessionConfirm';
Expand Down Expand Up @@ -339,7 +343,13 @@ class SettingsViewInner extends React.Component<SettingsViewProps, State> {
hidden: false,
type: SessionSettingType.Toggle,
category: SessionSettingCategory.Appearance,
setFn: window.toggleLinkPreview,
setFn: async () => {
const newValue = !window.getSettingValue('link-preview-setting');
window.setSettingValue('link-preview-setting', newValue);
if (!newValue) {
await createOrUpdateItem({ id: hasLinkPreviewPopupBeenDisplayed, value: false });
}
},
content: undefined,
comparisonValue: undefined,
onClick: undefined,
Expand Down
1 change: 1 addition & 0 deletions ts/data/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type ServerToken = {

export const hasSyncedInitialConfigurationItem = 'hasSyncedInitialConfigurationItem';
export const lastAvatarUploadTimestamp = 'lastAvatarUploadTimestamp';
export const hasLinkPreviewPopupBeenDisplayed = 'hasLinkPreviewPopupBeenDisplayed';

const channelsToMake = {
shutdown,
Expand Down
1 change: 0 additions & 1 deletion ts/window.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ declare global {
showResetSessionIdDialog: any;
storage: any;
textsecure: LibTextsecure;
toggleLinkPreview: any;
toggleMediaPermissions: any;
toggleMenuBar: any;
toggleSpellCheck: any;
Expand Down