From 0d2cb6e73150b1a9255cff1d7ddda34fb900320e Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 20 Dec 2019 14:43:06 -0700 Subject: [PATCH 1/7] Import haveTileForEvent() from the right place --- src/Unread.js | 4 ++-- src/components/structures/MessagePanel.js | 4 ++-- src/components/structures/RoomView.js | 3 ++- src/components/structures/TimelinePanel.js | 3 ++- src/components/views/rooms/SearchResultTile.js | 3 ++- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Unread.js b/src/Unread.js index d199991dc5..f82c0899b5 100644 --- a/src/Unread.js +++ b/src/Unread.js @@ -17,6 +17,7 @@ limitations under the License. import {MatrixClientPeg} from "./MatrixClientPeg"; import shouldHideEvent from './shouldHideEvent'; import * as sdk from "./index"; +import {haveTileForEvent} from "./components/views/rooms/EventTile"; /** * Returns true iff this event arriving in a room should affect the room's @@ -38,8 +39,7 @@ export function eventTriggersUnreadCount(ev) { } else if (ev.getType() == 'm.room.server_acl') { return false; } - const EventTile = sdk.getComponent('rooms.EventTile'); - return EventTile.haveTileForEvent(ev); + return haveTileForEvent(ev); } export function doesRoomHaveUnreadMessages(room) { diff --git a/src/components/structures/MessagePanel.js b/src/components/structures/MessagePanel.js index 54b910732a..4ad75eb700 100644 --- a/src/components/structures/MessagePanel.js +++ b/src/components/structures/MessagePanel.js @@ -27,6 +27,7 @@ import * as sdk from '../../index'; import {MatrixClientPeg} from '../../MatrixClientPeg'; import SettingsStore from '../../settings/SettingsStore'; import {_t} from "../../languageHandler"; +import {haveTileForEvent} from "../views/rooms/EventTile"; const CONTINUATION_MAX_INTERVAL = 5 * 60 * 1000; // 5 minutes const continuedTypes = ['m.sticker', 'm.room.message']; @@ -318,8 +319,7 @@ export default class MessagePanel extends React.Component { return true; } - const EventTile = sdk.getComponent('rooms.EventTile'); - if (!EventTile.haveTileForEvent(mxEv)) { + if (!haveTileForEvent(mxEv)) { return false; // no tile = no show } diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 1cb9e7db5e..d3309a1f43 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -55,6 +55,7 @@ import SettingsStore, {SettingLevel} from "../../settings/SettingsStore"; import WidgetUtils from '../../utils/WidgetUtils'; import AccessibleButton from "../views/elements/AccessibleButton"; import RightPanelStore from "../../stores/RightPanelStore"; +import {haveTileForEvent} from "../views/rooms/EventTile"; const DEBUG = false; let debuglog = function() {}; @@ -1245,7 +1246,7 @@ export default createReactClass({ const roomId = mxEv.getRoomId(); const room = cli.getRoom(roomId); - if (!EventTile.haveTileForEvent(mxEv)) { + if (!haveTileForEvent(mxEv)) { // XXX: can this ever happen? It will make the result count // not match the displayed count. continue; diff --git a/src/components/structures/TimelinePanel.js b/src/components/structures/TimelinePanel.js index 54539b63fb..06be5af41c 100644 --- a/src/components/structures/TimelinePanel.js +++ b/src/components/structures/TimelinePanel.js @@ -35,6 +35,7 @@ import { KeyCode } from '../../Keyboard'; import Timer from '../../utils/Timer'; import shouldHideEvent from '../../shouldHideEvent'; import EditorStateTransfer from '../../utils/EditorStateTransfer'; +import {haveTileForEvent} from "../views/rooms/EventTile"; const PAGINATE_SIZE = 20; const INITIAL_SIZE = 20; @@ -1179,7 +1180,7 @@ const TimelinePanel = createReactClass({ const shouldIgnore = !!ev.status || // local echo (ignoreOwn && ev.sender && ev.sender.userId == myUserId); // own message - const isWithoutTile = !EventTile.haveTileForEvent(ev) || shouldHideEvent(ev); + const isWithoutTile = !haveTileForEvent(ev) || shouldHideEvent(ev); if (isWithoutTile || !node) { // don't start counting if the event should be ignored, diff --git a/src/components/views/rooms/SearchResultTile.js b/src/components/views/rooms/SearchResultTile.js index bf34a56de3..57856a3a5b 100644 --- a/src/components/views/rooms/SearchResultTile.js +++ b/src/components/views/rooms/SearchResultTile.js @@ -19,6 +19,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; import * as sdk from '../../../index'; +import {haveTileForEvent} from "./EventTile"; export default createReactClass({ displayName: 'SearchResult', @@ -54,7 +55,7 @@ export default createReactClass({ if (!contextual) { highlights = this.props.searchHighlights; } - if (EventTile.haveTileForEvent(ev)) { + if (haveTileForEvent(ev)) { ret.push( Date: Sun, 22 Dec 2019 19:47:10 -0700 Subject: [PATCH 2/7] Fix tabbed view export for component index --- src/components/structures/TabbedView.js | 2 +- src/components/views/dialogs/RoomSettingsDialog.js | 2 +- src/components/views/dialogs/UserSettingsDialog.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/structures/TabbedView.js b/src/components/structures/TabbedView.js index ae5f9e3ee1..20af183af8 100644 --- a/src/components/structures/TabbedView.js +++ b/src/components/structures/TabbedView.js @@ -38,7 +38,7 @@ export class Tab { } } -export class TabbedView extends React.Component { +export default class TabbedView extends React.Component { static propTypes = { // The tabs to show tabs: PropTypes.arrayOf(PropTypes.instanceOf(Tab)).isRequired, diff --git a/src/components/views/dialogs/RoomSettingsDialog.js b/src/components/views/dialogs/RoomSettingsDialog.js index 67b30e19c8..2f01204c84 100644 --- a/src/components/views/dialogs/RoomSettingsDialog.js +++ b/src/components/views/dialogs/RoomSettingsDialog.js @@ -17,7 +17,7 @@ limitations under the License. import React from 'react'; import PropTypes from 'prop-types'; -import {Tab, TabbedView} from "../../structures/TabbedView"; +import TabbedView, {Tab} from "../../structures/TabbedView"; import {_t, _td} from "../../../languageHandler"; import AdvancedRoomSettingsTab from "../settings/tabs/room/AdvancedRoomSettingsTab"; import RolesRoomSettingsTab from "../settings/tabs/room/RolesRoomSettingsTab"; diff --git a/src/components/views/dialogs/UserSettingsDialog.js b/src/components/views/dialogs/UserSettingsDialog.js index a3f586cdea..b135d5f5f6 100644 --- a/src/components/views/dialogs/UserSettingsDialog.js +++ b/src/components/views/dialogs/UserSettingsDialog.js @@ -17,7 +17,7 @@ limitations under the License. import React from 'react'; import PropTypes from 'prop-types'; -import {Tab, TabbedView} from "../../structures/TabbedView"; +import TabbedView, {Tab} from "../../structures/TabbedView"; import {_t, _td} from "../../../languageHandler"; import GeneralUserSettingsTab from "../settings/tabs/user/GeneralUserSettingsTab"; import SettingsStore from "../../../settings/SettingsStore"; From 18ac2db2ea5c44de4153efbf133b8085ba613075 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 20 Dec 2019 14:47:49 -0700 Subject: [PATCH 3/7] Fix Notifier imports in NotificationControllers require() is a bit weird for riot-web's webpack, so we fork it out to its own function to reduce the weirdness. The added weirdness is that require() is sync though exports a module instead. If we use import(), we get a promise which doesn't help us here. We therefore have to require() and pull out the default export, though this is only a problem for webpack - babel (our chosen compiler for exporting ES6) doesn't need this, hence the if statement. --- .../controllers/NotificationControllers.js | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/settings/controllers/NotificationControllers.js b/src/settings/controllers/NotificationControllers.js index ada4155206..395da765a1 100644 --- a/src/settings/controllers/NotificationControllers.js +++ b/src/settings/controllers/NotificationControllers.js @@ -34,10 +34,15 @@ function isMasterRuleEnabled() { return !masterRule.enabled; } +function getNotifier() { + let Notifier = require('../../Notifier'); // avoids cyclical references + if (Notifier.default) Notifier = Notifier.default; // correct for webpack require() weirdness + return Notifier; +} + export class NotificationsEnabledController extends SettingController { getValueOverride(level, roomId, calculatedValue, calculatedAtLevel) { - const Notifier = require('../../Notifier'); // avoids cyclical references - if (!Notifier.isPossible()) return false; + if (!getNotifier().isPossible()) return false; if (calculatedValue === null || calculatedAtLevel === "default") { return isMasterRuleEnabled(); @@ -47,18 +52,15 @@ export class NotificationsEnabledController extends SettingController { } onChange(level, roomId, newValue) { - const Notifier = require('../../Notifier'); // avoids cyclical references - - if (Notifier.supportsDesktopNotifications()) { - Notifier.setEnabled(newValue); + if (getNotifier().supportsDesktopNotifications()) { + getNotifier().setEnabled(newValue); } } } export class NotificationBodyEnabledController extends SettingController { getValueOverride(level, roomId, calculatedValue) { - const Notifier = require('../../Notifier'); // avoids cyclical references - if (!Notifier.isPossible()) return false; + if (!getNotifier().isPossible()) return false; if (calculatedValue === null) { return isMasterRuleEnabled(); @@ -70,8 +72,7 @@ export class NotificationBodyEnabledController extends SettingController { export class AudioNotificationsEnabledController extends SettingController { getValueOverride(level, roomId, calculatedValue) { - const Notifier = require('../../Notifier'); // avoids cyclical references - if (!Notifier.isPossible()) return false; + if (!getNotifier().isPossible()) return false; // Note: Audio notifications are *not* enabled by default. return calculatedValue; From 539a33c722997b22e1dbfe95eb98eaae1b45a81d Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 19 Dec 2019 18:02:36 -0700 Subject: [PATCH 4/7] Fix naming conflict in VectorConferenceHandler --- src/VectorConferenceHandler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VectorConferenceHandler.js b/src/VectorConferenceHandler.js index d0120136e1..180dad876b 100644 --- a/src/VectorConferenceHandler.js +++ b/src/VectorConferenceHandler.js @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {createNewMatrixCall, Room} from "matrix-js-sdk"; +import {createNewMatrixCall as jsCreateNewMatrixCall, Room} from "matrix-js-sdk"; import CallHandler from './CallHandler'; import {MatrixClientPeg} from "./MatrixClientPeg"; @@ -43,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 = createNewMatrixCall(self.client, room.roomId); + const call = jsCreateNewMatrixCall(self.client, room.roomId); call.confUserId = self.confUserId; call.groupRoomId = self.groupRoomId; return call; From 3eb3be45d18e6292c7bbddcae8cb1942d3a7b8a4 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 20 Dec 2019 13:58:46 -0700 Subject: [PATCH 5/7] Fix import of language index This is a similar fix to https://github.com/matrix-org/matrix-react-sdk/pull/3766/commits/18ac2db2ea5c44de4153efbf133b8085ba613075 --- src/languageHandler.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/languageHandler.js b/src/languageHandler.js index c56e5378df..4aa22f3e65 100644 --- a/src/languageHandler.js +++ b/src/languageHandler.js @@ -410,11 +410,12 @@ export function pickBestLanguage(langs) { } function getLangsJson() { - return new Promise((resolve, reject) => { + return new Promise(async (resolve, reject) => { let url; try { // $webapp is a webpack resolve alias pointing to the output directory, see webpack config - url = require('$webapp/i18n/languages.json'); + url = import('$webapp/i18n/languages.json'); + if (url.then) url = (await url).default; // webpack resolves to a Module through a promise. } catch (e) { url = i18nFolder + 'languages.json'; } From 9edc361afc283961be02abc7b139a66e062d5ad5 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 3 Jan 2020 12:29:22 -0700 Subject: [PATCH 6/7] Use new imports for js-sdk's ContentRepo Per https://github.com/matrix-org/matrix-js-sdk/pull/1134/commits/f4d1c5c006027962cd18dffb3f7c521d9e24e831 --- src/Avatar.js | 4 ++-- src/components/structures/RoomDirectory.js | 4 ++-- src/components/views/avatars/RoomAvatar.js | 4 ++-- src/components/views/rooms/RoomDetailRow.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Avatar.js b/src/Avatar.js index 6d31959718..1039ab1bb1 100644 --- a/src/Avatar.js +++ b/src/Avatar.js @@ -15,9 +15,9 @@ limitations under the License. */ 'use strict'; -import {ContentRepo} from 'matrix-js-sdk'; import {MatrixClientPeg} from './MatrixClientPeg'; import DMRoomMap from './utils/DMRoomMap'; +import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo"; export function avatarUrlForMember(member, width, height, resizeMethod) { let url = member.getAvatarUrl( @@ -38,7 +38,7 @@ export function avatarUrlForMember(member, width, height, resizeMethod) { } export function avatarUrlForUser(user, width, height, resizeMethod) { - const url = ContentRepo.getHttpUriForMxc( + const url = getHttpUriForMxc( MatrixClientPeg.get().getHomeserverUrl(), user.avatarUrl, Math.floor(width * window.devicePixelRatio), Math.floor(height * window.devicePixelRatio), diff --git a/src/components/structures/RoomDirectory.js b/src/components/structures/RoomDirectory.js index e06c00902b..d783c8cc3f 100644 --- a/src/components/structures/RoomDirectory.js +++ b/src/components/structures/RoomDirectory.js @@ -18,7 +18,6 @@ limitations under the License. import React from 'react'; import createReactClass from 'create-react-class'; -import {ContentRepo} from "matrix-js-sdk"; import {MatrixClientPeg} from "../../MatrixClientPeg"; import * as sdk from "../../index"; import dis from "../../dispatcher"; @@ -28,6 +27,7 @@ import PropTypes from 'prop-types'; import { _t } from '../../languageHandler'; import { instanceForInstanceId, protocolNameForInstanceId } from '../../utils/DirectoryUtils'; import Analytics from '../../Analytics'; +import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo"; const MAX_NAME_LENGTH = 80; const MAX_TOPIC_LENGTH = 160; @@ -463,7 +463,7 @@ export default createReactClass({ topic = `${topic.substring(0, MAX_TOPIC_LENGTH)}...`; } topic = linkifyAndSanitizeHtml(topic); - const avatarUrl = ContentRepo.getHttpUriForMxc( + const avatarUrl = getHttpUriForMxc( MatrixClientPeg.get().getHomeserverUrl(), room.avatar_url, 32, 32, "crop", ); diff --git a/src/components/views/avatars/RoomAvatar.js b/src/components/views/avatars/RoomAvatar.js index 3b51fae4b3..c79e1827da 100644 --- a/src/components/views/avatars/RoomAvatar.js +++ b/src/components/views/avatars/RoomAvatar.js @@ -16,11 +16,11 @@ limitations under the License. import React from "react"; import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; -import {ContentRepo} from "matrix-js-sdk"; import {MatrixClientPeg} from "../../../MatrixClientPeg"; import Modal from '../../../Modal'; import * as sdk from "../../../index"; import * as Avatar from '../../../Avatar'; +import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo"; export default createReactClass({ displayName: 'RoomAvatar', @@ -82,7 +82,7 @@ export default createReactClass({ getImageUrls: function(props) { return [ - ContentRepo.getHttpUriForMxc( + getHttpUriForMxc( MatrixClientPeg.get().getHomeserverUrl(), props.oobData.avatarUrl, Math.floor(props.width * window.devicePixelRatio), diff --git a/src/components/views/rooms/RoomDetailRow.js b/src/components/views/rooms/RoomDetailRow.js index 66ec733061..2210406c18 100644 --- a/src/components/views/rooms/RoomDetailRow.js +++ b/src/components/views/rooms/RoomDetailRow.js @@ -18,10 +18,10 @@ import * as sdk from '../../../index'; import React, {createRef} from 'react'; import { _t } from '../../../languageHandler'; import { linkifyElement } from '../../../HtmlUtils'; -import { ContentRepo } from 'matrix-js-sdk'; import {MatrixClientPeg} from '../../../MatrixClientPeg'; import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; +import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo"; export function getDisplayAliasForRoom(room) { return room.canonicalAlias || (room.aliases ? room.aliases[0] : ""); @@ -101,7 +101,7 @@ export default createReactClass({ From 4e4871c281655dff5cecf75c8d085e3cd487d2f9 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 9 Jan 2020 13:56:14 -0700 Subject: [PATCH 7/7] Move lang import to the top of the file --- src/languageHandler.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/languageHandler.js b/src/languageHandler.js index c31db5eb5b..3a061df915 100644 --- a/src/languageHandler.js +++ b/src/languageHandler.js @@ -22,6 +22,9 @@ import counterpart from 'counterpart'; import React from 'react'; import SettingsStore, {SettingLevel} from "./settings/SettingsStore"; +// $webapp is a webpack resolve alias pointing to the output directory, see webpack config +import webpackLangJsonUrl from "$webapp/i18n/languages.json"; + const i18nFolder = 'i18n/'; // Control whether to also return original, untranslated strings @@ -417,9 +420,7 @@ function getLangsJson() { return new Promise(async (resolve, reject) => { let url; try { - // $webapp is a webpack resolve alias pointing to the output directory, see webpack config - url = import('$webapp/i18n/languages.json'); - if (url.then) url = (await url).default; // webpack resolves to a Module through a promise. + url = webpackLangJsonUrl; } catch (e) { url = i18nFolder + 'languages.json'; }