Skip to content

Commit

Permalink
feat: add "related chats" to group profile (#3379)
Browse files Browse the repository at this point in the history
* Add related chats to group profile

* Rename from "Shared Chats" into "Related Chats" in the group profile
and add a translation string

* fix css bug

* changelog entry

* adapt to breaking change in core 123

* diable by default and add a switch for it
in settings

---------

Co-authored-by: SimonLaux <[email protected]>
  • Loading branch information
link2xt and Simon-Laux authored Sep 29, 2023
1 parent 7bbe47a commit a9aba5e
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Added
- mark webxdc app context as secure #3413
- Experimental: Related Chats

### Changed
- update deltachat-node and deltachat/jsonrpc-client to `v1.123.0`
Expand All @@ -22,6 +23,7 @@

### Added
- Show video chat instance URLs as subtitles #3369
- Add similar chats to group profile #3379

### Changed
- Offer to copy non-HTTP links to the clipboard instead of trying to open them in webxdc source code link and inside of html emails.
Expand Down
3 changes: 3 additions & 0 deletions _locales/_untranslated_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@
},
"desktop_offer_copy_non_web_link_to_clipboard": {
"message": "The link \"%1$d\" can not be opened in the web browser. Do you want to copy the link to the clipboard instead?"
},
"group_related_chats": {
"message": "Related Chats"
}
}
5 changes: 5 additions & 0 deletions scss/dialogs/_group-styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ div.group-member-contact-list-wrapper {
margin-right: -20px;
}

div.group-related-chats-list-wrapper {
margin-left: -20px;
margin-bottom: -20px;
}

div.group-image-wrapper {
position: relative;
div.group-image-edit-button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export function SettingsExperimentalFeatures({
label: tx('menu_chat_audit_log'),
description: tx('chat_audit_log_description'),
})}
{renderDTSettingSwitch({
key: 'EnableRelatedChats',
label: tx('group_related_chats'),
})}
{renderDTSettingSwitch({
key: 'experimentalEnableMarkdownInMessages',
label: 'Render Markdown in Messages',
Expand Down
60 changes: 60 additions & 0 deletions src/renderer/components/dialogs/ViewGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import {
DeltaDialogBody,
DeltaDialogOkCancelFooter,
} from './DeltaDialog'
import ChatListItem from '../chat/ChatListItem'
import { useContactSearch, AddMemberInnerDialog } from './CreateChat'
import { QrCodeShowQrInner } from './QrCode'
import { selectChat } from '../helpers/ChatMethods'
import { useThemeCssVar } from '../../ThemeManager'
import { ContactList2, useContactsMap } from '../contact/ContactList'
import { useLogicVirtualChatList, ChatListPart } from '../chat/ChatList'
import {
PseudoListItemShowQrCode,
PseudoListItemAddMember,
Expand All @@ -31,6 +35,7 @@ import { selectedAccountId } from '../../ScreenController'
import { modifyGroup } from '../helpers/ChatMethods'
import { DcEventType } from '@deltachat/jsonrpc-client'
import { InlineVerifiedIcon } from '../VerifiedIcon'
import { useSettingsStore } from '../../stores/settings'

const log = getLogger('renderer/ViewGroup')

Expand Down Expand Up @@ -135,6 +140,23 @@ function ViewGroupInner(props: {
const { openDialog } = useContext(ScreenContext)
const { onClose, chat, isBroadcast } = props
const tx = useTranslationFunction()
const [settings] = useSettingsStore()
const isRelatedChatsEnabled =
settings?.desktopSettings.EnableRelatedChats || false

const [chatListIds, setChatListIds] = useState<number[]>([])

useEffect(() => {
if (isRelatedChatsEnabled)
BackendRemote.rpc
.getSimilarChatIds(selectedAccountId(), chat.id)
.then(chatIds => setChatListIds(chatIds))
}, [chat.id, isRelatedChatsEnabled])

const { isChatLoaded, loadChats, chatCache } = useLogicVirtualChatList(
chatListIds,
null
)

const chatDisabled = !chat.canSend

Expand Down Expand Up @@ -207,6 +229,14 @@ function ViewGroupInner(props: {
null
)

const onChatClick = (chatId: number) => {
selectChat(chatId)
onClose()
}

const CHATLISTITEM_CHAT_HEIGHT =
Number(useThemeCssVar('--SPECIAL-chatlist-item-chat-height')) || 64

return (
<>
{!profileContact && (
Expand Down Expand Up @@ -238,6 +268,36 @@ function ViewGroupInner(props: {
{groupName} {chat.isProtected && <InlineVerifiedIcon />}
</p>
</div>
{isRelatedChatsEnabled && (
<>
<div className='group-separator'>
{tx('group_related_chats')}
</div>
<div className='group-related-chats-list-wrapper'>
<ChatListPart
isRowLoaded={isChatLoaded}
loadMoreRows={loadChats}
rowCount={chatListIds.length}
width={400}
height={CHATLISTITEM_CHAT_HEIGHT * chatListIds.length}
itemKey={index => 'key' + chatListIds[index]}
itemHeight={CHATLISTITEM_CHAT_HEIGHT}
>
{({ index, style }) => {
const chatId = chatListIds[index]
return (
<div style={style}>
<ChatListItem
chatListItem={chatCache[chatId] || undefined}
onClick={onChatClick.bind(null, chatId)}
/>
</div>
)
}}
</ChatListPart>
</div>
</>
)}
<div className='group-separator'>
{!isBroadcast
? tx(
Expand Down
1 change: 1 addition & 0 deletions src/shared/shared-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface DesktopSettingsType {
HTMLEmailAskForRemoteLoadingConfirmation: boolean
/** always loads remote content without asking, for non contact requests */
HTMLEmailAlwaysLoadRemoteContent: boolean
EnableRelatedChats: boolean
}

export interface RC_Config {
Expand Down
1 change: 1 addition & 0 deletions src/shared/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export function getDefaultState(): DesktopSettingsType {
enableWebxdcDevTools: false,
HTMLEmailAskForRemoteLoadingConfirmation: true,
HTMLEmailAlwaysLoadRemoteContent: false,
EnableRelatedChats: false,
}
}

0 comments on commit a9aba5e

Please sign in to comment.