diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 02629ea169..7d998f8c4b 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -1,8 +1,6 @@ # autogenerated file: run scripts/generate-eslint-error-ignore-file to update. src/component-index.js -src/components/structures/BottomLeftMenu.js -src/components/structures/CreateRoom.js src/components/structures/RoomDirectory.js src/components/structures/RoomStatusBar.js src/components/structures/RoomView.js @@ -18,53 +16,38 @@ src/components/views/dialogs/UnknownDeviceDialog.js src/components/views/elements/AddressSelector.js src/components/views/elements/DirectorySearchBox.js src/components/views/elements/MemberEventListSummary.js -src/components/views/elements/TintableSvg.js src/components/views/elements/UserSelector.js src/components/views/globals/MatrixToolbar.js src/components/views/globals/NewVersionBar.js src/components/views/globals/UpdateCheckBar.js src/components/views/messages/MFileBody.js -src/components/views/messages/RoomAvatarEvent.js src/components/views/messages/TextualBody.js src/components/views/room_settings/ColorSettings.js src/components/views/rooms/Autocomplete.js src/components/views/rooms/AuxPanel.js -src/components/views/rooms/EntityTile.js src/components/views/rooms/LinkPreviewWidget.js src/components/views/rooms/MemberDeviceInfo.js src/components/views/rooms/MemberInfo.js src/components/views/rooms/MemberList.js -src/components/views/rooms/SlateMessageComposer.js -src/components/views/rooms/PinnedEventTile.js src/components/views/rooms/RoomList.js src/components/views/rooms/RoomPreviewBar.js -src/components/views/rooms/SearchableEntityList.js src/components/views/rooms/SearchBar.js src/components/views/rooms/SearchResultTile.js -src/components/views/rooms/TopUnreadMessagesBar.js -src/components/views/rooms/UserTile.js +src/components/views/rooms/SlateMessageComposer.js src/components/views/settings/ChangeAvatar.js src/components/views/settings/ChangePassword.js src/components/views/settings/DevicesPanel.js src/components/views/settings/Notifications.js -src/GroupAddressPicker.js src/HtmlUtils.js src/ImageUtils.js -src/linkify-matrix.js src/Markdown.js -src/MatrixClientPeg.js src/notifications/ContentRules.js src/notifications/PushRuleVectorState.js -src/notifications/VectorPushRulesDefinitions.js -src/Notifier.js src/PlatformPeg.js -src/Presence.js src/rageshake/rageshake.js src/rageshake/submit-rageshake.js src/ratelimitedfunc.js -src/Roles.js src/Rooms.js -src/UiEffects.js src/Unread.js src/utils/DecryptFile.js src/utils/DirectoryUtils.js @@ -72,16 +55,10 @@ src/utils/DMRoomMap.js src/utils/FormattingUtils.js src/utils/MultiInviter.js src/utils/Receipt.js -src/VectorConferenceHandler.js src/Velociraptor.js -src/WhoIsTyping.js -src/wrappers/withMatrixClient.js test/components/structures/MessagePanel-test.js -test/components/structures/ScrollPanel-test.js -test/components/structures/TimelinePanel-test.js test/components/views/dialogs/InteractiveAuthDialog-test.js test/components/views/rooms/MessageComposerInput-test.js -test/components/views/rooms/RoomSettings-test.js test/mock-clock.js test/notifications/ContentRules-test.js test/notifications/PushRuleVectorState-test.js diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 27c4f40669..bebb254afc 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -16,9 +16,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -'use strict'; - -import Matrix from 'matrix-js-sdk'; +import {MatrixClient, MemoryStore} from 'matrix-js-sdk'; import utils from 'matrix-js-sdk/lib/utils'; import EventTimeline from 'matrix-js-sdk/lib/models/event-timeline'; @@ -27,7 +25,6 @@ import sdk from './index'; import createMatrixClient from './utils/createMatrixClient'; import SettingsStore from './settings/SettingsStore'; import MatrixActionCreators from './actions/MatrixActionCreators'; -import {phasedRollOutExpiredForUser} from "./PhasedRollOut"; import Modal from './Modal'; import {verificationMethods} from 'matrix-js-sdk/lib/crypto'; import MatrixClientBackedSettingsHandler from "./settings/handlers/MatrixClientBackedSettingsHandler"; @@ -87,7 +84,7 @@ class MatrixClientPeg { MatrixActionCreators.stop(); } - /* + /** * If we've registered a user ID we set this to the ID of the * user we've just registered. If they then go & log in, we * can send them to the welcome user (obviously this doesn't @@ -99,7 +96,7 @@ class MatrixClientPeg { this._justRegisteredUserId = uid; } - /* + /** * Returns true if the current user has just been registered by this * client as determined by setJustRegisteredUserId() * @@ -112,7 +109,7 @@ class MatrixClientPeg { ); } - /** + /* * Replace this MatrixClientPeg's client with a client instance that has * homeserver / identity server URLs and active credentials */ @@ -131,7 +128,7 @@ class MatrixClientPeg { } catch (err) { if (dbType === 'indexeddb') { console.error('Error starting matrixclient store - falling back to memory store', err); - this.matrixClient.store = new Matrix.MemoryStore({ + this.matrixClient.store = new MemoryStore({ localStorage: global.localStorage, }); } else { @@ -195,7 +192,7 @@ class MatrixClientPeg { }; } - /** + /* * Return the server name of the user's homeserver * Throws an error if unable to deduce the homeserver name * (eg. if the user is not logged in) diff --git a/src/Notifier.js b/src/Notifier.js index 0b0a5f6990..cca0ea2b89 100644 --- a/src/Notifier.js +++ b/src/Notifier.js @@ -112,7 +112,7 @@ const Notifier = { console.warn(`${roomId} has custom notification sound event, but no url key`); return null; } - + if (!content.url.startsWith("mxc://")) { console.warn(`${roomId} has custom notification sound event, but url is not a mxc url`); return null; @@ -203,7 +203,8 @@ const Notifier = { // The permission request was dismissed or denied // TODO: Support alternative branding in messaging const description = result === 'denied' - ? _t('Riot does not have permission to send you notifications - please check your browser settings') + ? _t('Riot does not have permission to send you notifications - ' + + 'please check your browser settings') : _t('Riot was not given permission to send notifications - please try again'); const ErrorDialog = sdk.getComponent('dialogs.ErrorDialog'); Modal.createTrackedDialog('Unable to enable Notifications', result, ErrorDialog, { diff --git a/src/Presence.js b/src/Presence.js index 8e00e95cdf..ca3db9b762 100644 --- a/src/Presence.js +++ b/src/Presence.js @@ -15,8 +15,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -const MatrixClientPeg = require("./MatrixClientPeg"); -const dis = require("./dispatcher"); +import MatrixClientPeg from "./MatrixClientPeg"; +import dis from "./dispatcher"; import Timer from './utils/Timer'; // Time in ms after that a user is considered as unavailable/away @@ -24,7 +24,6 @@ const UNAVAILABLE_TIME_MS = 3 * 60 * 1000; // 3 mins const PRESENCE_STATES = ["online", "offline", "unavailable"]; class Presence { - constructor() { this._activitySignal = null; this._unavailableTimer = null; @@ -43,7 +42,7 @@ class Presence { try { await this._unavailableTimer.finished(); this.setState("unavailable"); - } catch(e) { /* aborted, stop got called */ } + } catch (e) { /* aborted, stop got called */ } } } @@ -88,7 +87,7 @@ class Presence { if (PRESENCE_STATES.indexOf(newState) === -1) { throw new Error("Bad presence state: " + newState); } - const old_state = this.state; + const oldState = this.state; this.state = newState; if (MatrixClientPeg.get().isGuest()) { @@ -98,9 +97,9 @@ class Presence { try { await MatrixClientPeg.get().setPresence(this.state); console.log("Presence: %s", newState); - } catch(err) { + } catch (err) { console.error("Failed to set presence: %s", err); - this.state = old_state; + this.state = oldState; } } } diff --git a/src/Roles.js b/src/Roles.js index 438b6c1236..10c4ceaf1e 100644 --- a/src/Roles.js +++ b/src/Roles.js @@ -26,7 +26,7 @@ export function levelRoleMap(usersDefault) { } export function textualPowerLevel(level, usersDefault) { - const LEVEL_ROLE_MAP = this.levelRoleMap(usersDefault); + const LEVEL_ROLE_MAP = levelRoleMap(usersDefault); if (LEVEL_ROLE_MAP[level]) { return LEVEL_ROLE_MAP[level] + (level !== undefined ? ` (${level})` : ` (${usersDefault})`); } else { diff --git a/src/VectorConferenceHandler.js b/src/VectorConferenceHandler.js index e839d3f78b..37b3a7ddad 100644 --- a/src/VectorConferenceHandler.js +++ b/src/VectorConferenceHandler.js @@ -14,12 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -"use strict"; - import Promise from 'bluebird'; -const Matrix = require("matrix-js-sdk"); -const Room = Matrix.Room; -const CallHandler = require('./CallHandler'); +import {createNewMatrixCall, Room} from "matrix-js-sdk"; +import CallHandler from './CallHandler'; +import MatrixClientPeg from "./MatrixClientPeg"; // FIXME: this is Riot (Vector) specific code, but will be removed shortly when // we switch over to jitsi entirely for video conferencing. @@ -45,7 +43,7 @@ ConferenceCall.prototype.setup = function() { // return a call for *this* room to be placed. We also tack on // confUserId to speed up lookups (else we'd need to loop every room // looking for a 1:1 room with this conf user ID!) - const call = Matrix.createNewMatrixCall(self.client, room.roomId); + const call = createNewMatrixCall(self.client, room.roomId); call.confUserId = self.confUserId; call.groupRoomId = self.groupRoomId; return call; @@ -84,7 +82,7 @@ ConferenceCall.prototype._getConferenceUserRoom = function() { preset: "private_chat", invite: [this.confUserId], }).then(function(res) { - return new Room(res.room_id, null, client.getUserId()); + return new Room(res.room_id, null, MatrixClientPeg.get().getUserId()); }); }; diff --git a/src/WhoIsTyping.js b/src/WhoIsTyping.js index 78ca77ce5a..eb09685cbe 100644 --- a/src/WhoIsTyping.js +++ b/src/WhoIsTyping.js @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -const MatrixClientPeg = require("./MatrixClientPeg"); +import MatrixClientPeg from "./MatrixClientPeg"; import { _t } from './languageHandler'; module.exports = { @@ -33,6 +33,9 @@ module.exports = { /** * Given a Room object and, optionally, a list of userID strings * to exclude, return a list of user objects who are typing. + * @param {Room} room: room object to get users from. + * @param {string[]} exclude: list of user mxids to exclude. + * @returns {string[]} list of user objects who are typing. */ usersTyping: function(room, exclude) { const whoIsTyping = []; @@ -46,7 +49,7 @@ module.exports = { const userId = memberKeys[i]; if (room.currentState.members[userId].typing) { - if (exclude.indexOf(userId) == -1) { + if (exclude.indexOf(userId) === -1) { whoIsTyping.push(room.currentState.members[userId]); } } @@ -60,16 +63,19 @@ module.exports = { if (whoIsTyping.length > limit) { othersCount = whoIsTyping.length - limit + 1; } - if (whoIsTyping.length == 0) { + if (whoIsTyping.length === 0) { return ''; - } else if (whoIsTyping.length == 1) { + } else if (whoIsTyping.length === 1) { return _t('%(displayName)s is typing …', {displayName: whoIsTyping[0].name}); } const names = whoIsTyping.map(function(m) { return m.name; }); if (othersCount>=1) { - return _t('%(names)s and %(count)s others are typing …', {names: names.slice(0, limit - 1).join(', '), count: othersCount}); + return _t('%(names)s and %(count)s others are typing …', { + names: names.slice(0, limit - 1).join(', '), + count: othersCount, + }); } else { const lastPerson = names.pop(); return _t('%(names)s and %(lastPerson)s are typing …', {names: names.join(', '), lastPerson: lastPerson}); diff --git a/src/linkify-matrix.js b/src/linkify-matrix.js index 50d50f219a..a9e894d582 100644 --- a/src/linkify-matrix.js +++ b/src/linkify-matrix.js @@ -44,7 +44,7 @@ function matrixLinkify(linkify) { const S_ROOMALIAS_COLON = new linkify.parser.State(); const S_ROOMALIAS_COLON_NUM = new linkify.parser.State(ROOMALIAS); - const roomname_tokens = [ + const roomnameTokens = [ TT.DOT, TT.PLUS, TT.NUM, @@ -58,8 +58,8 @@ function matrixLinkify(linkify) { TT.LOCALHOST, ]; - S_HASH.on(roomname_tokens, S_HASH_NAME); - S_HASH_NAME.on(roomname_tokens, S_HASH_NAME); + S_HASH.on(roomnameTokens, S_HASH_NAME); + S_HASH_NAME.on(roomnameTokens, S_HASH_NAME); S_HASH_NAME.on(TT.DOMAIN, S_HASH_NAME); S_HASH_NAME.on(TT.COLON, S_HASH_NAME_COLON); @@ -92,7 +92,7 @@ function matrixLinkify(linkify) { const S_USERID_COLON = new linkify.parser.State(); const S_USERID_COLON_NUM = new linkify.parser.State(USERID); - const username_tokens = [ + const usernameTokens = [ TT.DOT, TT.UNDERSCORE, TT.PLUS, @@ -100,12 +100,12 @@ function matrixLinkify(linkify) { TT.DOMAIN, TT.TLD, - // as in roomname_tokens + // as in roomnameTokens TT.LOCALHOST, ]; - S_AT.on(username_tokens, S_AT_NAME); - S_AT_NAME.on(username_tokens, S_AT_NAME); + S_AT.on(usernameTokens, S_AT_NAME); + S_AT_NAME.on(usernameTokens, S_AT_NAME); S_AT_NAME.on(TT.DOMAIN, S_AT_NAME); S_AT_NAME.on(TT.COLON, S_AT_NAME_COLON); @@ -138,7 +138,7 @@ function matrixLinkify(linkify) { const S_GROUPID_COLON = new linkify.parser.State(); const S_GROUPID_COLON_NUM = new linkify.parser.State(GROUPID); - const groupid_tokens = [ + const groupIdTokens = [ TT.DOT, TT.UNDERSCORE, TT.PLUS, @@ -146,12 +146,12 @@ function matrixLinkify(linkify) { TT.DOMAIN, TT.TLD, - // as in roomname_tokens + // as in roomnameTokens TT.LOCALHOST, ]; - S_PLUS.on(groupid_tokens, S_PLUS_NAME); - S_PLUS_NAME.on(groupid_tokens, S_PLUS_NAME); + S_PLUS.on(groupIdTokens, S_PLUS_NAME); + S_PLUS_NAME.on(groupIdTokens, S_PLUS_NAME); S_PLUS_NAME.on(TT.DOMAIN, S_PLUS_NAME); S_PLUS_NAME.on(TT.COLON, S_PLUS_NAME_COLON); @@ -179,14 +179,14 @@ const escapeRegExp = function(string) { // Recognise URLs from both our local vector and official vector as vector. // anyone else really should be using matrix.to. -matrixLinkify.VECTOR_URL_PATTERN = "^(?:https?:\/\/)?(?:" +matrixLinkify.VECTOR_URL_PATTERN = "^(?:https?://)?(?:" + escapeRegExp(window.location.host + window.location.pathname) + "|" + "(?:www\\.)?(?:riot|vector)\\.im/(?:app|beta|staging|develop)/" + ")(#.*)"; -matrixLinkify.MATRIXTO_URL_PATTERN = "^(?:https?:\/\/)?(?:www\\.)?matrix\\.to/#/(([#@!+]).*)"; +matrixLinkify.MATRIXTO_URL_PATTERN = "^(?:https?://)?(?:www\\.)?matrix\\.to/#/(([#@!+]).*)"; matrixLinkify.MATRIXTO_MD_LINK_PATTERN = - '\\[([^\\]]*)\\]\\((?:https?:\/\/)?(?:www\\.)?matrix\\.to/#/([#@!+][^\\)]*)\\)'; + '\\[([^\\]]*)\\]\\((?:https?://)?(?:www\\.)?matrix\\.to/#/([#@!+][^\\)]*)\\)'; matrixLinkify.MATRIXTO_BASE_URL= baseUrl; const matrixToEntityMap = {