"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/renderer/components/dialogs/ImportQrCode.tsx" between
deltachat-desktop-1.3.3.tar.gz and deltachat-desktop-1.3.4.tar.gz

About: Delta Chat is a messanger for Desktop (Linux), IOS and Android that allows chatting over e-mail (it’s a little bit like Telegram or Whatsapp but without tracking or central control).

ImportQrCode.tsx  (deltachat-desktop-1.3.3):ImportQrCode.tsx  (deltachat-desktop-1.3.4)
import React, { useContext, useState, useRef } from 'react' import React, { useContext, useState, useRef } from 'react'
import DeltaDialog, { DeltaDialogBody, DeltaDialogContent } from './DeltaDialog' import DeltaDialog, { DeltaDialogBody, DeltaDialogContent } from './DeltaDialog'
import { DeltaButtonDanger } from './SmallDialog'
import { ScreenContext } from '../../contexts' import { ScreenContext } from '../../contexts'
import { Icon } from '@blueprintjs/core' import { Icon } from '@blueprintjs/core'
import { LocalSettings } from '../../../shared/shared-types' import { LocalSettings } from '../../../shared/shared-types'
import { selectChat } from '../../stores/chat' import { selectChat } from '../../stores/chat'
import QrReader from 'react-qr-reader' import QrReader from 'react-qr-reader'
import { Intent, ProgressBar, Card } from '@blueprintjs/core' import { Intent, ProgressBar, Card } from '@blueprintjs/core'
import { DeltaBackend } from '../../delta-remote' import { DeltaBackend } from '../../delta-remote'
interface QrStates { interface QrStates {
[key: number]: string [key: number]: string
skipping to change at line 34 skipping to change at line 35
332: 'QrUrl', // text1=URL 332: 'QrUrl', // text1=URL
400: 'QrError', // text1=error string 400: 'QrError', // text1=error string
} }
export declare type QrCodeResponse = { export declare type QrCodeResponse = {
state: keyof QrStates state: keyof QrStates
id: number id: number
text1: string text1: string
} }
export async function processOPENPGP4FPRUrl(url: string, onClose: any = null) { export async function processOPENPGP4FPRUrl(url: string, callback: any = null) {
const tx = window.translate const tx = window.translate
let error = false let error = false
const response: QrCodeResponse = await DeltaBackend.call('checkQrCode', url) const response: QrCodeResponse = await DeltaBackend.call('checkQrCode', url)
if (response === null) { if (response === null) {
error = true error = true
} }
const state = qrStates[response.state] const state = response ? qrStates[response.state] : null
if (error || state === 'QrError' || state === 'QrText') { if (error || state === 'QrError' || state === 'QrText') {
window.__userFeedback({ window.__userFeedback({
type: 'error', type: 'error',
text: tx('import_qr_error'), text: tx('import_qr_error'),
}) })
return return
} }
const selectChatAndClose = (chatId: number) => {
selectChat(chatId)
onClose()
}
if (state === 'QrAskVerifyContact') { if (state === 'QrAskVerifyContact') {
const contact = await DeltaBackend.call('contacts.getContact', response.id) const contact = await DeltaBackend.call('contacts.getContact', response.id)
window.__openDialog('ConfirmationDialog', { window.__openDialog('ConfirmationDialog', {
message: tx('ask_start_chat_with', contact.address), message: tx('ask_start_chat_with', contact.address),
confirmLabel: tx('ok'), confirmLabel: tx('ok'),
cb: async (confirmed: boolean) => { cb: async (confirmed: boolean) => {
if (confirmed) { if (confirmed) {
DeltaBackend.call('joinSecurejoin', url).then(selectChatAndClose) DeltaBackend.call('joinSecurejoin', url).then(callback)
} }
}, },
}) })
} else if (state === 'QrAskVerifyGroup') { } else if (state === 'QrAskVerifyGroup') {
window.__openDialog('ConfirmationDialog', { window.__openDialog('ConfirmationDialog', {
message: tx('qrscan_ask_join_group', response.text1), message: tx('qrscan_ask_join_group', response.text1),
confirmLabel: tx('ok'), confirmLabel: tx('ok'),
cb: (confirmed: boolean) => { cb: (confirmed: boolean) => {
if (confirmed) { if (confirmed) {
DeltaBackend.call('joinSecurejoin', url).then(selectChatAndClose) DeltaBackend.call('joinSecurejoin', url).then(callback)
} }
return return
}, },
}) })
} else if (state === 'QrFprOk') { } else if (state === 'QrFprOk') {
const contact = await DeltaBackend.call('contacts.getContact', response.id) const contact = await DeltaBackend.call('contacts.getContact', response.id)
window.__openDialog('ConfirmationDialog', { window.__openDialog('ConfirmationDialog', {
message: `The fingerprint of ${contact.displayName} is valid!`, message: `The fingerprint of ${contact.displayName} is valid!`,
confirmLabel: tx('ok'), confirmLabel: tx('ok'),
cb: onClose, cb: callback,
}) })
} else { } else {
window.__userFeedback({ window.__userFeedback({
type: 'error', type: 'error',
text: "Don't know what to do with this URL :/", text: "Don't know what to do with this URL :/",
}) })
} }
} }
export function DeltaDialogImportQrInner({ export function DeltaDialogImportQrInner({
skipping to change at line 104 skipping to change at line 100
onClose, onClose,
}: { }: {
description: string description: string
onClose: () => void onClose: () => void
}) { }) {
const tx = window.translate const tx = window.translate
const [qrCode, setQrCode] = useState('') const [qrCode, setQrCode] = useState('')
const screenContext = useContext(ScreenContext) const screenContext = useContext(ScreenContext)
const [secureJoinOngoing, setSecureJoinOngoing] = useState(false) const [secureJoinOngoing, setSecureJoinOngoing] = useState(false)
const handleScanResult = (chatId: number = null) => {
setSecureJoinOngoing(false)
if (chatId) {
selectChat(chatId)
}
onClose()
}
const handleResponse = async (scannedQrCode: string) => { const handleResponse = async (scannedQrCode: string) => {
processOPENPGP4FPRUrl(scannedQrCode, onClose) setSecureJoinOngoing(true)
processOPENPGP4FPRUrl(scannedQrCode, handleScanResult)
} }
const qrImageReader = useRef<any>() const qrImageReader = useRef<any>()
const handleScan = (data: string) => { const handleScan = (data: string) => {
if (data) { if (data) {
handleResponse(data) handleResponse(data)
} }
} }
const cancelProcess = () => {
DeltaBackend.call('stopOngoingProcess')
onClose()
}
const handleError = (err: string) => { const handleError = (err: string) => {
/* ignore-console-log */ /* ignore-console-log */
console.error(err) console.error(err)
} }
const openImageDialog = () => { const openImageDialog = () => {
qrImageReader.current.openImageDialog() qrImageReader.current.openImageDialog()
} }
return ( return (
<DeltaDialogBody> <DeltaDialogBody>
<DeltaDialogContent noPadding> <DeltaDialogContent noPadding>
{secureJoinOngoing && ( {secureJoinOngoing && (
<div> <div>
<p className='progress-info'>Secure join in progress...</p> <p className='progress-info'>Secure join in progress...</p>
<ProgressBar intent={Intent.PRIMARY} value={100} /> <ProgressBar intent={Intent.PRIMARY} value={100} />
<DeltaButtonDanger onClick={cancelProcess}>
{tx('cancel')}
</DeltaButtonDanger>
</div> </div>
)} )}
{!secureJoinOngoing && ( {!secureJoinOngoing && (
<div className='import-qr-code-dialog'> <div className='import-qr-code-dialog'>
<div> <div>
<div> <div>
<QrReader <QrReader
delay={300} delay={300}
onError={handleError} onError={handleError}
onScan={handleScan} onScan={handleScan}
 End of changes. 11 change blocks. 
11 lines changed or deleted 24 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)