From 79aca9c2313e01613a7775fd861fb891db35f707 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 15 Jul 2024 11:41:00 +1000 Subject: [PATCH] fix: open url confirm is Primary color and not destructive also delete all messages when reinvited to a group we were kicked from --- _locales/en/messages.json | 3 ++- ts/components/conversation/SessionConversation.tsx | 6 ++++-- ts/components/dialog/SessionConfirm.tsx | 8 +++++++- ts/interactions/conversations/unsendingInteractions.ts | 2 +- ts/models/conversation.ts | 2 +- ts/receiver/closedGroups.ts | 2 +- ts/receiver/groupv2/handleGroupV2Message.ts | 10 +++++++++- .../utils/job_runners/jobs/GroupPendingRemovalsJob.ts | 2 +- ts/types/LocalizerKeys.ts | 2 ++ 9 files changed, 28 insertions(+), 9 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 745dea777..d498763cd 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -494,8 +494,9 @@ "device": "Device", "destination": "Destination", "learnMore": "Learn more", - "linkVisitWarningTitle": "Open this link in your browser?", + "linkVisitWarningTitle": "Open URL", "linkVisitWarningMessage": "Are you sure you want to open $url$ in your browser?", + "copyUrl": "Copy URL", "open": "Open", "audioMessageAutoplayTitle": "Autoplay Audio Messages", "audioMessageAutoplayDescription": "Autoplay consecutive audio messages.", diff --git a/ts/components/conversation/SessionConversation.tsx b/ts/components/conversation/SessionConversation.tsx index 60fe629c0..73b789059 100644 --- a/ts/components/conversation/SessionConversation.tsx +++ b/ts/components/conversation/SessionConversation.tsx @@ -59,6 +59,8 @@ import { NoticeBanner } from '../NoticeBanner'; import { SessionSpinner } from '../basic/SessionSpinner'; import { ConversationMessageRequestButtons } from './MessageRequestButtons'; import { RightPanel, StyledRightPanelContainer } from './right-panel/RightPanel'; +import { showLinkVisitWarningDialog } from '../dialog/SessionConfirm'; +import { useDispatch } from 'react-redux'; const DEFAULT_JPEG_QUALITY = 0.85; interface State { @@ -671,7 +673,7 @@ function OutdatedLegacyGroupBanner(props: { selectedConversation: Pick; }) { const { selectedConversation } = props; - // const dispatch = useDispatch(); + const dispatch = useDispatch(); const isLegacyGroup = !selectedConversation.isPrivate && @@ -682,7 +684,7 @@ function OutdatedLegacyGroupBanner(props: { { - // showLinkVisitWarningDialog('', dispatch); + showLinkVisitWarningDialog('', dispatch); throw new Error('TODO'); // fixme audric }} icon="externalLink" diff --git a/ts/components/dialog/SessionConfirm.tsx b/ts/components/dialog/SessionConfirm.tsx index 229a905ff..32e0d8a2b 100644 --- a/ts/components/dialog/SessionConfirm.tsx +++ b/ts/components/dialog/SessionConfirm.tsx @@ -219,18 +219,24 @@ export const SessionConfirm = (props: SessionConfirmDialogProps) => { ); }; + + + + export const showLinkVisitWarningDialog = (urlToOpen: string, dispatch: Dispatch) => { function onClickOk() { void shell.openExternal(urlToOpen); } + + dispatch( updateConfirmModal({ title: window.i18n('linkVisitWarningTitle'), message: window.i18n('linkVisitWarningMessage', [urlToOpen]), okText: window.i18n('open'), okTheme: SessionButtonColor.Primary, - cancelText: window.i18n('editMenuCopy'), + cancelText: window.i18n('copyUrl'), showExitIcon: true, onClickOk, onClickClose: () => { diff --git a/ts/interactions/conversations/unsendingInteractions.ts b/ts/interactions/conversations/unsendingInteractions.ts index 7e982c4c4..76b03c341 100644 --- a/ts/interactions/conversations/unsendingInteractions.ts +++ b/ts/interactions/conversations/unsendingInteractions.ts @@ -87,7 +87,7 @@ export async function unsendMessagesForEveryoneGroupV2({ await getMessageQueue().sendToGroupV2NonDurably({ message: new GroupUpdateDeleteMemberContentMessage({ createAtNetworkTimestamp: GetNetworkTime.now(), - expirationType: 'unknown', // this is not displayed so not expiring. + expirationType: 'unknown', // GroupUpdateDeleteMemberContentMessage is not displayed so not expiring. expireTimer: 0, groupPk, memberSessionIds: allMessagesFrom, diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 4860e1c61..7e86e7387 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -1101,7 +1101,7 @@ export class ConversationModel extends Backbone.Model { if (this.isClosedGroup()) { if (this.isAdmin(UserUtils.getOurPubKeyStrFromCache())) { if (this.isClosedGroupV2()) { - if (!PubKey.is03Pubkey(this.id)) { + if (!PubKey.is03Pubkey(this.id)) { throw new Error('updateExpireTimer v2 group requires a 03 key'); } const group = await UserGroupsWrapperActions.getGroup(this.id); diff --git a/ts/receiver/closedGroups.ts b/ts/receiver/closedGroups.ts index 049c53af7..b1b649068 100644 --- a/ts/receiver/closedGroups.ts +++ b/ts/receiver/closedGroups.ts @@ -357,7 +357,7 @@ export async function handleNewClosedGroup( members, admins, activeAt: envelopeTimestamp, - expirationType: 'unknown', + expirationType: 'unknown', // group creation message, is not expiring expireTimer: 0, }; diff --git a/ts/receiver/groupv2/handleGroupV2Message.ts b/ts/receiver/groupv2/handleGroupV2Message.ts index bbb05a910..32b44ef70 100644 --- a/ts/receiver/groupv2/handleGroupV2Message.ts +++ b/ts/receiver/groupv2/handleGroupV2Message.ts @@ -30,6 +30,7 @@ import { UserGroupsWrapperActions, } from '../../webworker/workers/browser/libsession_worker_interface'; import { WithMessageHash } from '../../session/types/with'; +import { deleteAllMessagesByConvoIdNoConfirmation } from '../../interactions/conversationInteractions'; type WithSignatureTimestamp = { signatureTimestamp: number }; type WithAuthor = { author: PubkeyType }; @@ -66,7 +67,7 @@ async function sendInviteResponseToGroup({ groupPk }: { groupPk: GroupPubkeyType groupPk, isApproved: true, createAtNetworkTimestamp: GetNetworkTime.now(), - expirationType: 'unknown', // an invite should not expire + expirationType: 'unknown', // an invite response should not expire expireTimer: 0, }), }); @@ -124,6 +125,7 @@ async function handleGroupInviteMessage({ const userEd25519Secretkey = (await UserUtils.getUserED25519KeyPairBytes()).privKeyBytes; let found = await UserGroupsWrapperActions.getGroup(groupPk); + const wasKicked = found?.kicked || false; if (!found) { found = { authData: null, @@ -153,6 +155,12 @@ async function handleGroupInviteMessage({ await SessionUtilConvoInfoVolatile.insertConvoFromDBIntoWrapperAndRefresh(convo.id); + if (wasKicked && !found.kicked) { + // we have been reinvited to a group which we had been kicked from. + // Let's empty the conversation again to remove any "you were removed from the group" control message + await deleteAllMessagesByConvoIdNoConfirmation(groupPk); + } + await MetaGroupWrapperActions.init(groupPk, { metaDumped: null, groupEd25519Secretkey: null, diff --git a/ts/session/utils/job_runners/jobs/GroupPendingRemovalsJob.ts b/ts/session/utils/job_runners/jobs/GroupPendingRemovalsJob.ts index 84adaf0af..b8cb17aa8 100644 --- a/ts/session/utils/job_runners/jobs/GroupPendingRemovalsJob.ts +++ b/ts/session/utils/job_runners/jobs/GroupPendingRemovalsJob.ts @@ -173,7 +173,7 @@ class GroupPendingRemovalsJob extends PersistedJob