From 01b7d7bb7c05b194c0a2ec0198652951b0f32528 Mon Sep 17 00:00:00 2001 From: turt2live Date: Fri, 30 Jun 2017 08:44:56 -0600 Subject: [PATCH 01/55] Don't pad 12h timestamps Signed-off-by: Travis Ralston --- src/DateUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/DateUtils.js b/src/DateUtils.js index 545d92dd3b..79f5e1cfc0 100644 --- a/src/DateUtils.js +++ b/src/DateUtils.js @@ -55,7 +55,6 @@ function twelveHourTime(date) { let hours = date.getHours() % 12; const minutes = pad(date.getMinutes()); const ampm = date.getHours() >= 12 ? 'PM' : 'AM'; - hours = pad(hours ? hours : 12); return `${hours}:${minutes}${ampm}`; } From e058dd58e5893b5a8c0b0efc3827a258a434bacd Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 30 Jun 2017 09:29:40 -0600 Subject: [PATCH 02/55] Fix overzealous code deletion Signed-off-by: Travis Ralston --- src/DateUtils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DateUtils.js b/src/DateUtils.js index 79f5e1cfc0..56dd048945 100644 --- a/src/DateUtils.js +++ b/src/DateUtils.js @@ -55,6 +55,7 @@ function twelveHourTime(date) { let hours = date.getHours() % 12; const minutes = pad(date.getMinutes()); const ampm = date.getHours() >= 12 ? 'PM' : 'AM'; + hours = hours ? hours : 12; // convert 0 -> 12 return `${hours}:${minutes}${ampm}`; } From b315ed630e7ed2756854b6c17f10bd852d4cc0a9 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Fri, 30 Jun 2017 16:31:40 +0100 Subject: [PATCH 03/55] Match by emoji ascii regex first before shorthand Plaintext emojis that start with ":" will also match against the shorthand regex but the match won't include the important part of the plaintext emoji. This means some emoji like ":)" won't be matched. To fix this, put the ascii emoji regex first so that the match will be plaintext or otherwise it will fall through to the shorthand match (if there is one). Fixes https://github.com/vector-im/riot-web/issues/4467 --- src/autocomplete/EmojiProvider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/autocomplete/EmojiProvider.js b/src/autocomplete/EmojiProvider.js index 36aad68639..5afcbedd2e 100644 --- a/src/autocomplete/EmojiProvider.js +++ b/src/autocomplete/EmojiProvider.js @@ -41,7 +41,7 @@ const CATEGORY_ORDER = [ ]; // Match for ":wink:" or ascii-style ";-)" provided by emojione -const EMOJI_REGEX = new RegExp('(:\\w*:?|' + asciiRegexp + ')', 'g'); +const EMOJI_REGEX = new RegExp('(' + asciiRegexp + '|:\\w*:?)', 'g'); const EMOJI_SHORTNAMES = Object.keys(EmojiData).map((key) => EmojiData[key]).sort( (a, b) => { if (a.category === b.category) { From 9dba628f10f16fd616338631b5ab375f9ec51923 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 12:55:43 +0100 Subject: [PATCH 04/55] add missing commands to the Autocomplete CommandProvider Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/autocomplete/CommandProvider.js | 32 +++++++++++++++++++++++++++++ src/i18n/strings/en_EN.json | 6 ++++++ 2 files changed, 38 insertions(+) diff --git a/src/autocomplete/CommandProvider.js b/src/autocomplete/CommandProvider.js index 205a3737dc..d48e2d7b37 100644 --- a/src/autocomplete/CommandProvider.js +++ b/src/autocomplete/CommandProvider.js @@ -21,6 +21,7 @@ import AutocompleteProvider from './AutocompleteProvider'; import Fuse from 'fuse.js'; import {TextualCompletion} from './Components'; +// TODO merge this with the factory mechanics of SlashCommands? // Warning: Since the description string will be translated in _t(result.description), all these strings below must be in i18n/strings/en_EN.json file const COMMANDS = [ { @@ -33,6 +34,16 @@ const COMMANDS = [ args: ' [reason]', description: 'Bans user with given id', }, + { + command: '/unban', + args: ' [reason]', + description: 'Unbans user with given id', + }, + { + command: '/op', + args: '', + description: 'Ops user with given id', + }, { command: '/deop', args: '', @@ -48,6 +59,16 @@ const COMMANDS = [ args: '', description: 'Joins room with given alias', }, + { + command: '/part', + args: '', + description: 'Leaves room with given alias', + }, + { + command: '/topic', + args: '', + description: 'Sets the room topic', + }, { command: '/kick', args: ' [reason]', @@ -63,6 +84,17 @@ const COMMANDS = [ args: '', description: 'Searches DuckDuckGo for results', }, + { + command: '/tint', + args: ' []', + description: 'Change colourscheme of current room', + }, + { + command: '/verify', + args: ' ', + description: 'Verify a user, device, and pubkey tuple', + }, + // Omitting `/markdown` as it only seems to apply to OldComposer ]; const COMMAND_RE = /(^\/\w*)/g; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index a4dcb2873f..e3e64a808e 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -187,6 +187,7 @@ "Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. Either use HTTPS or enable unsafe scripts.": "Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. Either use HTTPS or enable unsafe scripts.", "Can't load user settings": "Can't load user settings", "Change Password": "Change Password", + "Change colourscheme of current room": "Change colourscheme of current room", "%(senderName)s changed their display name from %(oldDisplayName)s to %(displayName)s.": "%(senderName)s changed their display name from %(oldDisplayName)s to %(displayName)s.", "%(senderName)s changed their profile picture.": "%(senderName)s changed their profile picture.", "%(senderName)s changed the power level of %(powerLevelDiffText)s.": "%(senderName)s changed the power level of %(powerLevelDiffText)s.", @@ -376,6 +377,7 @@ "Labs": "Labs", "Last seen": "Last seen", "Leave room": "Leave room", + "Leaves room with given alias": "Leaves room with given alias", "left and rejoined": "left and rejoined", "left": "left", "%(targetName)s left the room.": "%(targetName)s left the room.", @@ -507,6 +509,7 @@ "%(senderName)s set their display name to %(displayName)s.": "%(senderName)s set their display name to %(displayName)s.", "Set": "Set", "Settings": "Settings", + "Sets the room topic": "Sets the room topic", "Show panel": "Show panel", "Show Text Formatting Toolbar": "Show Text Formatting Toolbar", "Show timestamps in 12 hour format (e.g. 2:30pm)": "Show timestamps in 12 hour format (e.g. 2:30pm)", @@ -581,6 +584,7 @@ "Unable to restore previous session": "Unable to restore previous session", "Unable to verify email address.": "Unable to verify email address.", "Unban": "Unban", + "Unbans user with given id": "Unbans user with given id", "%(senderName)s unbanned %(targetName)s.": "%(senderName)s unbanned %(targetName)s.", "Unable to ascertain that the address this invite was sent to matches one associated with your account.": "Unable to ascertain that the address this invite was sent to matches one associated with your account.", "Unable to capture screen": "Unable to capture screen", @@ -803,6 +807,7 @@ "Analytics": "Analytics", "Opt out of analytics": "Opt out of analytics", "Options": "Options", + "Ops user with given id": "Ops user with given id", "Riot collects anonymous analytics to allow us to improve the application.": "Riot collects anonymous analytics to allow us to improve the application.", "Passphrases must match": "Passphrases must match", "Passphrase must not be empty": "Passphrase must not be empty", @@ -835,6 +840,7 @@ "If it matches, press the verify button below. If it doesn't, then someone else is intercepting this device and you probably want to press the blacklist button instead.": "If it matches, press the verify button below. If it doesn't, then someone else is intercepting this device and you probably want to press the blacklist button instead.", "In future this verification process will be more sophisticated.": "In future this verification process will be more sophisticated.", "Verify device": "Verify device", + "Verify a user, device, and pubkey tuple": "Verify a user, device, and pubkey tuple", "I verify that the keys match": "I verify that the keys match", "We encountered an error trying to restore your previous session. If you continue, you will need to log in again, and encrypted chat history will be unreadable.": "We encountered an error trying to restore your previous session. If you continue, you will need to log in again, and encrypted chat history will be unreadable.", "Unable to restore session": "Unable to restore session", From fb61a5d68b6c5565995e82bda520c4a15b262555 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 13:08:23 +0100 Subject: [PATCH 05/55] post-merge fix Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/autocomplete/CommandProvider.js | 4 ++-- src/i18n/strings/en_EN.json | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/autocomplete/CommandProvider.js b/src/autocomplete/CommandProvider.js index cefe48afa2..3b09c9dd2d 100644 --- a/src/autocomplete/CommandProvider.js +++ b/src/autocomplete/CommandProvider.js @@ -87,12 +87,12 @@ const COMMANDS = [ { command: '/tint', args: ' []', - description: 'Change colourscheme of current room', + description: 'Changes colourscheme of current room', }, { command: '/verify', args: ' ', - description: 'Verify a user, device, and pubkey tuple', + description: 'Verifies a user, device, and pubkey tuple', }, // Omitting `/markdown` as it only seems to apply to OldComposer ]; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 397c2ecaaa..2d4eba3c2c 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -196,6 +196,7 @@ "%(senderDisplayName)s changed the topic to \"%(topic)s\".": "%(senderDisplayName)s changed the topic to \"%(topic)s\".", "Changes to who can read history will only apply to future messages in this room": "Changes to who can read history will only apply to future messages in this room", "Changes your display nickname": "Changes your display nickname", + "Changes colourscheme of current room": "Changes colourscheme of current room", "changing room on a RoomView is not supported": "changing room on a RoomView is not supported", "Changing password will currently reset any end-to-end encryption keys on all devices, making encrypted chat history unreadable, unless you first export your room keys and re-import them afterwards. In future this will be improved.": "Changing password will currently reset any end-to-end encryption keys on all devices, making encrypted chat history unreadable, unless you first export your room keys and re-import them afterwards. In future this will be improved.", "Claimed Ed25519 fingerprint key": "Claimed Ed25519 fingerprint key", @@ -512,6 +513,7 @@ "%(senderName)s set their display name to %(displayName)s.": "%(senderName)s set their display name to %(displayName)s.", "Set": "Set", "Settings": "Settings", + "Sets the room topic": "Sets the room topic", "Show Apps": "Show Apps", "Show panel": "Show panel", "Show Text Formatting Toolbar": "Show Text Formatting Toolbar", @@ -843,6 +845,7 @@ "If it matches, press the verify button below. If it doesn't, then someone else is intercepting this device and you probably want to press the blacklist button instead.": "If it matches, press the verify button below. If it doesn't, then someone else is intercepting this device and you probably want to press the blacklist button instead.", "In future this verification process will be more sophisticated.": "In future this verification process will be more sophisticated.", "Verify device": "Verify device", + "Verifies a user, device, and pubkey tuple": "Verifies a user, device, and pubkey tuple", "I verify that the keys match": "I verify that the keys match", "We encountered an error trying to restore your previous session. If you continue, you will need to log in again, and encrypted chat history will be unreadable.": "We encountered an error trying to restore your previous session. If you continue, you will need to log in again, and encrypted chat history will be unreadable.", "Unable to restore session": "Unable to restore session", From fde7d5eaf49413fc8442ca53dfd49a01233ed177 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 13:36:28 +0100 Subject: [PATCH 06/55] make RoomHeader Topic use EmojiText to be emojione-friendly Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/rooms/RoomHeader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/RoomHeader.js b/src/components/views/rooms/RoomHeader.js index 19010d8a10..c60f5c37ae 100644 --- a/src/components/views/rooms/RoomHeader.js +++ b/src/components/views/rooms/RoomHeader.js @@ -255,7 +255,7 @@ module.exports = React.createClass({ } } if (topic) { - topic_el =
{ topic }
; + topic_el = { topic }; } } From e56203f2a135dccee38ebfc6cab45418bb8b381e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 14:13:32 +0100 Subject: [PATCH 07/55] de-lint RoomHeader, Avatar, SdkConfig, SlashCommands Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 4 - src/Avatar.js | 20 +-- src/SdkConfig.js | 6 +- src/SlashCommands.js | 5 +- src/components/views/rooms/RoomHeader.js | 197 +++++++++++------------ 5 files changed, 109 insertions(+), 123 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index ffd492d491..2d383ea675 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -9,7 +9,6 @@ src/autocomplete/DuckDuckGoProvider.js src/autocomplete/EmojiProvider.js src/autocomplete/RoomProvider.js src/autocomplete/UserProvider.js -src/Avatar.js src/BasePlatform.js src/CallHandler.js src/component-index.js @@ -96,7 +95,6 @@ src/components/views/rooms/MessageComposerInput.js src/components/views/rooms/MessageComposerInputOld.js src/components/views/rooms/PresenceLabel.js src/components/views/rooms/ReadReceiptMarker.js -src/components/views/rooms/RoomHeader.js src/components/views/rooms/RoomList.js src/components/views/rooms/RoomNameEditor.js src/components/views/rooms/RoomPreviewBar.js @@ -148,9 +146,7 @@ src/RoomNotifs.js src/Rooms.js src/ScalarAuthClient.js src/ScalarMessaging.js -src/SdkConfig.js src/Skinner.js -src/SlashCommands.js src/stores/LifecycleStore.js src/TabComplete.js src/TabCompleteEntries.js diff --git a/src/Avatar.js b/src/Avatar.js index c0127d49af..d41a3f6a79 100644 --- a/src/Avatar.js +++ b/src/Avatar.js @@ -15,18 +15,18 @@ limitations under the License. */ 'use strict'; -var ContentRepo = require("matrix-js-sdk").ContentRepo; -var MatrixClientPeg = require('./MatrixClientPeg'); +import {ContentRepo} from 'matrix-js-sdk'; +import MatrixClientPeg from './MatrixClientPeg'; module.exports = { avatarUrlForMember: function(member, width, height, resizeMethod) { - var url = member.getAvatarUrl( + let url = member.getAvatarUrl( MatrixClientPeg.get().getHomeserverUrl(), Math.floor(width * window.devicePixelRatio), Math.floor(height * window.devicePixelRatio), resizeMethod, false, - false + false, ); if (!url) { // member can be null here currently since on invites, the JS SDK @@ -38,11 +38,11 @@ module.exports = { }, avatarUrlForUser: function(user, width, height, resizeMethod) { - var url = ContentRepo.getHttpUriForMxc( + const url = ContentRepo.getHttpUriForMxc( MatrixClientPeg.get().getHomeserverUrl(), user.avatarUrl, Math.floor(width * window.devicePixelRatio), Math.floor(height * window.devicePixelRatio), - resizeMethod + resizeMethod, ); if (!url || url.length === 0) { return null; @@ -51,11 +51,11 @@ module.exports = { }, defaultAvatarUrlForString: function(s) { - var images = ['76cfa6', '50e2c2', 'f4c371']; - var total = 0; - for (var i = 0; i < s.length; ++i) { + const images = ['76cfa6', '50e2c2', 'f4c371']; + let total = 0; + for (let i = 0; i < s.length; ++i) { total += s.charCodeAt(i); } return 'img/' + images[total % images.length] + '.png'; - } + }, }; diff --git a/src/SdkConfig.js b/src/SdkConfig.js index 8d8e93a889..48ebf011f2 100644 --- a/src/SdkConfig.js +++ b/src/SdkConfig.js @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -var DEFAULTS = { +const DEFAULTS = { // URL to a page we show in an iframe to configure integrations integrations_ui_url: "https://scalar.vector.im/", // Base URL to the REST interface of the integrations server @@ -30,8 +30,8 @@ class SdkConfig { } static put(cfg) { - var defaultKeys = Object.keys(DEFAULTS); - for (var i = 0; i < defaultKeys.length; ++i) { + const defaultKeys = Object.keys(DEFAULTS); + for (let i = 0; i < defaultKeys.length; ++i) { if (cfg[defaultKeys[i]] === undefined) { cfg[defaultKeys[i]] = DEFAULTS[defaultKeys[i]]; } diff --git a/src/SlashCommands.js b/src/SlashCommands.js index 185ea504ac..b1cd59f3a9 100644 --- a/src/SlashCommands.js +++ b/src/SlashCommands.js @@ -186,7 +186,7 @@ const commands = { if (targetRoomId) { break; } } if (!targetRoomId) { - return reject(_t("Unrecognised room alias:") + ' ' + roomAlias); + return reject(_t("Unrecognised room alias:") + ' ' + roomAlias); } } } @@ -344,8 +344,7 @@ const commands = { _t('WARNING: KEY VERIFICATION FAILED! The signing key for %(userId)s and device' + ' %(deviceId)s is "%(fprint)s" which does not match the provided key' + ' "%(fingerprint)s". This could mean your communications are being intercepted!', - {deviceId: deviceId, fprint: fprint, userId: userId, fingerprint: fingerprint}) - ); + {deviceId: deviceId, fprint: fprint, userId: userId, fingerprint: fingerprint})); } } } diff --git a/src/components/views/rooms/RoomHeader.js b/src/components/views/rooms/RoomHeader.js index 19010d8a10..ce163003c0 100644 --- a/src/components/views/rooms/RoomHeader.js +++ b/src/components/views/rooms/RoomHeader.js @@ -16,18 +16,18 @@ limitations under the License. 'use strict'; -var React = require('react'); -var classNames = require('classnames'); -var sdk = require('../../../index'); +import React from 'react'; +import classNames from 'classnames'; +import sdk from '../../../index'; import { _t } from '../../../languageHandler'; -var MatrixClientPeg = require('../../../MatrixClientPeg'); -var Modal = require("../../../Modal"); -var dis = require("../../../dispatcher"); -var rate_limited_func = require('../../../ratelimitedfunc'); +import MatrixClientPeg from '../../../MatrixClientPeg'; +import Modal from "../../../Modal"; +import dis from "../../../dispatcher"; +import RateLimitedFunc from '../../../ratelimitedfunc'; -var linkify = require('linkifyjs'); -var linkifyElement = require('linkifyjs/element'); -var linkifyMatrix = require('../../../linkify-matrix'); +import * as linkify from 'linkifyjs'; +import linkifyElement from 'linkifyjs/element'; +import linkifyMatrix from '../../../linkify-matrix'; import AccessibleButton from '../elements/AccessibleButton'; import {CancelButton} from './SimpleRoomHeader'; @@ -58,7 +58,7 @@ module.exports = React.createClass({ }, componentDidMount: function() { - var cli = MatrixClientPeg.get(); + const cli = MatrixClientPeg.get(); cli.on("RoomState.events", this._onRoomStateEvents); // When a room name occurs, RoomState.events is fired *before* @@ -79,14 +79,14 @@ module.exports = React.createClass({ if (this.props.room) { this.props.room.removeListener("Room.name", this._onRoomNameChange); } - var cli = MatrixClientPeg.get(); + const cli = MatrixClientPeg.get(); if (cli) { cli.removeListener("RoomState.events", this._onRoomStateEvents); } }, _onRoomStateEvents: function(event, state) { - if (!this.props.room || event.getRoomId() != this.props.room.roomId) { + if (!this.props.room || event.getRoomId() !== this.props.room.roomId) { return; } @@ -94,7 +94,8 @@ module.exports = React.createClass({ this._rateLimitedUpdate(); }, - _rateLimitedUpdate: new rate_limited_func(function() { + _rateLimitedUpdate: new RateLimitedFunc(function() { + /* eslint-disable babel/no-invalid-this */ this.forceUpdate(); }, 500), @@ -109,15 +110,14 @@ module.exports = React.createClass({ }, onAvatarSelected: function(ev) { - var self = this; - var changeAvatar = this.refs.changeAvatar; + const changeAvatar = this.refs.changeAvatar; if (!changeAvatar) { console.error("No ChangeAvatar found to upload image to!"); return; } changeAvatar.onFileSelected(ev).catch(function(err) { - var errMsg = (typeof err === "string") ? err : (err.error || ""); - var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); + const errMsg = (typeof err === "string") ? err : (err.error || ""); + const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); console.error("Failed to set avatar: " + errMsg); Modal.createDialog(ErrorDialog, { title: _t("Error"), @@ -133,10 +133,10 @@ module.exports = React.createClass({ /** * After editing the settings, get the new name for the room * - * Returns undefined if we didn't let the user edit the room name + * @return {?string} newName or undefined if we didn't let the user edit the room name */ getEditedName: function() { - var newName; + let newName; if (this.refs.nameEditor) { newName = this.refs.nameEditor.getRoomName(); } @@ -146,10 +146,10 @@ module.exports = React.createClass({ /** * After editing the settings, get the new topic for the room * - * Returns undefined if we didn't let the user edit the room topic + * @return {?string} newTopic or undefined if we didn't let the user edit the room topic */ getEditedTopic: function() { - var newTopic; + let newTopic; if (this.refs.topicEditor) { newTopic = this.refs.topicEditor.getTopic(); } @@ -157,38 +157,31 @@ module.exports = React.createClass({ }, render: function() { - var RoomAvatar = sdk.getComponent("avatars.RoomAvatar"); - var ChangeAvatar = sdk.getComponent("settings.ChangeAvatar"); - var TintableSvg = sdk.getComponent("elements.TintableSvg"); + const RoomAvatar = sdk.getComponent("avatars.RoomAvatar"); + const ChangeAvatar = sdk.getComponent("settings.ChangeAvatar"); + const TintableSvg = sdk.getComponent("elements.TintableSvg"); const EmojiText = sdk.getComponent('elements.EmojiText'); - var header; - var name = null; - var searchStatus = null; - var topic_el = null; - var cancel_button = null; - var spinner = null; - var save_button = null; - var settings_button = null; + let name = null; + let searchStatus = null; + let topicElement = null; + let cancelButton = null; + let spinner = null; + let saveButton = null; + let settingsButton = null; + + let canSetRoomName; + let canSetRoomAvatar; + let canSetRoomTopic; if (this.props.editing) { - // calculate permissions. XXX: this should be done on mount or something - var user_id = MatrixClientPeg.get().credentials.userId; + const userId = MatrixClientPeg.get().credentials.userId; - var can_set_room_name = this.props.room.currentState.maySendStateEvent( - 'm.room.name', user_id - ); - var can_set_room_avatar = this.props.room.currentState.maySendStateEvent( - 'm.room.avatar', user_id - ); - var can_set_room_topic = this.props.room.currentState.maySendStateEvent( - 'm.room.topic', user_id - ); - var can_set_room_name = this.props.room.currentState.maySendStateEvent( - 'm.room.name', user_id - ); + canSetRoomName = this.props.room.currentState.maySendStateEvent('m.room.name', userId); + canSetRoomAvatar = this.props.room.currentState.maySendStateEvent('m.room.avatar', userId); + canSetRoomTopic = this.props.room.currentState.maySendStateEvent('m.room.topic', userId); - save_button = ( + saveButton = ( {_t("Save")} @@ -196,39 +189,41 @@ module.exports = React.createClass({ } if (this.props.onCancelClick) { - cancel_button = ; + cancelButton = ; } if (this.props.saving) { - var Spinner = sdk.getComponent("elements.Spinner"); + const Spinner = sdk.getComponent("elements.Spinner"); spinner =
; } - if (can_set_room_name) { - var RoomNameEditor = sdk.getComponent("rooms.RoomNameEditor"); + if (canSetRoomName) { + const RoomNameEditor = sdk.getComponent("rooms.RoomNameEditor"); name = ; - } - else { - var searchStatus; + } else { // don't display the search count until the search completes and // gives us a valid (possibly zero) searchCount. - if (this.props.searchInfo && this.props.searchInfo.searchCount !== undefined && this.props.searchInfo.searchCount !== null) { - searchStatus =
 { _t("(~%(count)s results)", { count: this.props.searchInfo.searchCount }) }
; + if (this.props.searchInfo && + this.props.searchInfo.searchCount !== undefined && + this.props.searchInfo.searchCount !== null) { + searchStatus =
  + { _t("(~%(count)s results)", { count: this.props.searchInfo.searchCount }) } +
; } // XXX: this is a bit inefficient - we could just compare room.name for 'Empty room'... - var settingsHint = false; - var members = this.props.room ? this.props.room.getJoinedMembers() : undefined; + let settingsHint = false; + const members = this.props.room ? this.props.room.getJoinedMembers() : undefined; if (members) { if (members.length === 1 && members[0].userId === MatrixClientPeg.get().credentials.userId) { - var name = this.props.room.currentState.getStateEvents('m.room.name', ''); + name = this.props.room.currentState.getStateEvents('m.room.name', ''); if (!name || !name.getContent().name) { settingsHint = true; } } } - var roomName = _t("Join Room"); + let roomName = _t("Join Room"); if (this.props.oobData && this.props.oobData.name) { roomName = this.props.oobData.name; } else if (this.props.room) { @@ -243,24 +238,25 @@ module.exports = React.createClass({ ; } - if (can_set_room_topic) { - var RoomTopicEditor = sdk.getComponent("rooms.RoomTopicEditor"); - topic_el = ; + if (canSetRoomTopic) { + const RoomTopicEditor = sdk.getComponent("rooms.RoomTopicEditor"); + topicElement = ; } else { - var topic; + let topic; if (this.props.room) { - var ev = this.props.room.currentState.getStateEvents('m.room.topic', ''); + const ev = this.props.room.currentState.getStateEvents('m.room.topic', ''); if (ev) { topic = ev.getContent().topic; } } if (topic) { - topic_el =
{ topic }
; + topicElement = +
{ topic }
; } } - var roomAvatar = null; - if (can_set_room_avatar) { + let roomAvatar = null; + if (canSetRoomAvatar) { roomAvatar = (
@@ -276,8 +272,7 @@ module.exports = React.createClass({
); - } - else if (this.props.room || (this.props.oobData && this.props.oobData.name)) { + } else if (this.props.room || (this.props.oobData && this.props.oobData.name)) { roomAvatar = (
@@ -285,9 +280,8 @@ module.exports = React.createClass({ ); } - var settings_button; if (this.props.onSettingsClick) { - settings_button = + settingsButton = ; @@ -301,61 +295,58 @@ module.exports = React.createClass({ //
; // } - var forget_button; + let forgetButton; if (this.props.onForgetClick) { - forget_button = + forgetButton = ; } - let search_button; + let searchButton; if (this.props.onSearchClick && this.props.inRoom) { - search_button = + searchButton = ; } - var rightPanel_buttons; + let rightPanelButtons; if (this.props.collapsedRhs) { - rightPanel_buttons = + rightPanelButtons = ; } - var right_row; + let rightRow; if (!this.props.editing) { - right_row = + rightRow =
- { settings_button } - { forget_button } - { search_button } - { rightPanel_buttons } + { settingsButton } + { forgetButton } + { searchButton } + { rightPanelButtons }
; } - header = -
-
-
- { roomAvatar } -
-
- { name } - { topic_el } -
-
- {spinner} - {save_button} - {cancel_button} - {right_row} -
; - return (
- { header } +
+
+
+ { roomAvatar } +
+
+ { name } + { topicElement } +
+
+ {spinner} + {saveButton} + {cancelButton} + {rightRow} +
); }, From 09ae6bba0726ff74d0c893fd53c83fef3282938c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 14:15:26 +0100 Subject: [PATCH 08/55] de-lint BasePlatform Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 1 - src/BasePlatform.js | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 2d383ea675..c459422c78 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -9,7 +9,6 @@ src/autocomplete/DuckDuckGoProvider.js src/autocomplete/EmojiProvider.js src/autocomplete/RoomProvider.js src/autocomplete/UserProvider.js -src/BasePlatform.js src/CallHandler.js src/component-index.js src/components/structures/ContextualMenu.js diff --git a/src/BasePlatform.js b/src/BasePlatform.js index a920479823..5f8772c7aa 100644 --- a/src/BasePlatform.js +++ b/src/BasePlatform.js @@ -57,6 +57,7 @@ export default class BasePlatform { /** * Returns true if the platform supports displaying * notifications, otherwise false. + * @returns {boolean} whether the platform supports displaying notifications */ supportsNotifications(): boolean { return false; @@ -65,6 +66,7 @@ export default class BasePlatform { /** * Returns true if the application currently has permission * to display notifications. Otherwise false. + * @returns {boolean} whether the application has permission to display notifications */ maySendNotifications(): boolean { return false; From b8ad0957b2434ae1deaf4b302f04f1c9e9158f97 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 14:21:28 +0100 Subject: [PATCH 09/55] de-lint AddThreepid Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 1 - src/AddThreepid.js | 16 ++++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index c459422c78..6fbb51b0fd 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -1,6 +1,5 @@ # autogenerated file: run scripts/generate-eslint-error-ignore-file to update. -src/AddThreepid.js src/async-components/views/dialogs/EncryptedEventDialog.js src/autocomplete/AutocompleteProvider.js src/autocomplete/Autocompleter.js diff --git a/src/AddThreepid.js b/src/AddThreepid.js index 8be7a19b13..337e38d867 100644 --- a/src/AddThreepid.js +++ b/src/AddThreepid.js @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -var MatrixClientPeg = require("./MatrixClientPeg"); +import MatrixClientPeg from './MatrixClientPeg'; import { _t } from './languageHandler'; /** @@ -44,7 +44,7 @@ class AddThreepid { this.sessionId = res.sid; return res; }, function(err) { - if (err.errcode == 'M_THREEPID_IN_USE') { + if (err.errcode === 'M_THREEPID_IN_USE') { err.message = _t('This email address is already in use'); } else if (err.httpStatus) { err.message = err.message + ` (Status ${err.httpStatus})`; @@ -69,7 +69,7 @@ class AddThreepid { this.sessionId = res.sid; return res; }, function(err) { - if (err.errcode == 'M_THREEPID_IN_USE') { + if (err.errcode === 'M_THREEPID_IN_USE') { err.message = _t('This phone number is already in use'); } else if (err.httpStatus) { err.message = err.message + ` (Status ${err.httpStatus})`; @@ -85,16 +85,15 @@ class AddThreepid { * the request failed. */ checkEmailLinkClicked() { - var identityServerDomain = MatrixClientPeg.get().idBaseUrl.split("://")[1]; + const identityServerDomain = MatrixClientPeg.get().idBaseUrl.split("://")[1]; return MatrixClientPeg.get().addThreePid({ sid: this.sessionId, client_secret: this.clientSecret, - id_server: identityServerDomain + id_server: identityServerDomain, }, this.bind).catch(function(err) { if (err.httpStatus === 401) { err.message = _t('Failed to verify email address: make sure you clicked the link in the email'); - } - else if (err.httpStatus) { + } else if (err.httpStatus) { err.message += ` (Status ${err.httpStatus})`; } throw err; @@ -104,6 +103,7 @@ class AddThreepid { /** * Takes a phone number verification code as entered by the user and validates * it with the ID server, then if successful, adds the phone number. + * @param {string} token phone number verification code as entered by the user * @return {Promise} Resolves if the phone number was added. Rejects with an object * with a "message" property which contains a human-readable message detailing why * the request failed. @@ -119,7 +119,7 @@ class AddThreepid { return MatrixClientPeg.get().addThreePid({ sid: this.sessionId, client_secret: this.clientSecret, - id_server: identityServerDomain + id_server: identityServerDomain, }, this.bind); }); } From b98c105dcc09166cc0dd7e9dc97ea29087deea13 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 14:28:12 +0100 Subject: [PATCH 10/55] de-lint Skinner, RoomNotifs Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 2 -- src/RoomNotifs.js | 30 ++++++++++-------------------- src/Skinner.js | 11 +++++------ 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 6fbb51b0fd..57639aa3a5 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -140,11 +140,9 @@ src/Resend.js src/RichText.js src/Roles.js src/RoomListSorter.js -src/RoomNotifs.js src/Rooms.js src/ScalarAuthClient.js src/ScalarMessaging.js -src/Skinner.js src/stores/LifecycleStore.js src/TabComplete.js src/TabCompleteEntries.js diff --git a/src/RoomNotifs.js b/src/RoomNotifs.js index 7cb7d4b9de..88b6e56c7f 100644 --- a/src/RoomNotifs.js +++ b/src/RoomNotifs.js @@ -52,7 +52,7 @@ export function getRoomNotifsState(roomId) { } export function setRoomNotifsState(roomId, newState) { - if (newState == MUTE) { + if (newState === MUTE) { return setRoomNotifsStateMuted(roomId); } else { return setRoomNotifsStateUnmuted(roomId, newState); @@ -80,11 +80,11 @@ function setRoomNotifsStateMuted(roomId) { kind: 'event_match', key: 'room_id', pattern: roomId, - } + }, ], actions: [ 'dont_notify', - ] + ], })); return q.all(promises); @@ -99,16 +99,16 @@ function setRoomNotifsStateUnmuted(roomId, newState) { promises.push(cli.deletePushRule('global', 'override', overrideMuteRule.rule_id)); } - if (newState == 'all_messages') { + if (newState === 'all_messages') { const roomRule = cli.getRoomPushRule('global', roomId); if (roomRule) { promises.push(cli.deletePushRule('global', 'room', roomRule.rule_id)); } - } else if (newState == 'mentions_only') { + } else if (newState === 'mentions_only') { promises.push(cli.addPushRule('global', 'room', roomId, { actions: [ 'dont_notify', - ] + ], })); // https://matrix.org/jira/browse/SPEC-400 promises.push(cli.setPushRuleEnabled('global', 'room', roomId, true)); @@ -119,8 +119,8 @@ function setRoomNotifsStateUnmuted(roomId, newState) { { set_tweak: 'sound', value: 'default', - } - ] + }, + ], })); // https://matrix.org/jira/browse/SPEC-400 promises.push(cli.setPushRuleEnabled('global', 'room', roomId, true)); @@ -145,20 +145,10 @@ function isRuleForRoom(roomId, rule) { return false; } const cond = rule.conditions[0]; - if ( - cond.kind == 'event_match' && - cond.key == 'room_id' && - cond.pattern == roomId - ) { - return true; - } - return false; + return (cond.kind === 'event_match' && cond.key === 'room_id' && cond.pattern === roomId); } function isMuteRule(rule) { - return ( - rule.actions.length == 1 && - rule.actions[0] == 'dont_notify' - ); + return (rule.actions.length === 1 && rule.actions[0] === 'dont_notify'); } diff --git a/src/Skinner.js b/src/Skinner.js index 0688c9fc26..f47572ba01 100644 --- a/src/Skinner.js +++ b/src/Skinner.js @@ -51,19 +51,18 @@ class Skinner { if (this.components !== null) { throw new Error( "Attempted to load a skin while a skin is already loaded"+ - "If you want to change the active skin, call resetSkin first" - ); + "If you want to change the active skin, call resetSkin first"); } this.components = {}; - var compKeys = Object.keys(skinObject.components); - for (var i = 0; i < compKeys.length; ++i) { - var comp = skinObject.components[compKeys[i]]; + const compKeys = Object.keys(skinObject.components); + for (let i = 0; i < compKeys.length; ++i) { + const comp = skinObject.components[compKeys[i]]; this.addComponent(compKeys[i], comp); } } addComponent(name, comp) { - var slot = name; + let slot = name; if (comp.replaces !== undefined) { if (comp.replaces.indexOf('.') > -1) { slot = comp.replaces; From fdd8df87b0ed1ee3c4c719c0234f7a30fad1462c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 14:31:59 +0100 Subject: [PATCH 11/55] de-lint PasswordReset Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 1 - src/PasswordReset.js | 19 +++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 57639aa3a5..9fd55dca7f 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -132,7 +132,6 @@ src/MatrixClientPeg.js src/Modal.js src/Notifier.js src/ObjectUtils.js -src/PasswordReset.js src/PlatformPeg.js src/Presence.js src/ratelimitedfunc.js diff --git a/src/PasswordReset.js b/src/PasswordReset.js index 0739ca0a24..71fc4f6b31 100644 --- a/src/PasswordReset.js +++ b/src/PasswordReset.js @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -var Matrix = require("matrix-js-sdk"); +import * as Matrix from 'matrix-js-sdk'; import { _t } from './languageHandler'; /** @@ -34,7 +34,7 @@ class PasswordReset { constructor(homeserverUrl, identityUrl) { this.client = Matrix.createClient({ baseUrl: homeserverUrl, - idBaseUrl: identityUrl + idBaseUrl: identityUrl, }); this.clientSecret = this.client.generateClientSecret(); this.identityServerDomain = identityUrl.split("://")[1]; @@ -53,7 +53,7 @@ class PasswordReset { this.sessionId = res.sid; return res; }, function(err) { - if (err.errcode == 'M_THREEPID_NOT_FOUND') { + if (err.errcode === 'M_THREEPID_NOT_FOUND') { err.message = _t('This email address was not found'); } else if (err.httpStatus) { err.message = err.message + ` (Status ${err.httpStatus})`; @@ -75,16 +75,15 @@ class PasswordReset { threepid_creds: { sid: this.sessionId, client_secret: this.clientSecret, - id_server: this.identityServerDomain - } + id_server: this.identityServerDomain, + }, }, this.password).catch(function(err) { if (err.httpStatus === 401) { err.message = _t('Failed to verify email address: make sure you clicked the link in the email'); - } - else if (err.httpStatus === 404) { - err.message = _t('Your email address does not appear to be associated with a Matrix ID on this Homeserver.'); - } - else if (err.httpStatus) { + } else if (err.httpStatus === 404) { + err.message = + _t('Your email address does not appear to be associated with a Matrix ID on this Homeserver.'); + } else if (err.httpStatus) { err.message += ` (Status ${err.httpStatus})`; } throw err; From a270c852954793a74458c6ce1f0b5bfb099cf740 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 14:34:20 +0100 Subject: [PATCH 12/55] de-lint Entities Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 1 - src/Entities.js | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 9fd55dca7f..c8eff5868b 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -119,7 +119,6 @@ src/ContentMessages.js src/createRoom.js src/DateUtils.js src/email.js -src/Entities.js src/extend.js src/HtmlUtils.js src/ImageUtils.js diff --git a/src/Entities.js b/src/Entities.js index 7c3909f36f..21abd9c473 100644 --- a/src/Entities.js +++ b/src/Entities.js @@ -14,8 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -var React = require('react'); -var sdk = require('./index'); +import sdk from './index'; function isMatch(query, name, uid) { query = query.toLowerCase(); @@ -33,8 +32,8 @@ function isMatch(query, name, uid) { } // split spaces in name and try matching constituent parts - var parts = name.split(" "); - for (var i = 0; i < parts.length; i++) { + const parts = name.split(" "); + for (let i = 0; i < parts.length; i++) { if (parts[i].indexOf(query) === 0) { return true; } @@ -67,7 +66,7 @@ class Entity { class MemberEntity extends Entity { getJsx() { - var MemberTile = sdk.getComponent("rooms.MemberTile"); + const MemberTile = sdk.getComponent("rooms.MemberTile"); return ( ); @@ -84,6 +83,7 @@ class UserEntity extends Entity { super(model); this.showInviteButton = Boolean(showInviteButton); this.inviteFn = inviteFn; + this.onClick = this.onClick.bind(this); } onClick() { @@ -93,15 +93,15 @@ class UserEntity extends Entity { } getJsx() { - var UserTile = sdk.getComponent("rooms.UserTile"); + const UserTile = sdk.getComponent("rooms.UserTile"); return ( + showInviteButton={this.showInviteButton} onClick={this.onClick} /> ); } matches(queryString) { - var name = this.model.displayName || this.model.userId; + const name = this.model.displayName || this.model.userId; return isMatch(queryString, name, this.model.userId); } } @@ -109,7 +109,7 @@ class UserEntity extends Entity { module.exports = { newEntity: function(jsx, matchFn) { - var entity = new Entity(); + const entity = new Entity(); entity.getJsx = function() { return jsx; }; @@ -137,5 +137,5 @@ module.exports = { return users.map(function(u) { return new UserEntity(u, showInviteButton, inviteFn); }); - } + }, }; From 68fb11d2bf65b64a33929a2feec638d7a168a4df Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 14:35:40 +0100 Subject: [PATCH 13/55] de-lint LifecycleStore Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 1 - src/stores/LifecycleStore.js | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index c8eff5868b..171eb36f35 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -141,7 +141,6 @@ src/RoomListSorter.js src/Rooms.js src/ScalarAuthClient.js src/ScalarMessaging.js -src/stores/LifecycleStore.js src/TabComplete.js src/TabCompleteEntries.js src/TextForEvent.js diff --git a/src/stores/LifecycleStore.js b/src/stores/LifecycleStore.js index d954ef16b6..0d76f06e72 100644 --- a/src/stores/LifecycleStore.js +++ b/src/stores/LifecycleStore.js @@ -50,7 +50,7 @@ class LifecycleStore extends Store { deferred_action: null, }); break; - case 'sync_state': + case 'sync_state': { if (payload.state !== 'PREPARED') { break; } @@ -61,6 +61,7 @@ class LifecycleStore extends Store { }); dis.dispatch(deferredAction); break; + } case 'on_logged_out': this.reset(); break; From 7da14d7078da75ae04349feed2667e61703f722b Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 14:38:32 +0100 Subject: [PATCH 14/55] de-lint ObjectUtils Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 1 - src/ObjectUtils.js | 26 ++++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 171eb36f35..661cdebf41 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -130,7 +130,6 @@ src/Markdown.js src/MatrixClientPeg.js src/Modal.js src/Notifier.js -src/ObjectUtils.js src/PlatformPeg.js src/Presence.js src/ratelimitedfunc.js diff --git a/src/ObjectUtils.js b/src/ObjectUtils.js index 5fac588a4f..07d8b465af 100644 --- a/src/ObjectUtils.js +++ b/src/ObjectUtils.js @@ -23,8 +23,8 @@ limitations under the License. * { key: $KEY, val: $VALUE, place: "add|del" } */ module.exports.getKeyValueArrayDiffs = function(before, after) { - var results = []; - var delta = {}; + const results = []; + const delta = {}; Object.keys(before).forEach(function(beforeKey) { delta[beforeKey] = delta[beforeKey] || 0; // init to 0 initially delta[beforeKey]--; // keys present in the past have -ve values @@ -46,9 +46,9 @@ module.exports.getKeyValueArrayDiffs = function(before, after) { results.push({ place: "del", key: muxedKey, val: beforeVal }); }); break; - case 0: // A mix of added/removed keys + case 0: {// A mix of added/removed keys // compare old & new vals - var itemDelta = {}; + const itemDelta = {}; before[muxedKey].forEach(function(beforeVal) { itemDelta[beforeVal] = itemDelta[beforeVal] || 0; itemDelta[beforeVal]--; @@ -68,9 +68,9 @@ module.exports.getKeyValueArrayDiffs = function(before, after) { } }); break; + } default: - console.error("Calculated key delta of " + delta[muxedKey] + - " - this should never happen!"); + console.error("Calculated key delta of " + delta[muxedKey] + " - this should never happen!"); break; } }); @@ -79,8 +79,10 @@ module.exports.getKeyValueArrayDiffs = function(before, after) { }; /** - * Shallow-compare two objects for equality: each key and value must be - * identical + * Shallow-compare two objects for equality: each key and value must be identical + * @param {Object} objA First object to compare against the second + * @param {Object} objB Second object to compare against the first + * @return {boolean} whether the two objects have same key=values */ module.exports.shallowEqual = function(objA, objB) { if (objA === objB) { @@ -92,15 +94,15 @@ module.exports.shallowEqual = function(objA, objB) { return false; } - var keysA = Object.keys(objA); - var keysB = Object.keys(objB); + const keysA = Object.keys(objA); + const keysB = Object.keys(objB); if (keysA.length !== keysB.length) { return false; } - for (var i = 0; i < keysA.length; i++) { - var key = keysA[i]; + for (let i = 0; i < keysA.length; i++) { + const key = keysA[i]; if (!objB.hasOwnProperty(key) || objA[key] !== objB[key]) { return false; } From b9379576094129ffee02b596fd3daaa93b043c73 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 14:40:46 +0100 Subject: [PATCH 15/55] de-lint createRoom Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 1 - src/createRoom.js | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 661cdebf41..1814d7ee83 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -116,7 +116,6 @@ src/components/views/voip/IncomingCallBox.js src/components/views/voip/VideoFeed.js src/components/views/voip/VideoView.js src/ContentMessages.js -src/createRoom.js src/DateUtils.js src/email.js src/extend.js diff --git a/src/createRoom.js b/src/createRoom.js index ce83f31c27..8aa15f315b 100644 --- a/src/createRoom.js +++ b/src/createRoom.js @@ -14,24 +14,24 @@ See the License for the specific language governing permissions and limitations under the License. */ -var MatrixClientPeg = require('./MatrixClientPeg'); -var Modal = require('./Modal'); -var sdk = require('./index'); +import MatrixClientPeg from './MatrixClientPeg'; +import Modal from './Modal'; +import sdk from './index'; import { _t } from './languageHandler'; -var dis = require("./dispatcher"); -var Rooms = require("./Rooms"); +import dis from "./dispatcher"; +import Rooms from "./Rooms"; -var q = require('q'); +import q from 'q'; /** * Create a new room, and switch to it. * - * Returns a promise which resolves to the room id, or null if the - * action was aborted or failed. - * * @param {object=} opts parameters for creating the room * @param {string=} opts.dmUserId If specified, make this a DM room for this user and invite them * @param {object=} opts.createOpts set of options to pass to createRoom call. + * + * @returns {Promise} which resolves to the room id, or null if the + * action was aborted or failed. */ function createRoom(opts) { opts = opts || {}; @@ -69,11 +69,11 @@ function createRoom(opts) { createOpts.initial_state = createOpts.initial_state || [ { content: { - guest_access: 'can_join' + guest_access: 'can_join', }, type: 'm.room.guest_access', state_key: '', - } + }, ]; const modal = Modal.createDialog(Loader, null, 'mx_Dialog_spinner'); From f514f1ff7488469eaade426a642e71a388200b4e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 14:42:12 +0100 Subject: [PATCH 16/55] de-lint DateUtils Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 1 - src/DateUtils.js | 13 +++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 1814d7ee83..06e810bd9c 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -116,7 +116,6 @@ src/components/views/voip/IncomingCallBox.js src/components/views/voip/VideoFeed.js src/components/views/voip/VideoView.js src/ContentMessages.js -src/DateUtils.js src/email.js src/extend.js src/HtmlUtils.js diff --git a/src/DateUtils.js b/src/DateUtils.js index 545d92dd3b..0f3aa01bc8 100644 --- a/src/DateUtils.js +++ b/src/DateUtils.js @@ -61,17 +61,18 @@ function twelveHourTime(date) { module.exports = { formatDate: function(date, showTwelveHour=false) { - var now = new Date(); + const now = new Date(); const days = getDaysArray(); const months = getMonthsArray(); if (date.toDateString() === now.toDateString()) { return this.formatTime(date); - } - else if (now.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000) { + } else if (now.getTime() - date.getTime() < 6 * 24 * 60 * 60 * 1000) { // TODO: use standard date localize function provided in counterpart - return _t('%(weekDayName)s %(time)s', {weekDayName: days[date.getDay()], time: this.formatTime(date, showTwelveHour)}); - } - else if (now.getFullYear() === date.getFullYear()) { + return _t('%(weekDayName)s %(time)s', { + weekDayName: days[date.getDay()], + time: this.formatTime(date, showTwelveHour), + }); + } else if (now.getFullYear() === date.getFullYear()) { // TODO: use standard date localize function provided in counterpart return _t('%(weekDayName)s, %(monthName)s %(day)s %(time)s', { weekDayName: days[date.getDay()], From 8bf13f8f48cebae8851696e44cab7ec63fbc64fb Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 14:43:18 +0100 Subject: [PATCH 17/55] de-lint email, extend Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 2 -- src/email.js | 4 ++-- src/extend.js | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 06e810bd9c..9d5525cac9 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -116,8 +116,6 @@ src/components/views/voip/IncomingCallBox.js src/components/views/voip/VideoFeed.js src/components/views/voip/VideoView.js src/ContentMessages.js -src/email.js -src/extend.js src/HtmlUtils.js src/ImageUtils.js src/Invite.js diff --git a/src/email.js b/src/email.js index c4375079d7..3fd535c849 100644 --- a/src/email.js +++ b/src/email.js @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -var EMAIL_ADDRESS_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; +const EMAIL_ADDRESS_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; module.exports = { looksValid: function(email) { return EMAIL_ADDRESS_REGEX.test(email); - } + }, }; diff --git a/src/extend.js b/src/extend.js index cc3c33b2e7..4b3f028a94 100644 --- a/src/extend.js +++ b/src/extend.js @@ -17,7 +17,7 @@ limitations under the License. 'use strict'; module.exports = function(dest, src) { - for (var i in src) { + for (const i in src) { if (src.hasOwnProperty(i)) { dest[i] = src[i]; } From 661a0f3956a14526f66452d1dd73e09399230181 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 14:50:22 +0100 Subject: [PATCH 18/55] de-lint Resend, RoomListSorter, UserActivity Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 3 --- src/Resend.js | 16 ++++++---------- src/Roles.js | 2 +- src/RoomListSorter.js | 5 ++--- src/UserActivity.js | 29 ++++++++++++----------------- 5 files changed, 21 insertions(+), 34 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 9d5525cac9..3d4207caa2 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -129,10 +129,8 @@ src/Notifier.js src/PlatformPeg.js src/Presence.js src/ratelimitedfunc.js -src/Resend.js src/RichText.js src/Roles.js -src/RoomListSorter.js src/Rooms.js src/ScalarAuthClient.js src/ScalarMessaging.js @@ -142,7 +140,6 @@ src/TextForEvent.js src/Tinter.js src/UiEffects.js src/Unread.js -src/UserActivity.js src/utils/DecryptFile.js src/utils/DMRoomMap.js src/utils/FormattingUtils.js diff --git a/src/Resend.js b/src/Resend.js index bbd980ea7f..1fee5854ea 100644 --- a/src/Resend.js +++ b/src/Resend.js @@ -14,10 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -var MatrixClientPeg = require('./MatrixClientPeg'); -var dis = require('./dispatcher'); -var sdk = require('./index'); -var Modal = require('./Modal'); +import MatrixClientPeg from './MatrixClientPeg'; +import dis from './dispatcher'; import { EventStatus } from 'matrix-js-sdk'; module.exports = { @@ -37,12 +35,10 @@ module.exports = { }, resend: function(event) { const room = MatrixClientPeg.get().getRoom(event.getRoomId()); - MatrixClientPeg.get().resendEvent( - event, room - ).done(function(res) { + MatrixClientPeg.get().resendEvent(event, room).done(function(res) { dis.dispatch({ action: 'message_sent', - event: event + event: event, }); }, function(err) { // XXX: temporary logging to try to diagnose @@ -58,7 +54,7 @@ module.exports = { dis.dispatch({ action: 'message_send_failed', - event: event + event: event, }); }); }, @@ -66,7 +62,7 @@ module.exports = { MatrixClientPeg.get().cancelPendingEvent(event); dis.dispatch({ action: 'message_send_cancelled', - event: event + event: event, }); }, }; diff --git a/src/Roles.js b/src/Roles.js index 8c1f711bbe..83d8192c67 100644 --- a/src/Roles.js +++ b/src/Roles.js @@ -19,7 +19,7 @@ export function levelRoleMap() { return { undefined: _t('Default'), 0: _t('User'), - 50: _t('Moderator'), + 50: _t('Moderator'), 100: _t('Admin'), }; } diff --git a/src/RoomListSorter.js b/src/RoomListSorter.js index 7a43c1891e..c06cc60c97 100644 --- a/src/RoomListSorter.js +++ b/src/RoomListSorter.js @@ -19,8 +19,7 @@ limitations under the License. function tsOfNewestEvent(room) { if (room.timeline.length) { return room.timeline[room.timeline.length - 1].getTs(); - } - else { + } else { return Number.MAX_SAFE_INTEGER; } } @@ -32,5 +31,5 @@ function mostRecentActivityFirst(roomList) { } module.exports = { - mostRecentActivityFirst: mostRecentActivityFirst + mostRecentActivityFirst, }; diff --git a/src/UserActivity.js b/src/UserActivity.js index 1ae272f5df..b6fae38ed5 100644 --- a/src/UserActivity.js +++ b/src/UserActivity.js @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -var dis = require("./dispatcher"); +import dis from './dispatcher'; -var MIN_DISPATCH_INTERVAL_MS = 500; -var CURRENTLY_ACTIVE_THRESHOLD_MS = 2000; +const MIN_DISPATCH_INTERVAL_MS = 500; +const CURRENTLY_ACTIVE_THRESHOLD_MS = 2000; /** * This class watches for user activity (moving the mouse or pressing a key) @@ -58,16 +58,15 @@ class UserActivity { /** * Return true if there has been user activity very recently * (ie. within a few seconds) + * @returns {boolean} true if user is currently/very recently active */ userCurrentlyActive() { return this.lastActivityAtTs > new Date().getTime() - CURRENTLY_ACTIVE_THRESHOLD_MS; } _onUserActivity(event) { - if (event.screenX && event.type == "mousemove") { - if (event.screenX === this.lastScreenX && - event.screenY === this.lastScreenY) - { + if (event.screenX && event.type === "mousemove") { + if (event.screenX === this.lastScreenX && event.screenY === this.lastScreenY) { // mouse hasn't actually moved return; } @@ -79,28 +78,24 @@ class UserActivity { if (this.lastDispatchAtTs < this.lastActivityAtTs - MIN_DISPATCH_INTERVAL_MS) { this.lastDispatchAtTs = this.lastActivityAtTs; dis.dispatch({ - action: 'user_activity' + action: 'user_activity', }); if (!this.activityEndTimer) { - this.activityEndTimer = setTimeout( - this._onActivityEndTimer.bind(this), MIN_DISPATCH_INTERVAL_MS - ); + this.activityEndTimer = setTimeout(this._onActivityEndTimer.bind(this), MIN_DISPATCH_INTERVAL_MS); } } } _onActivityEndTimer() { - var now = new Date().getTime(); - var targetTime = this.lastActivityAtTs + MIN_DISPATCH_INTERVAL_MS; + const now = new Date().getTime(); + const targetTime = this.lastActivityAtTs + MIN_DISPATCH_INTERVAL_MS; if (now >= targetTime) { dis.dispatch({ - action: 'user_activity_end' + action: 'user_activity_end', }); this.activityEndTimer = undefined; } else { - this.activityEndTimer = setTimeout( - this._onActivityEndTimer.bind(this), targetTime - now - ); + this.activityEndTimer = setTimeout(this._onActivityEndTimer.bind(this), targetTime - now); } } } From 9ef83b8dc009d709f3967b41d277de4b31daf8b1 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 1 Jul 2017 14:58:46 +0100 Subject: [PATCH 19/55] de-lint views/voip/* Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .eslintignore.errorfiles | 4 --- src/components/views/voip/CallView.js | 29 ++++++++--------- src/components/views/voip/IncomingCallBox.js | 23 ++++++-------- src/components/views/voip/VideoFeed.js | 2 +- src/components/views/voip/VideoView.js | 33 ++++++++++---------- 5 files changed, 41 insertions(+), 50 deletions(-) diff --git a/.eslintignore.errorfiles b/.eslintignore.errorfiles index 3d4207caa2..55eaf75e4b 100644 --- a/.eslintignore.errorfiles +++ b/.eslintignore.errorfiles @@ -111,10 +111,6 @@ src/components/views/settings/ChangePassword.js src/components/views/settings/DevicesPanel.js src/components/views/settings/DevicesPanelEntry.js src/components/views/settings/EnableNotificationsButton.js -src/components/views/voip/CallView.js -src/components/views/voip/IncomingCallBox.js -src/components/views/voip/VideoFeed.js -src/components/views/voip/VideoView.js src/ContentMessages.js src/HtmlUtils.js src/ImageUtils.js diff --git a/src/components/views/voip/CallView.js b/src/components/views/voip/CallView.js index b53794637f..e669f7e0a6 100644 --- a/src/components/views/voip/CallView.js +++ b/src/components/views/voip/CallView.js @@ -13,11 +13,11 @@ 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. */ -var React = require("react"); -var dis = require("../../../dispatcher"); -var CallHandler = require("../../../CallHandler"); -var sdk = require('../../../index'); -var MatrixClientPeg = require("../../../MatrixClientPeg"); +import React from 'react'; +import dis from '../../../dispatcher'; +import CallHandler from '../../../CallHandler'; +import sdk from '../../../index'; +import MatrixClientPeg from '../../../MatrixClientPeg'; import { _t } from '../../../languageHandler'; module.exports = React.createClass({ @@ -73,10 +73,10 @@ module.exports = React.createClass({ }, showCall: function() { - var call; + let call; if (this.props.room) { - var roomId = this.props.room.roomId; + const roomId = this.props.room.roomId; call = CallHandler.getCallForRoom(roomId) || (this.props.ConferenceHandler ? this.props.ConferenceHandler.getConferenceCallForRoom(roomId) : @@ -86,9 +86,7 @@ module.exports = React.createClass({ if (this.call) { this.setState({ call: call }); } - - } - else { + } else { call = CallHandler.getAnyActiveCall(); this.setState({ call: call }); } @@ -109,8 +107,7 @@ module.exports = React.createClass({ call.confUserId ? "none" : "block" ); this.getVideoView().getRemoteVideoElement().style.display = "block"; - } - else { + } else { this.getVideoView().getLocalVideoElement().style.display = "none"; this.getVideoView().getRemoteVideoElement().style.display = "none"; dis.dispatch({action: 'video_fullscreen', fullscreen: false}); @@ -126,11 +123,11 @@ module.exports = React.createClass({ }, render: function() { - var VideoView = sdk.getComponent('voip.VideoView'); + const VideoView = sdk.getComponent('voip.VideoView'); - var voice; + let voice; if (this.state.call && this.state.call.type === "voice" && this.props.showVoice) { - var callRoom = MatrixClientPeg.get().getRoom(this.state.call.roomId); + const callRoom = MatrixClientPeg.get().getRoom(this.state.call.roomId); voice = (
{_t("Active call (%(roomName)s)", {roomName: callRoom.name})} @@ -147,6 +144,6 @@ module.exports = React.createClass({ { voice }
); - } + }, }); diff --git a/src/components/views/voip/IncomingCallBox.js b/src/components/views/voip/IncomingCallBox.js index 1b806fc5b3..c5934b74dc 100644 --- a/src/components/views/voip/IncomingCallBox.js +++ b/src/components/views/voip/IncomingCallBox.js @@ -13,10 +13,9 @@ 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. */ -var React = require('react'); -var MatrixClientPeg = require('../../../MatrixClientPeg'); -var dis = require("../../../dispatcher"); -var CallHandler = require("../../../CallHandler"); +import React from 'react'; +import MatrixClientPeg from '../../../MatrixClientPeg'; +import dis from '../../../dispatcher'; import { _t } from '../../../languageHandler'; module.exports = React.createClass({ @@ -29,34 +28,32 @@ module.exports = React.createClass({ onAnswerClick: function() { dis.dispatch({ action: 'answer', - room_id: this.props.incomingCall.roomId + room_id: this.props.incomingCall.roomId, }); }, onRejectClick: function() { dis.dispatch({ action: 'hangup', - room_id: this.props.incomingCall.roomId + room_id: this.props.incomingCall.roomId, }); }, render: function() { - var room = null; + let room = null; if (this.props.incomingCall) { room = MatrixClientPeg.get().getRoom(this.props.incomingCall.roomId); } - var caller = room ? room.name : _t("unknown caller"); + const caller = room ? room.name : _t("unknown caller"); let incomingCallText = null; if (this.props.incomingCall) { if (this.props.incomingCall.type === "voice") { incomingCallText = _t("Incoming voice call from %(name)s", {name: caller}); - } - else if (this.props.incomingCall.type === "video") { + } else if (this.props.incomingCall.type === "video") { incomingCallText = _t("Incoming video call from %(name)s", {name: caller}); - } - else { + } else { incomingCallText = _t("Incoming call from %(name)s", {name: caller}); } } @@ -81,6 +78,6 @@ module.exports = React.createClass({ ); - } + }, }); diff --git a/src/components/views/voip/VideoFeed.js b/src/components/views/voip/VideoFeed.js index 0b8d0b20fc..953dbc866f 100644 --- a/src/components/views/voip/VideoFeed.js +++ b/src/components/views/voip/VideoFeed.js @@ -16,7 +16,7 @@ limitations under the License. 'use strict'; -var React = require('react'); +import React from 'react'; module.exports = React.createClass({ displayName: 'VideoFeed', diff --git a/src/components/views/voip/VideoView.js b/src/components/views/voip/VideoView.js index ea37579237..6ebf2078c1 100644 --- a/src/components/views/voip/VideoView.js +++ b/src/components/views/voip/VideoView.js @@ -16,11 +16,11 @@ limitations under the License. 'use strict'; -var React = require('react'); -var ReactDOM = require('react-dom'); +import React from 'react'; +import ReactDOM from 'react-dom'; -var sdk = require('../../../index'); -var dis = require('../../../dispatcher'); +import sdk from '../../../index'; +import dis from '../../../dispatcher'; module.exports = React.createClass({ displayName: 'VideoView', @@ -53,9 +53,10 @@ module.exports = React.createClass({ // this needs to be somewhere at the top of the DOM which // always exists to avoid audio interruptions. // Might as well just use DOM. - var remoteAudioElement = document.getElementById("remoteAudio"); + const remoteAudioElement = document.getElementById("remoteAudio"); if (!remoteAudioElement) { - console.error("Failed to find remoteAudio element - cannot play audio! You need to add an