From f5353fcdc54a09cf94e2fca51a70d2733acf24f3 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 23 Jun 2017 13:43:52 +0100 Subject: [PATCH 1/6] Only submit phone number when phone loginType is selected Otherwise submit a phoneNumber and phoneCountry of `null` (when logging in with email or username). Fixes https://github.com/vector-im/riot-web/issues/4000 --- src/components/views/login/PasswordLogin.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/views/login/PasswordLogin.js b/src/components/views/login/PasswordLogin.js index 46a48d14a0..54237bec19 100644 --- a/src/components/views/login/PasswordLogin.js +++ b/src/components/views/login/PasswordLogin.js @@ -69,10 +69,19 @@ class PasswordLogin extends React.Component { onSubmitForm(ev) { ev.preventDefault(); + if (this.state.loginType === PasswordLogin.LOGIN_FIELD_PHONE) { + this.props.onSubmit( + this.state.username, + this.state.phoneCountry, + this.state.phoneNumber, + this.state.password, + ); + return; + } this.props.onSubmit( this.state.username, - this.state.phoneCountry, - this.state.phoneNumber, + null, + null, this.state.password, ); } From c51255da40f2cf69ca1a2d9dc54189621a9a4958 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 23 Jun 2017 14:34:19 +0100 Subject: [PATCH 2/6] Submit empty string username when on phone number login --- src/components/views/login/PasswordLogin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/login/PasswordLogin.js b/src/components/views/login/PasswordLogin.js index 54237bec19..2c125be378 100644 --- a/src/components/views/login/PasswordLogin.js +++ b/src/components/views/login/PasswordLogin.js @@ -71,7 +71,7 @@ class PasswordLogin extends React.Component { ev.preventDefault(); if (this.state.loginType === PasswordLogin.LOGIN_FIELD_PHONE) { this.props.onSubmit( - this.state.username, + '', this.state.phoneCountry, this.state.phoneNumber, this.state.password, From ec36a348be008c84fbd13b80d2c2b2eeab983d4c Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 23 Jun 2017 14:48:15 +0100 Subject: [PATCH 3/6] comment why we send the empty string --- src/components/views/login/PasswordLogin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/login/PasswordLogin.js b/src/components/views/login/PasswordLogin.js index 2c125be378..9f855616fc 100644 --- a/src/components/views/login/PasswordLogin.js +++ b/src/components/views/login/PasswordLogin.js @@ -71,7 +71,7 @@ class PasswordLogin extends React.Component { ev.preventDefault(); if (this.state.loginType === PasswordLogin.LOGIN_FIELD_PHONE) { this.props.onSubmit( - '', + '', // XXX: Synapse breaks if you send null here: this.state.phoneCountry, this.state.phoneNumber, this.state.password, From c0e48c72fc51e2aea73d4d409bfe04e285610a61 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 23 Jun 2017 18:03:32 +0100 Subject: [PATCH 4/6] Remove dep on liblevenstein While we don't actually use it --- package.json | 1 - src/autocomplete/FuzzyMatcher.js | 170 +++++++++++++++---------------- 2 files changed, 85 insertions(+), 86 deletions(-) diff --git a/package.json b/package.json index 76323685ac..8d638a5928 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,6 @@ "glob": "^5.0.14", "highlight.js": "^8.9.1", "isomorphic-fetch": "^2.2.1", - "liblevenshtein": "^2.0.4", "linkifyjs": "^2.1.3", "lodash": "^4.13.1", "matrix-js-sdk": "matrix-org/matrix-js-sdk#develop", diff --git a/src/autocomplete/FuzzyMatcher.js b/src/autocomplete/FuzzyMatcher.js index 291e63d604..230cb1dbd2 100644 --- a/src/autocomplete/FuzzyMatcher.js +++ b/src/autocomplete/FuzzyMatcher.js @@ -1,91 +1,91 @@ -import Levenshtein from 'liblevenshtein'; -import _at from 'lodash/at'; -import _flatMap from 'lodash/flatMap'; -import _sortBy from 'lodash/sortBy'; -import _sortedUniq from 'lodash/sortedUniq'; -import _keys from 'lodash/keys'; - -class KeyMap { - keys: Array; - objectMap: {[String]: Array}; - priorityMap: {[String]: number} -} - -const DEFAULT_RESULT_COUNT = 10; -const DEFAULT_DISTANCE = 5; +//import Levenshtein from 'liblevenshtein'; +//import _at from 'lodash/at'; +//import _flatMap from 'lodash/flatMap'; +//import _sortBy from 'lodash/sortBy'; +//import _sortedUniq from 'lodash/sortedUniq'; +//import _keys from 'lodash/keys'; +// +//class KeyMap { +// keys: Array; +// objectMap: {[String]: Array}; +// priorityMap: {[String]: number} +//} +// +//const DEFAULT_RESULT_COUNT = 10; +//const DEFAULT_DISTANCE = 5; // FIXME Until Fuzzy matching works better, we use prefix matching. import PrefixMatcher from './QueryMatcher'; export default PrefixMatcher; -class FuzzyMatcher { // eslint-disable-line no-unused-vars - /** - * @param {object[]} objects the objects to perform a match on - * @param {string[]} keys an array of keys within each object to match on - * Keys can refer to object properties by name and as in JavaScript (for nested properties) - * - * To use, simply presort objects by required criteria, run through this function and create a FuzzyMatcher with the - * resulting KeyMap. - * - * TODO: Handle arrays and objects (Fuse did this, RoomProvider uses it) - * @return {KeyMap} - */ - static valuesToKeyMap(objects: Array, keys: Array): KeyMap { - const keyMap = new KeyMap(); - const map = {}; - const priorities = {}; - - objects.forEach((object, i) => { - const keyValues = _at(object, keys); - console.log(object, keyValues, keys); - for (const keyValue of keyValues) { - if (!map.hasOwnProperty(keyValue)) { - map[keyValue] = []; - } - map[keyValue].push(object); - } - priorities[object] = i; - }); - - keyMap.objectMap = map; - keyMap.priorityMap = priorities; - keyMap.keys = _sortBy(_keys(map), [(value) => priorities[value]]); - return keyMap; - } - - constructor(objects: Array, options: {[Object]: Object} = {}) { - this.options = options; - this.keys = options.keys; - this.setObjects(objects); - } - - setObjects(objects: Array) { - this.keyMap = FuzzyMatcher.valuesToKeyMap(objects, this.keys); - console.log(this.keyMap.keys); - this.matcher = new Levenshtein.Builder() - .dictionary(this.keyMap.keys, true) - .algorithm('transposition') - .sort_candidates(false) - .case_insensitive_sort(true) - .include_distance(true) - .maximum_candidates(this.options.resultCount || DEFAULT_RESULT_COUNT) // result count 0 doesn't make much sense - .build(); - } - - match(query: String): Array { - const candidates = this.matcher.transduce(query, this.options.distance || DEFAULT_DISTANCE); - // TODO FIXME This is hideous. Clean up when possible. - const val = _sortedUniq(_sortBy(_flatMap(candidates, (candidate) => { - return this.keyMap.objectMap[candidate[0]].map((value) => { - return { - distance: candidate[1], - ...value, - }; - }); - }), - [(candidate) => candidate.distance, (candidate) => this.keyMap.priorityMap[candidate]])); - console.log(val); - return val; - } -} +//class FuzzyMatcher { // eslint-disable-line no-unused-vars +// /** +// * @param {object[]} objects the objects to perform a match on +// * @param {string[]} keys an array of keys within each object to match on +// * Keys can refer to object properties by name and as in JavaScript (for nested properties) +// * +// * To use, simply presort objects by required criteria, run through this function and create a FuzzyMatcher with the +// * resulting KeyMap. +// * +// * TODO: Handle arrays and objects (Fuse did this, RoomProvider uses it) +// * @return {KeyMap} +// */ +// static valuesToKeyMap(objects: Array, keys: Array): KeyMap { +// const keyMap = new KeyMap(); +// const map = {}; +// const priorities = {}; +// +// objects.forEach((object, i) => { +// const keyValues = _at(object, keys); +// console.log(object, keyValues, keys); +// for (const keyValue of keyValues) { +// if (!map.hasOwnProperty(keyValue)) { +// map[keyValue] = []; +// } +// map[keyValue].push(object); +// } +// priorities[object] = i; +// }); +// +// keyMap.objectMap = map; +// keyMap.priorityMap = priorities; +// keyMap.keys = _sortBy(_keys(map), [(value) => priorities[value]]); +// return keyMap; +// } +// +// constructor(objects: Array, options: {[Object]: Object} = {}) { +// this.options = options; +// this.keys = options.keys; +// this.setObjects(objects); +// } +// +// setObjects(objects: Array) { +// this.keyMap = FuzzyMatcher.valuesToKeyMap(objects, this.keys); +// console.log(this.keyMap.keys); +// this.matcher = new Levenshtein.Builder() +// .dictionary(this.keyMap.keys, true) +// .algorithm('transposition') +// .sort_candidates(false) +// .case_insensitive_sort(true) +// .include_distance(true) +// .maximum_candidates(this.options.resultCount || DEFAULT_RESULT_COUNT) // result count 0 doesn't make much sense +// .build(); +// } +// +// match(query: String): Array { +// const candidates = this.matcher.transduce(query, this.options.distance || DEFAULT_DISTANCE); +// // TODO FIXME This is hideous. Clean up when possible. +// const val = _sortedUniq(_sortBy(_flatMap(candidates, (candidate) => { +// return this.keyMap.objectMap[candidate[0]].map((value) => { +// return { +// distance: candidate[1], +// ...value, +// }; +// }); +// }), +// [(candidate) => candidate.distance, (candidate) => this.keyMap.priorityMap[candidate]])); +// console.log(val); +// return val; +// } +//} From f0f4a16e979b5c595ae77638a557852e27a0ce43 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 23 Jun 2017 18:28:02 +0100 Subject: [PATCH 5/6] Translate autocomplete delay --- src/components/structures/UserSettings.js | 2 +- src/i18n/strings/en_EN.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 9171b081ab..ef574d2ed6 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -656,7 +656,7 @@ module.exports = React.createClass({ - +
Autocomplete Delay (ms): {_t('Autocomplete Delay (ms):')} Date: Fri, 23 Jun 2017 18:30:16 +0100 Subject: [PATCH 6/6] Add copyright headers --- src/ComposerHistoryManager.js | 15 +++++++++++++++ src/autocomplete/FuzzyMatcher.js | 16 ++++++++++++++++ src/autocomplete/QueryMatcher.js | 15 +++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/ComposerHistoryManager.js b/src/ComposerHistoryManager.js index ef9232c684..3e19a78bfe 100644 --- a/src/ComposerHistoryManager.js +++ b/src/ComposerHistoryManager.js @@ -1,4 +1,19 @@ //@flow +/* +Copyright 2017 Aviral Dasgupta + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ import {ContentState} from 'draft-js'; import * as RichText from './RichText'; diff --git a/src/autocomplete/FuzzyMatcher.js b/src/autocomplete/FuzzyMatcher.js index 230cb1dbd2..1aa0782c22 100644 --- a/src/autocomplete/FuzzyMatcher.js +++ b/src/autocomplete/FuzzyMatcher.js @@ -1,3 +1,19 @@ +/* +Copyright 2017 Aviral Dasgupta + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + //import Levenshtein from 'liblevenshtein'; //import _at from 'lodash/at'; //import _flatMap from 'lodash/flatMap'; diff --git a/src/autocomplete/QueryMatcher.js b/src/autocomplete/QueryMatcher.js index ead7ea8047..01fc251318 100644 --- a/src/autocomplete/QueryMatcher.js +++ b/src/autocomplete/QueryMatcher.js @@ -1,4 +1,19 @@ //@flow +/* +Copyright 2017 Aviral Dasgupta + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ import _at from 'lodash/at'; import _flatMap from 'lodash/flatMap';