Skip to content

Commit d6c8411

Browse files
authored
Don't show add contact manually (by mail) in groups (#5363)
1 parent 4cb76bd commit d6c8411

File tree

5 files changed

+49
-18
lines changed

5 files changed

+49
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
### Added
99

1010
### Fixed
11-
11+
- don't show "add contact manually" (by email address) for groups #5336
1212
- Make `Archived Chats` title non selectable
1313

1414
<a id="2_8_0"></a>

packages/frontend/src/components/chat/ChatList.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import type {
4848
import { isInviteLink } from '../../../../shared/util'
4949
import { RovingTabindexProvider } from '../../contexts/RovingTabindex'
5050
import { useRpcFetch } from '../../hooks/useFetch'
51+
import { useSettingsStore } from '../../stores/settings'
5152

5253
const enum LoadStatus {
5354
FETCHING = 1,
@@ -202,6 +203,9 @@ export default function ChatList(props: {
202203
const tabindexWrapperElementContacts = useRef<HTMLDivElement>(null)
203204
const tabindexWrapperElementMessages = useRef<HTMLDivElement>(null)
204205

206+
const settingsStore = useSettingsStore()[0]
207+
const isChatmail = settingsStore?.settings.is_chatmail === '1'
208+
205209
const addContactOnClick = async () => {
206210
if (!queryStrIsValidEmail || !queryStr) return
207211

@@ -526,7 +530,8 @@ export default function ChatList(props: {
526530
>
527531
{ChatListItemRowContact}
528532
</ChatListPart>
529-
{contactIds.length === 0 &&
533+
{!isChatmail &&
534+
contactIds.length === 0 &&
530535
chatListIds.length === 0 &&
531536
queryStrIsValidEmail && (
532537
<PseudoListItemAddContact

packages/frontend/src/components/dialogs/AddMember/AddMemberDialog.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AddMemberInnerDialog } from './AddMemberInnerDialog'
33
import { useLazyLoadedContacts } from '../../contact/ContactList'
44
import Dialog from '../../Dialog'
55
import Icon from '../../Icon'
6-
import type { T } from '@deltachat/jsonrpc-client'
6+
import { C, type T } from '@deltachat/jsonrpc-client'
77
import type { DialogProps } from '../../../contexts/DialogContext'
88
import { Avatar } from '../../Avatar'
99
import styles from './styles.module.scss'
@@ -32,6 +32,10 @@ export function AddMemberDialog({
3232
queryStrIsValidEmail,
3333
refreshContacts,
3434
} = useLazyLoadedContacts(listFlags, queryStr)
35+
36+
// compare bitwise if address flag is set
37+
const allowAddManually = (listFlags & C.DC_GCL_ADDRESS) !== 0
38+
3539
return (
3640
<Dialog
3741
canOutsideClickClose={false}
@@ -59,6 +63,7 @@ export function AddMemberDialog({
5963
groupMembers,
6064
titleMembersOrRecipients,
6165
isVerificationRequired,
66+
allowAddManually,
6267
})}
6368
</Dialog>
6469
)

packages/frontend/src/components/dialogs/AddMember/AddMemberInnerDialog.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export function AddMemberInnerDialog({
3939
groupMembers,
4040
titleMembersOrRecipients,
4141
isVerificationRequired = false,
42+
allowAddManually,
4243
}: {
4344
onOk: (addMembers: number[]) => void
4445
onCancel: Parameters<typeof OkCancelFooterAction>[0]['onCancel']
@@ -54,6 +55,7 @@ export function AddMemberInnerDialog({
5455
groupMembers: number[]
5556
titleMembersOrRecipients: 'members' | 'recipients'
5657
isVerificationRequired: boolean
58+
allowAddManually: boolean
5759
}) {
5860
const tx = useTranslationFunction()
5961
const { openDialog } = useDialog()
@@ -157,8 +159,9 @@ export function AddMemberInnerDialog({
157159
useLayoutEffect(applyCSSHacks, [inputRef, contactIdsToAdd])
158160
useEffect(applyCSSHacks, [])
159161

160-
const showAddContact = queryStr !== '' && contactIds.length === 0
161-
const itemCount = contactIds.length + (showAddContact ? 1 : 0)
162+
const showAddContactManually =
163+
queryStr !== '' && contactIds.length === 0 && allowAddManually
164+
const itemCount = contactIds.length + (showAddContactManually ? 1 : 0)
162165

163166
const addContactOnKeyDown = (ev: React.KeyboardEvent<HTMLInputElement>) => {
164167
if (ev.key === 'Enter') {

packages/frontend/src/components/dialogs/CreateChat/index.tsx

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import Dialog, {
3535
FooterActionButton,
3636
FooterActions,
3737
} from '../../Dialog'
38-
import { ScreenContext } from '../../../contexts/ScreenContext'
3938
import useChat from '../../../hooks/chat/useChat'
4039
import useConfirmationDialog from '../../../hooks/dialog/useConfirmationDialog'
4140
import useCreateChatByContactId from '../../../hooks/chat/useCreateChatByContactId'
@@ -48,6 +47,8 @@ import {
4847
import { dirname } from 'path'
4948
import QrCode from '../QrCode'
5049
import { areAllContactsVerified } from '../../../backend/chat'
50+
import AlertDialog from '../AlertDialog'
51+
import { unknownErrorToString } from '../../helpers/unknownErrorToString'
5152

5253
import type { T } from '@deltachat/jsonrpc-client'
5354
import type { DialogProps } from '../../../contexts/DialogContext'
@@ -161,7 +162,6 @@ type CreateChatMainProps = {
161162
function CreateChatMain(props: CreateChatMainProps) {
162163
const { setViewMode, onClose } = props
163164
const tx = useTranslationFunction()
164-
const { userFeedback } = useContext(ScreenContext)
165165
const openConfirmationDialog = useConfirmationDialog()
166166
const accountId = selectedAccountId()
167167
const { openDialog } = useDialog()
@@ -180,9 +180,9 @@ function CreateChatMain(props: CreateChatMainProps) {
180180
try {
181181
await createChatByContactId(accountId, id)
182182
} catch (error: any) {
183-
return userFeedback({
184-
type: 'error',
185-
text: error && (error.message || error),
183+
const errorMessage = unknownErrorToString(error)
184+
openDialog(AlertDialog, {
185+
message: tx('error_x', errorMessage),
186186
})
187187
}
188188
onClose()
@@ -202,6 +202,7 @@ function CreateChatMain(props: CreateChatMainProps) {
202202
const showNewEmail = !isChatmail && queryStr.length === 0
203203

204204
const showAddContact = !(
205+
isChatmail ||
205206
queryStr === '' ||
206207
(contactIds.length === 1 &&
207208
contactCache[contactIds[0]]?.address.toLowerCase() ===
@@ -246,13 +247,20 @@ function CreateChatMain(props: CreateChatMainProps) {
246247
const addContactOnClick = async () => {
247248
if (!queryStrIsValidEmail) return
248249

249-
const contactId = await BackendRemote.rpc.createContact(
250-
accountId,
251-
queryStr.trim(),
252-
null
253-
)
254-
await createChatByContactId(accountId, contactId)
255-
onClose()
250+
try {
251+
const contactId = await BackendRemote.rpc.createContact(
252+
accountId,
253+
queryStr.trim(),
254+
null
255+
)
256+
await createChatByContactId(accountId, contactId)
257+
onClose()
258+
} catch (error: any) {
259+
const errorMessage = unknownErrorToString(error)
260+
openDialog(AlertDialog, {
261+
message: tx('error_x', errorMessage),
262+
})
263+
}
256264
}
257265

258266
const { openContextMenu } = useContext(ContextMenuContext)
@@ -966,6 +974,8 @@ function useCreateGroup<
966974
groupMembers: number[]
967975
) {
968976
const accountId = selectedAccountId()
977+
const { openDialog } = useDialog()
978+
const tx = useTranslationFunction()
969979

970980
type ChatId = T.BasicChat['id']
971981
const createGroup = useCallback(async () => {
@@ -1017,7 +1027,15 @@ function useCreateGroup<
10171027
return
10181028
}
10191029

1020-
return createGroup()
1030+
try {
1031+
return await createGroup()
1032+
} catch (error) {
1033+
const errorMessage = unknownErrorToString(error)
1034+
openDialog(AlertDialog, {
1035+
message: tx('error_x', errorMessage),
1036+
})
1037+
return null
1038+
}
10211039
}
10221040
}
10231041

0 commit comments

Comments
 (0)