Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/frontend/src/components/ThreeDotMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { C } from '@deltachat/jsonrpc-client'
import React, { useContext } from 'react'

import { Timespans } from '../../../shared/constants'
Expand Down Expand Up @@ -44,7 +43,7 @@ export function useThreeDotMenu(selectedChat?: T.FullChat) {
id: chatId,
canSend,
} = selectedChat
const isGroup = selectedChat.chatType === C.DC_CHAT_TYPE_GROUP
const isGroup = selectedChat.chatType === 'Group'

const onLeaveGroup = () =>
selectedChat && openLeaveGroupOrChannelDialog(accountId, chatId, isGroup)
Expand Down Expand Up @@ -84,8 +83,8 @@ export function useThreeDotMenu(selectedChat?: T.FullChat) {
},
// See https://github.com/deltachat/deltachat-android/blob/fd4a377752cc6778f161590fde2f9ab29c5d3011/src/main/java/org/thoughtcrime/securesms/ConversationActivity.java#L445-L447.
canSend &&
selectedChat.chatType !== C.DC_CHAT_TYPE_IN_BROADCAST &&
selectedChat.chatType !== C.DC_CHAT_TYPE_MAILINGLIST &&
selectedChat.chatType !== 'InBroadcast' &&
selectedChat.chatType !== 'Mailinglist' &&
selectedChat.isEncrypted && {
label: tx('ephemeral_messages'),
action: onDisappearingMessages,
Expand Down
22 changes: 12 additions & 10 deletions packages/frontend/src/components/chat/ChatListContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useContext, useState } from 'react'
import { C } from '@deltachat/jsonrpc-client'

import { Timespans } from '../../../../shared/constants'
import { ContextMenuItem } from '../ContextMenu'
Expand Down Expand Up @@ -144,7 +143,9 @@ export function useChatListContextMenu(): {
accountId,
chatId
)
openViewGroupDialog(fullChat)
openViewGroupDialog(
fullChat as T.FullChat & { chatType: 'Group' | 'OutBroadcast' }
)
}
const onViewProfile = async (
chatId: (typeof chatListItems)[number]['id']
Expand All @@ -157,21 +158,23 @@ export function useChatListContextMenu(): {
throw new Error('chat was not found')
}
if (
fullChat.chatType !== C.DC_CHAT_TYPE_IN_BROADCAST &&
fullChat.chatType !== C.DC_CHAT_TYPE_MAILINGLIST
fullChat.chatType !== 'InBroadcast' &&
fullChat.chatType !== 'Mailinglist'
) {
openViewProfileDialog(accountId, fullChat.contactIds[0])
} else {
openDialog(MailingListProfile, {
chat: fullChat,
chat: fullChat as T.FullChat & {
chatType: 'InBroadcast' | 'Mailinglist'
},
})
}
}
const onLeaveGroupOrChannel = (chat: (typeof chatListItems)[number]) =>
openLeaveGroupOrChannelDialog(
accountId,
chat.id,
chat.chatType === C.DC_CHAT_TYPE_GROUP
chat.chatType === 'Group'
)
const onBlockContact = (chat: (typeof chatListItems)[number]) =>
openBlockFirstContactOfChatDialog(accountId, chat)
Expand All @@ -195,11 +198,10 @@ export function useChatListContextMenu(): {

const singleChat = chatListItems.length === 1 ? chatListItems[0] : false

const isGroup: boolean =
singleChat && singleChat.chatType === C.DC_CHAT_TYPE_GROUP
const isGroup: boolean = singleChat && singleChat.chatType === 'Group'

const isOutBroadcast: boolean =
singleChat && singleChat.chatType === C.DC_CHAT_TYPE_OUT_BROADCAST
singleChat && singleChat.chatType === 'OutBroadcast'

// TODO pluralize strings.
const viewCloneEncInfo = [
Expand Down Expand Up @@ -317,7 +319,7 @@ export function useChatListContextMenu(): {
//
// Leave channel
singleChat &&
singleChat.chatType === C.DC_CHAT_TYPE_IN_BROADCAST &&
singleChat.chatType === 'InBroadcast' &&
!singleChat.isContactRequest && {
label: tx('menu_leave_channel'),
action: () => onLeaveGroupOrChannel(singleChat),
Expand Down
3 changes: 1 addition & 2 deletions packages/frontend/src/components/chat/ChatListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,7 @@ export const ChatListItemMessageResult = React.memo<
displayName={msr.chatName}
/>
{!(
msr.chatType === C.DC_CHAT_TYPE_SINGLE &&
msr.authorId !== C.DC_CONTACT_ID_SELF
msr.chatType === 'Single' && msr.authorId !== C.DC_CONTACT_ID_SELF
) && (
<Avatar
className='small'
Expand Down
8 changes: 3 additions & 5 deletions packages/frontend/src/components/composer/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
useMemo,
useContext,
} from 'react'
import { C, T } from '@deltachat/jsonrpc-client'
import { T } from '@deltachat/jsonrpc-client'
import { extension } from 'mime-types'

import MenuAttachment from './menuAttachment'
Expand Down Expand Up @@ -456,7 +456,7 @@ const Composer = forwardRef<
<button
className='contact-request-button delete'
onClick={async () => {
if (selectedChat.chatType !== C.DC_CHAT_TYPE_SINGLE) {
if (selectedChat.chatType !== 'Single') {
// if chat gets deleted instead of blocked ask user for confirmation
if (
!(await confirmDialog(
Expand All @@ -473,9 +473,7 @@ const Composer = forwardRef<
unselectChat()
}}
>
{selectedChat.chatType === C.DC_CHAT_TYPE_SINGLE
? tx('block')
: tx('delete')}
{selectedChat.chatType === 'Single' ? tx('block') : tx('delete')}
</button>
<button
className='contact-request-button accept'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default function ChatAuditLogDialog(
privateReply,
accountId,
message,
selectedChat.chatType === C.DC_CHAT_TYPE_GROUP,
selectedChat.chatType === 'Group',
onClose
)

Expand Down
12 changes: 5 additions & 7 deletions packages/frontend/src/components/dialogs/MailingListProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import React from 'react'
import Dialog, { DialogBody, DialogContent, DialogHeader } from '../Dialog'
import useTranslationFunction from '../../hooks/useTranslationFunction'

import { C, type T } from '@deltachat/jsonrpc-client'
import { type T } from '@deltachat/jsonrpc-client'
import { DialogProps } from '../../contexts/DialogContext'
import ProfileInfoHeader from '../ProfileInfoHeader'
import { shouldDisableClickForFullscreen } from '../Avatar'

/**
* This dialog is used to display the profile of a mailing list
* (DC_CHAT_TYPE_MAILINGLIST) or a channel as seen by recipient.
* (DC_CHAT_TYPE_IN_BROADCAST)
* (chatType == 'Mailinglist') or a channel as seen by recipient.
* (chatType == 'InBroadcast')
*
* The main difference to other groups (which use ViewGroup):
* you don't see other receivers here and you can not edit the group.
*/
export default function MailingListProfile(
props: {
chat: T.BasicChat & {
chatType: C.DC_CHAT_TYPE_MAILINGLIST | C.DC_CHAT_TYPE_IN_BROADCAST
chatType: 'Mailinglist' | 'InBroadcast'
}
} & DialogProps
) {
Expand All @@ -28,9 +28,7 @@ export default function MailingListProfile(
const tx = useTranslationFunction()

const title =
chat.chatType === C.DC_CHAT_TYPE_MAILINGLIST
? tx('mailing_list')
: tx('channel')
chat.chatType === 'Mailinglist' ? tx('mailing_list') : tx('channel')

return (
<Dialog onClose={onClose} fixed>
Expand Down
6 changes: 3 additions & 3 deletions packages/frontend/src/components/dialogs/ViewGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const log = getLogger('ViewGroup')
* This dialog is used to for groups of various types:
* - encrypted groups
* - non encrypted groups (email groups)
* - channels if the current account is the sender (DC_CHAT_TYPE_OUT_BROADCAST)
* - channels if the current account is the sender (chatType == "OutBroadcast")
*
* Mailinglists and channels (receiver side) have an own dialog
* since you don't see other receivers in those chats
Expand Down Expand Up @@ -185,12 +185,12 @@ export const useGroup = (accountId: number, chat: T.FullChat) => {
function ViewGroupInner(
props: {
chat: T.FullChat & {
chatType: C.DC_CHAT_TYPE_GROUP | C.DC_CHAT_TYPE_OUT_BROADCAST
chatType: 'Group' | 'OutBroadcast'
}
} & DialogProps
) {
const { chat, onClose } = props
const isBroadcast = chat.chatType === C.DC_CHAT_TYPE_OUT_BROADCAST
const isBroadcast = chat.chatType === 'OutBroadcast'
const { openDialog } = useDialog()
const accountId = selectedAccountId()
const openConfirmationDialog = useConfirmationDialog()
Expand Down
5 changes: 2 additions & 3 deletions packages/frontend/src/components/message/EmptyChatMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useRef } from 'react'
import { C } from '@deltachat/jsonrpc-client'

import useTranslationFunction from '../../hooks/useTranslationFunction'

Expand All @@ -18,9 +17,9 @@ export default function EmptyChatMessage({ chat }: Props) {

let emptyChatMessage = tx('chat_new_one_to_one_hint', [chat.name, chat.name])

if (chat.chatType === C.DC_CHAT_TYPE_OUT_BROADCAST) {
if (chat.chatType === 'OutBroadcast') {
emptyChatMessage = tx('chat_new_channel_hint')
} else if (chat.chatType === C.DC_CHAT_TYPE_GROUP && !chat.isContactRequest) {
} else if (chat.chatType === 'Group' && !chat.isContactRequest) {
emptyChatMessage = chat.isUnpromoted
? tx('chat_new_group_hint')
: tx('chat_no_messages')
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ function buildContextMenu(

// Only show in groups, don't show on info messages or outgoing messages
const showReplyPrivately =
(conversationType.chatType === C.DC_CHAT_TYPE_GROUP ||
conversationType.chatType === C.DC_CHAT_TYPE_IN_BROADCAST) &&
(conversationType.chatType === 'Group' ||
conversationType.chatType === 'InBroadcast') &&
!message.isInfo &&
message.fromId > C.DC_CONTACT_ID_LAST_SPECIAL

Expand Down
15 changes: 3 additions & 12 deletions packages/frontend/src/components/message/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import React, {
} from 'react'
import classNames from 'classnames'
import moment from 'moment'
import { C } from '@deltachat/jsonrpc-client'
import { debounce } from 'debounce'

import { MessageWrapper } from './MessageWrapper'
Expand All @@ -34,14 +33,6 @@ import {
} from '../../contexts/RovingTabindex'
import { markChatAsSeen } from '../../backend/chat'

type ChatTypes =
| C.DC_CHAT_TYPE_SINGLE
| C.DC_CHAT_TYPE_GROUP
| C.DC_CHAT_TYPE_IN_BROADCAST
| C.DC_CHAT_TYPE_OUT_BROADCAST
| C.DC_CHAT_TYPE_MAILINGLIST
| C.DC_CHAT_TYPE_UNDEFINED

const onWindowFocus = (accountId: number) => {
log.debug('window focused')
const messageElements: HTMLElement[] = Array.prototype.slice.call(
Expand Down Expand Up @@ -737,7 +728,7 @@ export type ConversationType = {
/* whether this chat has multiple participants */
hasMultipleParticipants: boolean
isDeviceChat: boolean
chatType: ChatTypes
chatType: T.ChatType
}

export const MessageListInner = React.memo(
Expand Down Expand Up @@ -770,9 +761,9 @@ export const MessageListInner = React.memo(
} = props

const conversationType: ConversationType = {
hasMultipleParticipants: chat.chatType !== C.DC_CHAT_TYPE_SINGLE,
hasMultipleParticipants: chat.chatType !== 'Single',
isDeviceChat: chat.isDeviceChat as boolean,
chatType: chat.chatType as number,
chatType: chat.chatType,
}

useKeyBindingAction(KeybindAction.MessageList_PageUp, () => {
Expand Down
47 changes: 19 additions & 28 deletions packages/frontend/src/components/screens/MainScreen/MainScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,24 +339,21 @@ export default function MainScreen({ accountId }: Props) {
function chatSubtitle(chat: Type.FullChat) {
const tx = window.static_translate
if (chat.id && chat.id > C.DC_CHAT_ID_LAST_SPECIAL) {
if (chat.chatType === C.DC_CHAT_TYPE_GROUP) {
if (chat.chatType === 'Group') {
return tx('n_members', [String(chat.contactIds.length)], {
quantity: chat.contactIds.length,
})
} else if (
chat.chatType === C.DC_CHAT_TYPE_SINGLE &&
chat.contacts[0]?.isBot
) {
} else if (chat.chatType === 'Single' && chat.contacts[0]?.isBot) {
return tx('bot')
} else if (chat.chatType === C.DC_CHAT_TYPE_MAILINGLIST) {
} else if (chat.chatType === 'Mailinglist') {
if (chat.mailingListAddress) {
return `${tx('mailing_list')} – ${chat.mailingListAddress}`
} else {
return tx('mailing_list')
}
} else if (chat.chatType === C.DC_CHAT_TYPE_IN_BROADCAST) {
} else if (chat.chatType === 'InBroadcast') {
return tx('channel')
} else if (chat.chatType === C.DC_CHAT_TYPE_OUT_BROADCAST) {
} else if (chat.chatType === 'OutBroadcast') {
return tx('n_recipients', [String(chat.contactIds.length)], {
quantity: chat.contactIds.length,
})
Expand Down Expand Up @@ -384,16 +381,14 @@ function ChatHeading({ chat }: { chat: T.FullChat }) {
return
}

if (
chat.chatType === C.DC_CHAT_TYPE_IN_BROADCAST ||
chat.chatType === C.DC_CHAT_TYPE_MAILINGLIST
) {
openDialog(MailingListProfile, { chat })
} else if (
chat.chatType === C.DC_CHAT_TYPE_GROUP ||
chat.chatType === C.DC_CHAT_TYPE_OUT_BROADCAST
) {
openViewGroupDialog(chat)
if (chat.chatType === 'InBroadcast' || chat.chatType === 'Mailinglist') {
openDialog(MailingListProfile, {
chat: chat as T.FullChat & { chatType: 'InBroadcast' | 'Mailinglist' },
})
} else if (chat.chatType === 'Group' || chat.chatType === 'OutBroadcast') {
openViewGroupDialog(
chat as T.FullChat & { chatType: 'Group' | 'OutBroadcast' }
)
} else {
if (chat.contactIds && chat.contactIds[0]) {
openViewProfileDialog(accountId, chat.contactIds[0])
Expand All @@ -403,34 +398,30 @@ function ChatHeading({ chat }: { chat: T.FullChat }) {

let buttonLabel: string
switch (chat.chatType) {
case C.DC_CHAT_TYPE_SINGLE: {
case 'Single': {
buttonLabel = tx('menu_view_profile')
break
}
case C.DC_CHAT_TYPE_GROUP: {
case 'Group': {
// If you're no longer a member, editing the group is not possible,
// but we don't have a better string.
buttonLabel = tx('menu_edit_group')
break
}
case C.DC_CHAT_TYPE_OUT_BROADCAST: {
case 'OutBroadcast': {
buttonLabel = tx('edit_channel')
break
}
case C.DC_CHAT_TYPE_IN_BROADCAST: {
case 'InBroadcast': {
// We don't have a more appropriate one
buttonLabel = tx('menu_view_profile')
break
}
case C.DC_CHAT_TYPE_MAILINGLIST: {
case 'Mailinglist': {
// We don't have a more appropriate one
buttonLabel = tx('menu_view_profile')
break
}
case C.DC_CHAT_TYPE_UNDEFINED: {
buttonLabel = tx('menu_view_profile')
break
}
default: {
buttonLabel = tx('menu_view_profile')
log.warn(`Unknown chatType ${chat.chatType}`)
Expand Down Expand Up @@ -536,7 +527,7 @@ function ChatNavButtons({
// Core only allows placing calls in chats of type "single"
// (but not e.g. in groups consisting of 2 members).
// https://github.com/chatmail/core/blob/738dc5ce197f589131479801db2fbd0fb0964599/src/calls.rs#L147
chat.chatType === C.DC_CHAT_TYPE_SINGLE &&
chat.chatType === "Single" &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
chat.chatType === "Single" &&
chat.chatType === 'Single' &&

This will fix all lint warnings.

chat.contactIds.some(id => id > C.DC_CONTACT_ID_LAST_SPECIAL) && (
<Button
aria-label={tx('start_call')}
Expand Down
Loading
Loading