Skip to content

Commit

Permalink
Fix search while forwarding (close evgeny-nadymov#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-nadymov committed Nov 18, 2019
1 parent 86c1692 commit b790163
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 36 deletions.
2 changes: 1 addition & 1 deletion config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}),
Expand Down
3 changes: 1 addition & 2 deletions src/Components/Message/Meta.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
}

.meta-views-icon {
font-size: 15px;
transform: translateY(3px);
transform: translateY(2px);
}
2 changes: 1 addition & 1 deletion src/Components/Message/Meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Meta extends React.Component {
<span>&ensp;</span>
{views > 0 && (
<>
<VisibilityIcon className='meta-views-icon' />
<VisibilityIcon fontSize='inherit' className='meta-views-icon' />
<span className='meta-views'>
&nbsp;
{views}
Expand Down
58 changes: 44 additions & 14 deletions src/Components/Popup/ForwardDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class ForwardDialog extends React.Component {
}
};

handleSearchKeyUp = () => {
handleSearchKeyUp = async () => {
const { chatIds, savedMessages } = this.state;

const element = this.searchRef.current;
Expand All @@ -368,15 +368,15 @@ 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;
}

const latinText = getLatinInput(innerText);
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(
Expand All @@ -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 => {
Expand Down Expand Up @@ -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 => (
Expand All @@ -466,14 +487,23 @@ class ForwardDialog extends React.Component {
/>
));

const foundChats = (searchResults || []).map(x => (
<ForwardTargetChat
key={x}
chatId={x}
selected={this.targetChats.has(x)}
onSelect={() => 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 => (
<ForwardTargetChat
key={x}
chatId={x}
selected={this.targetChats.has(x)}
onSelect={() => this.handleChangeSelection(x)}
/>
));

console.log('[fd] render', searchResults, globalSearchResults);

return (
<Dialog
Expand Down
29 changes: 11 additions & 18 deletions src/TelegramApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import packageJson from '../package.json';
import AuthFormControl from './Components/Auth/AuthFormControl';
import InactivePage from './Components/InactivePage';
import NativeAppPage from './Components/NativeAppPage';
import MainPage from './Components/MainPage';
import StubPage from './Components/StubPage';
import registerServiceWorker from './registerServiceWorker';
import { isMobile } from './Utils/Common';
Expand All @@ -34,6 +33,7 @@ import AuthorizationStore from './Stores/AuthorizationStore';
import TdLibController from './Controllers/TdLibController';
import './TelegramApp.css';

import MainPage from './Components/MainPage';
// const MainPage = React.lazy(() => import('./Components/MainPage'));

const styles = theme => ({
Expand Down Expand Up @@ -199,7 +199,6 @@ class TelegramApp extends Component {
}

const loading = t('Loading').replace('...', '');
// let page = <StubPage title={loading} />;
let page = <MainPage />;
// (
// <React.Suspense fallback={<StubPage title='' />}>
Expand All @@ -217,12 +216,6 @@ class TelegramApp extends Component {
case 'authorizationStateClosing':
case 'authorizationStateLoggingOut':
case 'authorizationStateReady': {
page = <MainPage />;
// page = (
// <React.Suspense fallback={<StubPage title='' />}>
// <MainPage />
// </React.Suspense>
// );
break;
}
case 'authorizationStateWaitCode':
Expand Down Expand Up @@ -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 (
<div id='app' onDragOver={this.handleDragOver} onDrop={this.handleDrop} onKeyDown={this.handleKeyDown}>
Expand Down

0 comments on commit b790163

Please sign in to comment.