Skip to content

Commit af7e222

Browse files
nicodhWofWca
andcommitted
Add missing tasks (#5307)
* Hide "add member" and "show QR invite" buttons for non pgp groups * Hide edit group * Don't show "block contact" in own channel * refactor: better types for "view chat" dialogs (#5309) --------- Co-authored-by: WofWca <[email protected]>
1 parent a36f56f commit af7e222

File tree

3 files changed

+67
-17
lines changed

3 files changed

+67
-17
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ export function useChatListContextMenu(): {
160160

161161
const isGroup = chatListItem.chatType === C.DC_CHAT_TYPE_GROUP
162162

163+
const isOutBroadcast =
164+
chatListItem.chatType === C.DC_CHAT_TYPE_OUT_BROADCAST
165+
163166
const menu: (ContextMenuItem | false)[] = chatListItem
164167
? [
165168
// Pin
@@ -245,15 +248,23 @@ export function useChatListContextMenu(): {
245248
label: tx('menu_view_profile'),
246249
action: onViewProfile,
247250
},
251+
// View Group Profile (for non encrypted groups)
252+
isGroup &&
253+
!chatListItem.isEncrypted &&
254+
chatListItem.isSelfInGroup && {
255+
label: tx('menu_view_profile'),
256+
action: onViewGroup,
257+
},
248258
// Edit Group
249259
isGroup &&
260+
chatListItem.isEncrypted &&
250261
chatListItem.isSelfInGroup && {
251262
label: tx('menu_edit_group'),
252263
dataTestid: 'edit-group',
253264
action: onViewGroup,
254265
},
255266
// Edit Channel
256-
chatListItem.chatType === C.DC_CHAT_TYPE_OUT_BROADCAST && {
267+
isOutBroadcast && {
257268
label: tx('edit_channel'),
258269
action: onViewGroup,
259270
},
@@ -283,13 +294,18 @@ export function useChatListContextMenu(): {
283294
},
284295
// Leave group
285296
isGroup &&
297+
chatListItem.isEncrypted &&
286298
chatListItem.isSelfInGroup && {
287299
label: tx('menu_leave_group'),
288300
action: onLeaveGroupOrChannel,
289301
},
290302
// Block contact
291303
!isGroup &&
292-
!(chatListItem.isSelfTalk || chatListItem.isDeviceTalk) && {
304+
!(
305+
chatListItem.isSelfTalk ||
306+
chatListItem.isDeviceTalk ||
307+
isOutBroadcast
308+
) && {
293309
label: tx('menu_block_contact'),
294310
action: onBlockContact,
295311
},

packages/frontend/src/components/dialogs/MailingListProfile.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ import ProfileInfoHeader from '../ProfileInfoHeader'
1414

1515
/**
1616
* This dialog is used to display the profile of a mailing list
17-
* or a channel (DC_CHAT_TYPE_IN_BROADCAST as seen by recipient).
17+
* (DC_CHAT_TYPE_MAILINGLIST) or a channel as seen by recipient.
18+
* (DC_CHAT_TYPE_IN_BROADCAST)
19+
*
20+
* The main difference to other groups (which use ViewGroup):
21+
* you don't see other receivers here and you can not edit the group.
1822
*/
1923
export default function MailingListProfile(
2024
props: {
21-
chat: T.BasicChat
25+
chat: T.BasicChat & {
26+
chatType: C.DC_CHAT_TYPE_MAILINGLIST | C.DC_CHAT_TYPE_IN_BROADCAST
27+
}
2228
} & DialogProps
2329
) {
2430
const { onClose, chat } = props

packages/frontend/src/components/dialogs/ViewGroup.tsx

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,19 @@ import { unknownErrorToString } from '../helpers/unknownErrorToString'
4242
import { getLogger } from '@deltachat-desktop/shared/logger'
4343
const log = getLogger('ViewGroup')
4444

45+
/**
46+
* This dialog is used to for groups of various types:
47+
* - encrypted groups
48+
* - non encrypted groups (email groups)
49+
* - channels if the current account is the sender (DC_CHAT_TYPE_OUT_BROADCAST)
50+
*
51+
* Mailinglists and channels (receiver side) have an own dialog
52+
* since you don't see other receivers in those chats
53+
* (see MailingListProfile)
54+
*/
4555
export default function ViewGroup(
4656
props: {
47-
chat: T.FullChat
57+
chat: Parameters<typeof ViewGroupInner>[0]['chat']
4858
} & DialogProps
4959
) {
5060
const { chat, onClose } = props
@@ -173,7 +183,9 @@ export const useGroup = (accountId: number, chat: T.FullChat) => {
173183

174184
function ViewGroupInner(
175185
props: {
176-
chat: T.FullChat
186+
chat: T.FullChat & {
187+
chatType: C.DC_CHAT_TYPE_GROUP | C.DC_CHAT_TYPE_OUT_BROADCAST
188+
}
177189
} & DialogProps
178190
) {
179191
const { chat, onClose } = props
@@ -298,7 +310,7 @@ function ViewGroupInner(
298310
groupImage,
299311
groupColor: chat.color,
300312
onOk: (groupName: string, groupImage: string | null) => {
301-
//(treefit): TODO this check should be way earlier, you should not be able to "OK" the dialog if there is no group name
313+
// TODO this check should be way earlier, you should not be able to "OK" the dialog if there is no group name
302314
if (groupName.length > 1) {
303315
setGroupName(groupName)
304316
}
@@ -309,15 +321,22 @@ function ViewGroupInner(
309321
})
310322
}
311323

312-
// Note that this might also need `C.DC_GCL_ADDRESS` for unencrypted groups,
313-
// but we're not supposed to display this component for those.
314324
const listFlags = C.DC_GCL_ADD_SELF
315325

316326
// Note that we are not checking `chat.isEncrypted`,
317327
// unlike in "New E-Mail" dialog.
318328
// See https://github.com/deltachat/deltachat-desktop/issues/5294
319329
// > the chat itself picks up "group wording"
320330
const membersOrRecipients = isBroadcast ? 'recipients' : 'members'
331+
332+
// We don't allow editing of non encryped groups (email groups)
333+
// i.e. changing name, avatar or recipients
334+
// since it cannot be guaranteed that the recipients will adapt
335+
// these changes (image is not shown at all in MTAs, group name is
336+
// just the subject and recipients are basically just an email
337+
// distribution list)
338+
const allowEdit = !chatDisabled && group.isEncrypted
339+
321340
const showAddMemberDialog = () => {
322341
openDialog(AddMemberDialog, {
323342
listFlags,
@@ -355,12 +374,21 @@ function ViewGroupInner(
355374
<>
356375
{!profileContact && (
357376
<>
358-
<DialogHeader
359-
title={!isBroadcast ? tx('tab_group') : tx('channel')}
360-
onClickEdit={onClickEdit}
361-
onClose={onClose}
362-
dataTestid='view-group-dialog-header'
363-
/>
377+
{allowEdit && (
378+
<DialogHeader
379+
title={!isBroadcast ? tx('tab_group') : tx('channel')}
380+
onClickEdit={onClickEdit}
381+
onClose={onClose}
382+
dataTestid='view-group-dialog-header'
383+
/>
384+
)}
385+
{!allowEdit && (
386+
<DialogHeader
387+
title={tx('tab_group')}
388+
onClose={onClose}
389+
dataTestid='view-group-dialog-header'
390+
/>
391+
)}
364392
<DialogBody>
365393
<DialogContent paddingBottom>
366394
<ProfileInfoHeader
@@ -431,7 +459,7 @@ function ViewGroupInner(
431459
<RovingTabindexProvider
432460
wrapperElementRef={groupMemberContactListWrapperRef}
433461
>
434-
{!chatDisabled && (
462+
{!chatDisabled && group.isEncrypted && (
435463
<>
436464
<PseudoListItemAddMember
437465
onClick={() => showAddMemberDialog()}
@@ -446,7 +474,7 @@ function ViewGroupInner(
446474
)}
447475
<ContactList
448476
contacts={group.contacts}
449-
showRemove={!chatDisabled}
477+
showRemove={!chatDisabled && group.isEncrypted}
450478
onClick={contact => {
451479
if (contact.id === C.DC_CONTACT_ID_SELF) {
452480
return

0 commit comments

Comments
 (0)