From 9903c61a21bb7cbbc3dd52b30ebbd55ff56f7051 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 10 Jan 2019 09:41:26 +0000 Subject: [PATCH 1/2] Fix lint errors in MessageComposerInput and remove from ignored files Missed a load of the async arrows functions when changing them because they were in the ignored files, so trying to chip away at this. A lot of these were unused imports / variables. Probably the only interesting one was a 'this' in a non-member function which I've moved to be a member function. --- .eslintignore.errorfiles | 1 - .../views/rooms/MessageComposerInput.js | 52 +++++++++---------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 1a12432c87..1c9e2d4413 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -53,7 +53,6 @@ src/components/views/rooms/MemberInfo.js src/components/views/rooms/MemberList.js src/components/views/rooms/MemberTile.js src/components/views/rooms/MessageComposer.js -src/components/views/rooms/MessageComposerInput.js src/components/views/rooms/PinnedEventTile.js src/components/views/rooms/RoomList.js src/components/views/rooms/RoomPreviewBar.js diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index 80f90d37b4..4c800ad8d2 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -15,13 +15,11 @@ See the License for the specific language governing permissions and limitations under the License. */ import React from 'react'; -import ReactDOM from 'react-dom'; import PropTypes from 'prop-types'; -import type SyntheticKeyboardEvent from 'react/lib/SyntheticKeyboardEvent'; import { Editor } from 'slate-react'; import { getEventTransfer } from 'slate-react'; -import { Value, Document, Block, Inline, Text, Range, Node } from 'slate'; +import { Value, Block, Inline, Range } from 'slate'; import type { Change } from 'slate'; import Html from 'slate-html-serializer'; @@ -30,7 +28,6 @@ import Plain from 'slate-plain-serializer'; import PlainWithPillsSerializer from "../../../autocomplete/PlainWithPillsSerializer"; import classNames from 'classnames'; -import Promise from 'bluebird'; import MatrixClientPeg from '../../../MatrixClientPeg'; import type {MatrixClient} from 'matrix-js-sdk/lib/matrix'; @@ -38,7 +35,7 @@ import {processCommandInput} from '../../../SlashCommands'; import { KeyCode, isOnlyCtrlOrCmdKeyEvent } from '../../../Keyboard'; import Modal from '../../../Modal'; import sdk from '../../../index'; -import { _t, _td } from '../../../languageHandler'; +import { _t } from '../../../languageHandler'; import Analytics from '../../../Analytics'; import * as RichText from '../../../RichText'; @@ -49,27 +46,24 @@ import Markdown from '../../../Markdown'; import ComposerHistoryManager from '../../../ComposerHistoryManager'; import MessageComposerStore from '../../../stores/MessageComposerStore'; -import {MATRIXTO_MD_LINK_PATTERN, MATRIXTO_URL_PATTERN} from '../../../linkify-matrix'; -const REGEX_MATRIXTO_MARKDOWN_GLOBAL = new RegExp(MATRIXTO_MD_LINK_PATTERN, 'g'); +import {MATRIXTO_URL_PATTERN} from '../../../linkify-matrix'; -import {asciiRegexp, unicodeRegexp, shortnameToUnicode, emojioneList, asciiList, mapUnicodeToShort, toShort} from 'emojione'; +import { + asciiRegexp, unicodeRegexp, shortnameToUnicode, + asciiList, mapUnicodeToShort, toShort, +} from 'emojione'; import SettingsStore, {SettingLevel} from "../../../settings/SettingsStore"; import {makeUserPermalink} from "../../../matrix-to"; import ReplyPreview from "./ReplyPreview"; import ReplyThread from "../elements/ReplyThread"; import {ContentHelpers} from 'matrix-js-sdk'; -const EMOJI_SHORTNAMES = Object.keys(emojioneList); const EMOJI_UNICODE_TO_SHORTNAME = mapUnicodeToShort(); const REGEX_EMOJI_WHITESPACE = new RegExp('(?:^|\\s)(' + asciiRegexp + ')\\s$'); const EMOJI_REGEX = new RegExp(unicodeRegexp, 'g'); const TYPING_USER_TIMEOUT = 10000; const TYPING_SERVER_TIMEOUT = 30000; -const ENTITY_TYPES = { - AT_ROOM_PILL: 'ATROOMPILL', -}; - // the Slate node type to default to for unstyled text const DEFAULT_NODE = 'paragraph'; @@ -114,15 +108,6 @@ const SLATE_SCHEMA = { }, }; -function onSendMessageFailed(err, room) { - // XXX: temporary logging to try to diagnose - // https://github.com/vector-im/riot-web/issues/3148 - console.log('MessageComposer got send failure: ' + err.name + '('+err+')'); - this.props.roomViewStore.getDispatcher().dispatch({ - action: 'message_send_failed', - }); -} - function rangeEquals(a: Range, b: Range): boolean { return (a.anchor.key === b.anchor.key && a.anchor.offset === b.anchorOffset @@ -370,8 +355,16 @@ export default class MessageComposerInput extends React.Component { this._editor = e; } + onSendMessageFailed = (err, room) => { + // XXX: temporary logging to try to diagnose + // https://github.com/vector-im/riot-web/issues/3148 + console.log('MessageComposer got send failure: ' + err.name + '('+err+')'); + this.props.roomViewStore.getDispatcher().dispatch({ + action: 'message_send_failed', + }); + } + onAction = (payload) => { - const editor = this._editor; const editorState = this.state.editorState; switch (payload.action) { @@ -868,7 +861,7 @@ export default class MessageComposerInput extends React.Component { return true; } - const newState: ?Value = null; + //const newState: ?Value = null; // Draft handles rich text mode commands by default but we need to do it ourselves for Markdown. if (this.state.isRichTextEnabled) { @@ -1119,7 +1112,9 @@ export default class MessageComposerInput extends React.Component { const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); Modal.createTrackedDialog('Server error', '', ErrorDialog, { title: _t("Server error"), - description: ((err && err.message) ? err.message : _t("Server unavailable, overloaded, or something else went wrong.")), + description: ((err && err.message) ? err.message : _t( + "Server unavailable, overloaded, or something else went wrong.", + )), }); }); } else if (cmd.error) { @@ -1233,7 +1228,7 @@ export default class MessageComposerInput extends React.Component { action: 'message_sent', }); }).catch((e) => { - onSendMessageFailed(e, this.props.room); + this.onSendMessageFailed(e, this.props.room); }); this.setState({ @@ -1498,7 +1493,9 @@ export default class MessageComposerInput extends React.Component { }); const style = {}; if (props.selected) style.border = '1px solid blue'; - return {; + return {; } } }; @@ -1552,7 +1549,6 @@ export default class MessageComposerInput extends React.Component { getSelectionRange(editorState: Value) { let beginning = false; - const query = this.getAutocompleteQuery(editorState); const firstChild = editorState.document.nodes.get(0); const firstGrandChild = firstChild && firstChild.nodes.get(0); beginning = (firstChild && firstGrandChild && From fea19805811006ce54e3ae81c441e046c95d3b68 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 10 Jan 2019 10:23:49 +0000 Subject: [PATCH 2/2] Only 18 warnings now --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8804c0911b..7b55a09948 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "start:init": "babel src -d lib --source-maps --copy-files", "lint": "eslint src/", "lintall": "eslint src/ test/", - "lintwithexclusions": "eslint --max-warnings 19 --ignore-path .eslintignore.errorfiles src test", + "lintwithexclusions": "eslint --max-warnings 18 --ignore-path .eslintignore.errorfiles src test", "clean": "rimraf lib", "prepublish": "npm run clean && npm run build && git rev-parse HEAD > git-revision.txt", "test": "karma start --single-run=true --browsers ChromeHeadless",