From b790163b6af29fbeb5d0192944db88087cd8f78b Mon Sep 17 00:00:00 2001 From: evgeny-nadymov Date: Tue, 19 Nov 2019 00:41:42 +0300 Subject: [PATCH] Fix search while forwarding (close #93) --- config-overrides.js | 2 +- src/Components/Message/Meta.css | 3 +- src/Components/Message/Meta.js | 2 +- src/Components/Popup/ForwardDialog.js | 58 ++++++++++++++++++++------- src/TelegramApp.js | 29 +++++--------- 5 files changed, 58 insertions(+), 36 deletions(-) diff --git a/config-overrides.js b/config-overrides.js index 561449bc9..b07755023 100644 --- a/config-overrides.js +++ b/config-overrides.js @@ -33,7 +33,7 @@ module.exports = override( config => addWebpackBundleAnalyzer(config,{ // analyzerMode: 'static', // reportFilename: 'report.html', - openAnalyzer: false, + openAnalyzer: true, generateStatsFile: true, statsFilename: 'bundle-stats.json' }), diff --git a/src/Components/Message/Meta.css b/src/Components/Message/Meta.css index 65261d0a6..4b0fc346b 100644 --- a/src/Components/Message/Meta.css +++ b/src/Components/Message/Meta.css @@ -16,6 +16,5 @@ } .meta-views-icon { - font-size: 15px; - transform: translateY(3px); + transform: translateY(2px); } diff --git a/src/Components/Message/Meta.js b/src/Components/Message/Meta.js index d84958231..73dbab24a 100644 --- a/src/Components/Message/Meta.js +++ b/src/Components/Message/Meta.js @@ -36,7 +36,7 @@ class Meta extends React.Component { {views > 0 && ( <> - +   {views} diff --git a/src/Components/Popup/ForwardDialog.js b/src/Components/Popup/ForwardDialog.js index 4d78661b3..6784d26f7 100644 --- a/src/Components/Popup/ForwardDialog.js +++ b/src/Components/Popup/ForwardDialog.js @@ -355,7 +355,7 @@ class ForwardDialog extends React.Component { } }; - handleSearchKeyUp = () => { + handleSearchKeyUp = async () => { const { chatIds, savedMessages } = this.state; const element = this.searchRef.current; @@ -368,7 +368,7 @@ class ForwardDialog extends React.Component { const innerText = this.getInnerText(element).trim(); if (!innerText) { - this.setState({ searchText: null, searchResults: [] }); + this.setState({ searchText: null, searchResults: [], globalSearchResults: [] }); return; } @@ -376,7 +376,7 @@ class ForwardDialog extends React.Component { const cyrillicText = getCyrillicInput(innerText); const chatsSource = savedMessages - ? [savedMessages.id].concat(chatIds.filter(x => x !== savedMessages.id)).filter(x => canSendMessages(x)) + ? [savedMessages.id].concat(chatIds.filter(x => x !== savedMessages.id && canSendMessages(x))) : chatIds; const searchResults = chatsSource.filter( @@ -386,7 +386,21 @@ class ForwardDialog extends React.Component { (cyrillicText && this.hasSearchText(x, cyrillicText)) ); - this.setState({ searchText: innerText, searchResults: searchResults }); + this.setState({ searchText: innerText, searchResults }); + + const result = await TdLibController.send({ + '@type': 'searchChatsOnServer', + query: innerText, + limit: 100 + }); + + if (this.state.searchText !== innerText) { + return; + } + + this.setState({ + globalSearchResults: result.chat_ids + }); }; handleSearchPaste = event => { @@ -451,10 +465,17 @@ class ForwardDialog extends React.Component { render() { const { classes, t } = this.props; - const { chatIds, searchText, searchResults, savedMessages, publicMessageLink } = this.state; + const { + chatIds, + searchText, + searchResults, + globalSearchResults, + savedMessages, + publicMessageLink + } = this.state; const chatsSource = savedMessages - ? [savedMessages.id].concat(chatIds.filter(x => x !== savedMessages.id)).filter(x => canSendMessages(x)) + ? [savedMessages.id].concat(chatIds.filter(x => x !== savedMessages.id && canSendMessages(x))) : chatIds; const chats = chatsSource.map(x => ( @@ -466,14 +487,23 @@ class ForwardDialog extends React.Component { /> )); - const foundChats = (searchResults || []).map(x => ( - this.handleChangeSelection(x)} - /> - )); + const searchResultsMap = new Map((searchResults || []).map(x => [x, x])); + const filteredResults = (globalSearchResults || []).filter( + x => x !== savedMessages.id && canSendMessages(x) && !searchResultsMap.has(x) + ); + + const foundChats = (searchResults || []) + .concat(filteredResults) + .map(x => ( + this.handleChangeSelection(x)} + /> + )); + + console.log('[fd] render', searchResults, globalSearchResults); return ( import('./Components/MainPage')); const styles = theme => ({ @@ -199,7 +199,6 @@ class TelegramApp extends Component { } const loading = t('Loading').replace('...', ''); - // let page = ; let page = ; // ( // }> @@ -217,12 +216,6 @@ class TelegramApp extends Component { case 'authorizationStateClosing': case 'authorizationStateLoggingOut': case 'authorizationStateReady': { - page = ; - // page = ( - // }> - // - // - // ); break; } case 'authorizationStateWaitCode': @@ -252,16 +245,16 @@ class TelegramApp extends Component { } } - console.log( - 'TelegramApp.render', - state, - prevAuthorizationState, - authorizationState, - 'nativeMobile=' + nativeMobile, - 'inactive=' + inactive, - 'db=' + databaseExists, - page - ); + // console.log( + // 'TelegramApp.render', + // state, + // prevAuthorizationState, + // authorizationState, + // 'nativeMobile=' + nativeMobile, + // 'inactive=' + inactive, + // 'db=' + databaseExists, + // page + // ); return (