From b64e8bf61001239c3cfc16c873b6666f4b4bf55b Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 21 Jun 2021 10:59:37 +1000 Subject: [PATCH] fix seed dialog and leave group as admin dialog --- _locales/en/messages.json | 1 + ts/components/EditProfileDialog.tsx | 55 ++++--------------- ts/components/OnionStatusDialog.tsx | 8 +-- ts/components/session/SessionSeedModal.tsx | 2 + .../conversation/SessionRightPanel.tsx | 3 +- ts/components/session/menu/Menu.tsx | 55 ++++--------------- ts/interactions/conversationInteractions.ts | 39 ++++++++++++- ts/receiver/closedGroups.ts | 2 - ts/state/ducks/modalDialog.tsx | 2 +- 9 files changed, 65 insertions(+), 102 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 6471725c8..690436a24 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -262,6 +262,7 @@ "blockUser": "Block", "unblockUser": "Unblock", "unblocked": "Unblocked", + "blocked": "Blocked", "blockedSettingsTitle": "Blocked contacts", "unbanUser": "Unban User", "unbanUserConfirm": "Are you sure you want to unban this user?", diff --git a/ts/components/EditProfileDialog.tsx b/ts/components/EditProfileDialog.tsx index 32120a42e..00e502a9a 100644 --- a/ts/components/EditProfileDialog.tsx +++ b/ts/components/EditProfileDialog.tsx @@ -52,41 +52,6 @@ export class EditProfileDialog extends React.Component<{}, State> { window.addEventListener('keyup', this.onKeyUp); } - public async componentDidMount() { - const ourNumber = window.storage.get('primaryDevicePubKey'); - const conversation = await ConversationController.getInstance().getOrCreateAndWait( - ourNumber, - ConversationTypeEnum.PRIVATE - ); - - const readFile = async (attachment: any) => - new Promise((resolve, reject) => { - const fileReader = new FileReader(); - fileReader.onload = (e: any) => { - const data = e.target.result; - resolve({ - ...attachment, - data, - size: data.byteLength, - }); - }; - fileReader.onerror = reject; - fileReader.onabort = reject; - fileReader.readAsArrayBuffer(attachment.file); - }); - - const avatarPath = conversation.getAvatarPath(); - const profile = conversation.getLokiProfile(); - const displayName = profile && profile.displayName; - - this.setState({ - ...this.state, - profileName: profile.profileName, - avatar: avatarPath || '', - setProfileName: profile.profileName, - }); - } - public render() { const i18n = window.i18n; @@ -179,9 +144,9 @@ export class EditProfileDialog extends React.Component<{}, State> { { - this.setState({ mode: 'qr' }); + this.setState(state => ({ ...state, mode: 'qr' })); }} /> @@ -192,16 +157,19 @@ export class EditProfileDialog extends React.Component<{}, State> { } private fireInputEvent() { - this.setState({ mode: 'edit' }, () => { - const el = this.inputEl.current; - if (el) { - el.click(); + this.setState( + state => ({ ...state, mode: 'edit' }), + () => { + const el = this.inputEl.current; + if (el) { + el.click(); + } } - }); + ); } private renderDefaultView() { - const name = this.state.setProfileName ? this.state.setProfileName : this.state.profileName; + const name = this.state.setProfileName || this.state.profileName; return ( <> {this.renderProfileHeader()} @@ -274,7 +242,6 @@ export class EditProfileDialog extends React.Component<{}, State> { private onNameEdited(event: any) { const newName = event.target.value.replace(window.displayNameRegex, ''); - this.setState(state => { return { ...state, diff --git a/ts/components/OnionStatusDialog.tsx b/ts/components/OnionStatusDialog.tsx index a3275c7a5..90c2685c4 100644 --- a/ts/components/OnionStatusDialog.tsx +++ b/ts/components/OnionStatusDialog.tsx @@ -20,12 +20,6 @@ import { useNetwork } from '../hooks/useNetwork'; import { Snode } from '../data/data'; import { onionPathModal } from '../state/ducks/modalDialog'; -export type OnionPathModalType = { - confirmText?: string; - cancelText?: string; - title?: string; -}; - export type StatusLightType = { glowStartDelay: number; glowDuration: number; @@ -168,7 +162,7 @@ export const ActionPanelOnionStatusLight = (props: { ); }; -export const OnionPathModal = (props: OnionPathModalType) => { +export const OnionPathModal = () => { const onConfirm = () => { void shell.openExternal('https://getsession.org/faq/#onion-routing'); }; diff --git a/ts/components/session/SessionSeedModal.tsx b/ts/components/session/SessionSeedModal.tsx index 0f4875a36..d6e32d0bc 100644 --- a/ts/components/session/SessionSeedModal.tsx +++ b/ts/components/session/SessionSeedModal.tsx @@ -111,6 +111,7 @@ class SessionSeedModalInner extends React.Component<{}, State> { const fgColor = '#1B1B1B'; const hexEncodedSeed = mn_decode(this.state.recoveryPhrase, 'english'); + const onClose = () => window.inboxStore?.dispatch(recoveryPhraseModal(null)); return ( <> @@ -132,6 +133,7 @@ class SessionSeedModalInner extends React.Component<{}, State> { this.copyRecoveryPhrase(this.state.recoveryPhrase); }} /> + ); diff --git a/ts/components/session/conversation/SessionRightPanel.tsx b/ts/components/session/conversation/SessionRightPanel.tsx index 84431d046..2f510191f 100644 --- a/ts/components/session/conversation/SessionRightPanel.tsx +++ b/ts/components/session/conversation/SessionRightPanel.tsx @@ -29,6 +29,7 @@ import { showInviteContactByConvoId, showLeaveGroupByConvoId, showRemoveModeratorsByConvoId, + showUpdateGroupMembersByConvoId, showUpdateGroupNameByConvoId, } from '../../../interactions/conversationInteractions'; @@ -326,7 +327,7 @@ class SessionRightPanel extends React.Component { className="group-settings-item" role="button" onClick={async () => { - await showUpdateGroupNameByConvoId(id); + await showUpdateGroupMembersByConvoId(id); }} > {window.i18n('groupMembers')} diff --git a/ts/components/session/menu/Menu.tsx b/ts/components/session/menu/Menu.tsx index 18e222924..09519cf9c 100644 --- a/ts/components/session/menu/Menu.tsx +++ b/ts/components/session/menu/Menu.tsx @@ -11,8 +11,6 @@ import { } from '../../../state/ducks/modalDialog'; import { ConversationController } from '../../../session/conversations'; import { UserUtils } from '../../../session/utils'; -import { AdminLeaveClosedGroupDialog } from '../../conversation/AdminLeaveClosedGroupDialog'; -import { useTheme } from 'styled-components'; import { blockConvoById, clearNickNameByConvoId, @@ -23,6 +21,7 @@ import { setNotificationForConvoId, showAddModeratorsByConvoId, showInviteContactByConvoId, + showLeaveGroupByConvoId, showRemoveModeratorsByConvoId, showUpdateGroupNameByConvoId, unblockConvoById, @@ -187,49 +186,17 @@ export function getLeaveGroupMenuItem( if ( showLeaveGroup(Boolean(isKickedFromGroup), Boolean(left), Boolean(isGroup), Boolean(isPublic)) ) { - const dispatch = useDispatch(); - const theme = useTheme(); - const conversation = ConversationController.getInstance().get(conversationId); - - const onClickClose = () => { - dispatch(updateConfirmModal(null)); - }; - - const openConfirmationModal = () => { - if (!conversation.isGroup()) { - throw new Error('showLeaveGroupDialog() called with a non group convo.'); - } - - const title = window.i18n('leaveGroup'); - const message = window.i18n('leaveGroupConfirmation'); - const ourPK = UserUtils.getOurPubKeyStrFromCache(); - const isAdmin = (conversation.get('groupAdmins') || []).includes(ourPK); - const isClosedGroup = conversation.get('is_medium_group') || false; - - // if this is not a closed group, or we are not admin, we can just show a confirmation dialog - if (!isClosedGroup || (isClosedGroup && !isAdmin)) { - dispatch( - updateConfirmModal({ - title, - message, - onClickOk: () => { - void conversation.leaveClosedGroup(); - onClickClose(); - }, - onClickClose, - }) - ); - } else { - dispatch( - adminLeaveClosedGroup({ - conversationId, - }) - ); - } - }; - - return {window.i18n('leaveGroup')}; + return ( + { + showLeaveGroupByConvoId(conversationId); + }} + > + {window.i18n('leaveGroup')} + + ); } + return null; } diff --git a/ts/interactions/conversationInteractions.ts b/ts/interactions/conversationInteractions.ts index 19bb60fb7..cc64f8443 100644 --- a/ts/interactions/conversationInteractions.ts +++ b/ts/interactions/conversationInteractions.ts @@ -4,7 +4,7 @@ import { openGroupV2ConversationIdRegex, } from '../opengroup/utils/OpenGroupUtils'; import { getV2OpenGroupRoom } from '../data/opengroups'; -import { ToastUtils } from '../session/utils'; +import { ToastUtils, UserUtils } from '../session/utils'; import { ConversationModel, ConversationNotificationSettingType, @@ -17,6 +17,7 @@ import _ from 'lodash'; import { ConversationController } from '../session/conversations'; import { BlockedNumberController } from '../util/blockedNumberController'; import { + adminLeaveClosedGroup, changeNickNameModal, updateAddModeratorsModal, updateConfirmModal, @@ -194,8 +195,40 @@ export async function showUpdateGroupMembersByConvoId(conversationId: string) { export function showLeaveGroupByConvoId(conversationId: string) { const conversation = ConversationController.getInstance().get(conversationId); - throw new Error('Audric TODO'); - window.Whisper.events.trigger('leaveClosedGroup', conversation); + + if (!conversation.isGroup()) { + throw new Error('showLeaveGroupDialog() called with a non group convo.'); + } + + const title = window.i18n('leaveGroup'); + const message = window.i18n('leaveGroupConfirmation'); + const ourPK = UserUtils.getOurPubKeyStrFromCache(); + const isAdmin = (conversation.get('groupAdmins') || []).includes(ourPK); + const isClosedGroup = conversation.get('is_medium_group') || false; + + // if this is not a closed group, or we are not admin, we can just show a confirmation dialog + if (!isClosedGroup || (isClosedGroup && !isAdmin)) { + const onClickClose = () => { + window.inboxStore?.dispatch(updateConfirmModal(null)); + }; + window.inboxStore?.dispatch( + updateConfirmModal({ + title, + message, + onClickOk: () => { + void conversation.leaveClosedGroup(); + onClickClose(); + }, + onClickClose, + }) + ); + } else { + window.inboxStore?.dispatch( + adminLeaveClosedGroup({ + conversationId, + }) + ); + } } export function showInviteContactByConvoId(conversationId: string) { window.inboxStore?.dispatch(updateInviteContactModal({ conversationId })); diff --git a/ts/receiver/closedGroups.ts b/ts/receiver/closedGroups.ts index 312045500..7bc5fd668 100644 --- a/ts/receiver/closedGroups.ts +++ b/ts/receiver/closedGroups.ts @@ -971,8 +971,6 @@ async function sendToGroupMembers( const inviteResults = await Promise.all(promises); const allInvitesSent = _.every(inviteResults, Boolean); - throw new Error('audric: TODEBUG'); - if (allInvitesSent) { // if (true) { if (isRetry) { diff --git a/ts/state/ducks/modalDialog.tsx b/ts/state/ducks/modalDialog.tsx index a7279afcf..9fba3bfa8 100644 --- a/ts/state/ducks/modalDialog.tsx +++ b/ts/state/ducks/modalDialog.tsx @@ -84,7 +84,7 @@ const ModalSlice = createSlice({ return { ...state, onionPathModal: action.payload }; }, recoveryPhraseModal(state, action: PayloadAction) { - return { ...state, onionPathModal: action.payload }; + return { ...state, recoveryPhraseModal: action.payload }; }, adminLeaveClosedGroup(state, action: PayloadAction) { return { ...state, adminLeaveClosedGroup: action.payload };