From 3ab94a7e0080ee0b51ffbb48249d9a926ea38100 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 28 Nov 2024 15:54:15 +1100 Subject: [PATCH] feat: allow to not trigger toast on copyToClipboardButton because the about window doesn't have a full redux store setup, and the toasts need redux currently --- ts/components/AboutView.tsx | 4 ++++ ts/components/basic/SessionToast.tsx | 3 +-- ts/components/buttons/CopyToClipboardButton.tsx | 14 +++++++++----- .../overlay/OverlayRightPanelSettings.tsx | 8 ++++---- ts/components/dialog/UpdateGroupNameDialog.tsx | 6 ++++++ .../conversations/unsendingInteractions.ts | 3 ++- .../SwarmPollingGroupConfig.ts | 14 +++++++++++--- .../utils/job_runners/jobs/GroupInviteJob.ts | 1 + ts/state/ducks/metaGroups.ts | 2 ++ 9 files changed, 40 insertions(+), 15 deletions(-) diff --git a/ts/components/AboutView.tsx b/ts/components/AboutView.tsx index a42e8b5d5..58ae1ec98 100644 --- a/ts/components/AboutView.tsx +++ b/ts/components/AboutView.tsx @@ -95,22 +95,26 @@ export const AboutView = () => { className="version" text={versionInfo} buttonType={SessionButtonType.Simple} + showToast={false} /> {environmentStates.length ? ( ) : null} https://getsession.org diff --git a/ts/components/basic/SessionToast.tsx b/ts/components/basic/SessionToast.tsx index 2f710c8b9..aed2bf3df 100644 --- a/ts/components/basic/SessionToast.tsx +++ b/ts/components/basic/SessionToast.tsx @@ -18,7 +18,6 @@ export enum SessionToastType { type Props = { description: string; - id?: string; type?: SessionToastType; icon?: SessionIconType; @@ -28,7 +27,7 @@ type Props = { const DescriptionDiv = styled.div` font-size: var(--font-size-sm); - color: var(--text-secondary-color); + color: var(--text-primary-color); text-overflow: ellipsis; font-family: var(--font-default); padding-top: var(--margins-xs); diff --git a/ts/components/buttons/CopyToClipboardButton.tsx b/ts/components/buttons/CopyToClipboardButton.tsx index 943476f71..a9a308395 100644 --- a/ts/components/buttons/CopyToClipboardButton.tsx +++ b/ts/components/buttons/CopyToClipboardButton.tsx @@ -11,12 +11,13 @@ type CopyProps = { copyContent?: string; onCopyComplete?: (copiedValue: string | undefined) => void; hotkey?: boolean; + showToast?: boolean; }; type CopyToClipboardButtonProps = Omit & CopyProps; export const CopyToClipboardButton = (props: CopyToClipboardButtonProps) => { - const { copyContent, onCopyComplete, hotkey = false, text } = props; + const { copyContent, onCopyComplete, hotkey = false, text, showToast = true } = props; const [copied, setCopied] = useState(false); const onClick = () => { @@ -27,8 +28,9 @@ export const CopyToClipboardButton = (props: CopyToClipboardButtonProps) => { } clipboard.writeText(toCopy); - - ToastUtils.pushCopiedToClipBoard(); + if (showToast) { + ToastUtils.pushCopiedToClipBoard(); + } setCopied(true); if (onCopyComplete) { onCopyComplete(text); @@ -54,11 +56,13 @@ type CopyToClipboardIconProps = Omit { - const { copyContent, onCopyComplete, hotkey = false } = props; + const { copyContent, onCopyComplete, hotkey = false, showToast = true } = props; const onClick = () => { clipboard.writeText(copyContent); - ToastUtils.pushCopiedToClipBoard(); + if (showToast) { + ToastUtils.pushCopiedToClipBoard(); + } if (onCopyComplete) { onCopyComplete(copyContent); } diff --git a/ts/components/conversation/right-panel/overlay/OverlayRightPanelSettings.tsx b/ts/components/conversation/right-panel/overlay/OverlayRightPanelSettings.tsx index 33906be8d..0e40c0a04 100644 --- a/ts/components/conversation/right-panel/overlay/OverlayRightPanelSettings.tsx +++ b/ts/components/conversation/right-panel/overlay/OverlayRightPanelSettings.tsx @@ -1,5 +1,5 @@ import { compact, flatten, isEqual } from 'lodash'; -import { useEffect, useState } from 'react'; +import { SessionDataTestId, useEffect, useState } from 'react'; import { useDispatch } from 'react-redux'; import useInterval from 'react-use/lib/useInterval'; @@ -317,7 +317,7 @@ export const OverlayRightPanelSettings = () => { groupInfoActions.triggerFakeAvatarUpdate({ groupPk: selectedConvoKey }) as any ); }} - dataTestId="edit-group-name" + dataTestId={'' as SessionDataTestId} /> { }) as any ); }} - dataTestId="edit-group-name" + dataTestId={'' as SessionDataTestId} /> { }) as any ); }} - dataTestId="edit-group-name" + dataTestId={'' as SessionDataTestId} /> ) : null} diff --git a/ts/components/dialog/UpdateGroupNameDialog.tsx b/ts/components/dialog/UpdateGroupNameDialog.tsx index 410b214b4..56835bf52 100644 --- a/ts/components/dialog/UpdateGroupNameDialog.tsx +++ b/ts/components/dialog/UpdateGroupNameDialog.tsx @@ -189,6 +189,12 @@ export function UpdateGroupNameDialog(props: { conversationId: string }) { type="text" value={newGroupName} placeholder={window.i18n('groupNameEnter')} + onKeyDown={e => { + if (e.key === 'Enter') { + onClickOK(); + e.preventDefault(); + } + }} onChange={e => setNewGroupName(e.target.value)} tabIndex={0} required={true} diff --git a/ts/interactions/conversations/unsendingInteractions.ts b/ts/interactions/conversations/unsendingInteractions.ts index b7df6180d..d400bec5d 100644 --- a/ts/interactions/conversations/unsendingInteractions.ts +++ b/ts/interactions/conversations/unsendingInteractions.ts @@ -222,7 +222,8 @@ export async function deleteMessagesFromSwarmAndCompletelyLocally( conversation: ConversationModel, messages: Array ) { - const pubkey = conversation.id; + // If this is a private chat, we can only delete messages on our own swarm, so use our "side" of the conversation + const pubkey = conversation.isPrivate() ? UserUtils.getOurPubKeyStrFromCache() : conversation.id; if (!PubKey.is03Pubkey(pubkey) && !PubKey.is05Pubkey(pubkey)) { throw new Error('deleteMessagesFromSwarmAndCompletelyLocally needs a 03 or 05 pk'); } diff --git a/ts/session/apis/snode_api/swarm_polling_config/SwarmPollingGroupConfig.ts b/ts/session/apis/snode_api/swarm_polling_config/SwarmPollingGroupConfig.ts index 5ab2a9a60..e184ea310 100644 --- a/ts/session/apis/snode_api/swarm_polling_config/SwarmPollingGroupConfig.ts +++ b/ts/session/apis/snode_api/swarm_polling_config/SwarmPollingGroupConfig.ts @@ -18,6 +18,7 @@ import { ProfileManager } from '../../../profile_manager/ProfileManager'; import { UserUtils } from '../../../utils'; import { GroupSync } from '../../../utils/job_runners/jobs/GroupSyncJob'; import { destroyMessagesAndUpdateRedux } from '../../../disappearing_messages'; +import { ConversationTypeEnum } from '../../../../models/types'; /** * This is a basic optimization to avoid running the logic when the `deleteBeforeSeconds` @@ -163,11 +164,18 @@ async function handleMetaMergeResults(groupPk: GroupPubkeyType) { const member = members[index]; // if our DB doesn't have details about this user, set them. Otherwise we don't want to overwrite our changes with those // because they are most likely out of date from what we get from the user himself. - const memberConvo = ConvoHub.use().get(member.pubkeyHex); - if (!memberConvo) { + let memberConvoInDB = ConvoHub.use().get(member.pubkeyHex); + if (memberConvoInDB) { continue; } - if (member.name && member.name !== memberConvo.getRealSessionUsername()) { + if (!memberConvoInDB) { + // eslint-disable-next-line no-await-in-loop + memberConvoInDB = await ConvoHub.use().getOrCreateAndWait( + member.pubkeyHex, + ConversationTypeEnum.PRIVATE + ); + } + if (member.name && member.name !== memberConvoInDB.getRealSessionUsername()) { // eslint-disable-next-line no-await-in-loop await ProfileManager.updateProfileOfContact( member.pubkeyHex, diff --git a/ts/session/utils/job_runners/jobs/GroupInviteJob.ts b/ts/session/utils/job_runners/jobs/GroupInviteJob.ts index 0ad040cdd..85139edd0 100644 --- a/ts/session/utils/job_runners/jobs/GroupInviteJob.ts +++ b/ts/session/utils/job_runners/jobs/GroupInviteJob.ts @@ -303,6 +303,7 @@ export const GroupInvite = { GroupInviteJob, addJob, }; + function updateFailedStateForMember(groupPk: GroupPubkeyType, member: PubkeyType, failed: boolean) { let thisGroupFailure = invitesFailed.get(groupPk); diff --git a/ts/state/ducks/metaGroups.ts b/ts/state/ducks/metaGroups.ts index 3147dd894..f8afc823a 100644 --- a/ts/state/ducks/metaGroups.ts +++ b/ts/state/ducks/metaGroups.ts @@ -54,6 +54,7 @@ import { WithFromMemberLeftMessage, WithRemoveMembers, } from '../../session/types/with'; +import { updateGroupNameModal } from './modalDialog'; export type GroupState = { infos: Record; @@ -1152,6 +1153,7 @@ const currentDeviceGroupNameChange = createAsyncThunk( await checkWeAreAdminOrThrow(groupPk, 'currentDeviceGroupNameChange'); await handleNameChangeFromUI({ groupPk, ...args }); + window.inboxStore?.dispatch(updateGroupNameModal(null)); return { groupPk,