Skip to content

Commit

Permalink
Fix chat selection on create chat/verified group
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikstra committed Dec 9, 2019
1 parent a5926d4 commit d69cf7a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/renderer/components/chat/ChatList.js
Expand Up @@ -6,15 +6,14 @@ import { PseudoListItemAddContact } from '../helpers/PseudoListItem'
import C from 'deltachat-node/constants'
import { isValidEmail } from '../dialogs/CreateChat'
import { callDcMethodAsync } from '../../ipc'
import { useChatStore } from '../../stores/chat'
import { selectChat } from '../../stores/chat'

export default function ChatList (props) {
const { selectedChatId, showArchivedChats, onShowArchivedChats, queryStr } = props
const queryStrIsEmail = isValidEmail(queryStr)
const { chatListIds, setQueryStr, setListFlags } = useChatListIds()
const { chatItems, onChatListScroll, scrollRef } = useLazyChatListItems(chatListIds)
const realOpenContextMenu = useRef(null)
const chatStoreDispatch = useChatStore()[1]

const onChatClick = chatId => {
if (chatId === C.DC_CHAT_ID_ARCHIVED_LINK) return onShowArchivedChats()
Expand All @@ -35,7 +34,7 @@ export default function ChatList (props) {

const contactId = await callDcMethodAsync('contacts.createContact', [queryStr, queryStr])
const chatId = await callDcMethodAsync('contacts.createChatByContactId', contactId)
chatStoreDispatch({ type: 'SELECT_CHAT', payload: chatId })
selectChat(chatId)
}

const renderAddContactIfNeeded = () => {
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/components/dialogs/CreateChat.js
Expand Up @@ -6,6 +6,7 @@ import C from 'deltachat-node/constants'

import { callDcMethodAsync } from '../../ipc'
import ScreenContext from '../../contexts/ScreenContext'
import { selectChat } from '../../stores/chat'
import { useContacts, ContactList2 } from '../contact/ContactList'
import {
PseudoListItem,
Expand Down Expand Up @@ -41,9 +42,9 @@ export default function CreateChat (props) {
const [queryStr, onSearchChange] = useContactSearch(updateContacts)
const queryStrIsEmail = isValidEmail(queryStr)

const closeDialogAndSelectChat = async chatId => {
const closeDialogAndSelectChat = chatId => {
selectChat(chatId)
onClose()
await callDcMethodAsync('chatList.selectChat', [chatId])
}

const chooseContact = async ({ id }) => {
Expand Down Expand Up @@ -267,7 +268,7 @@ export const useCreateGroup = (verified, groupName, groupImage, groupMembers, on
if (groupName === '') return
const gId = await lazilyCreateOrUpdateGroup(true)
onClose()
await callDcMethodAsync('chatList.selectChat', [gId])
selectChat(gId)
}
return [groupId, lazilyCreateOrUpdateGroup, finishCreateGroup]
}
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/stores/chat.js
Expand Up @@ -234,4 +234,6 @@ ipcBackend.on('DC_EVENT_MSGS_CHANGED', async (_, [id, messageId]) => {
})

export const useChatStore = () => useStore(chatStore)
export const selectChat = chatId => chatStore.dispatch({ type: 'SELECT_CHAT', payload: chatId })

export default chatStore

0 comments on commit d69cf7a

Please sign in to comment.