Merge pull request #3766 from matrix-org/travis/babel7-wp-es6-fixes

Misc fixes for ES6 imports/exports
This commit is contained in:
Travis Ralston 2020-01-09 14:00:59 -07:00 committed by GitHub
commit 6ca9a7c998
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 39 additions and 33 deletions

View file

@ -15,9 +15,9 @@ limitations under the License.
*/ */
'use strict'; 'use strict';
import {ContentRepo} from 'matrix-js-sdk';
import {MatrixClientPeg} from './MatrixClientPeg'; import {MatrixClientPeg} from './MatrixClientPeg';
import DMRoomMap from './utils/DMRoomMap'; import DMRoomMap from './utils/DMRoomMap';
import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo";
export function avatarUrlForMember(member, width, height, resizeMethod) { export function avatarUrlForMember(member, width, height, resizeMethod) {
let url = member.getAvatarUrl( let url = member.getAvatarUrl(
@ -38,7 +38,7 @@ export function avatarUrlForMember(member, width, height, resizeMethod) {
} }
export function avatarUrlForUser(user, width, height, resizeMethod) { export function avatarUrlForUser(user, width, height, resizeMethod) {
const url = ContentRepo.getHttpUriForMxc( const url = getHttpUriForMxc(
MatrixClientPeg.get().getHomeserverUrl(), user.avatarUrl, MatrixClientPeg.get().getHomeserverUrl(), user.avatarUrl,
Math.floor(width * window.devicePixelRatio), Math.floor(width * window.devicePixelRatio),
Math.floor(height * window.devicePixelRatio), Math.floor(height * window.devicePixelRatio),

View file

@ -17,6 +17,7 @@ limitations under the License.
import {MatrixClientPeg} from "./MatrixClientPeg"; import {MatrixClientPeg} from "./MatrixClientPeg";
import shouldHideEvent from './shouldHideEvent'; import shouldHideEvent from './shouldHideEvent';
import * as sdk from "./index"; 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 * 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') { } else if (ev.getType() == 'm.room.server_acl') {
return false; return false;
} }
const EventTile = sdk.getComponent('rooms.EventTile'); return haveTileForEvent(ev);
return EventTile.haveTileForEvent(ev);
} }
export function doesRoomHaveUnreadMessages(room) { export function doesRoomHaveUnreadMessages(room) {

View file

@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License. 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 CallHandler from './CallHandler';
import {MatrixClientPeg} from "./MatrixClientPeg"; 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 // 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 // confUserId to speed up lookups (else we'd need to loop every room
// looking for a 1:1 room with this conf user ID!) // 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.confUserId = self.confUserId;
call.groupRoomId = self.groupRoomId; call.groupRoomId = self.groupRoomId;
return call; return call;

View file

@ -27,6 +27,7 @@ import * as sdk from '../../index';
import {MatrixClientPeg} from '../../MatrixClientPeg'; import {MatrixClientPeg} from '../../MatrixClientPeg';
import SettingsStore from '../../settings/SettingsStore'; import SettingsStore from '../../settings/SettingsStore';
import {_t} from "../../languageHandler"; import {_t} from "../../languageHandler";
import {haveTileForEvent} from "../views/rooms/EventTile";
const CONTINUATION_MAX_INTERVAL = 5 * 60 * 1000; // 5 minutes const CONTINUATION_MAX_INTERVAL = 5 * 60 * 1000; // 5 minutes
const continuedTypes = ['m.sticker', 'm.room.message']; const continuedTypes = ['m.sticker', 'm.room.message'];
@ -318,8 +319,7 @@ export default class MessagePanel extends React.Component {
return true; return true;
} }
const EventTile = sdk.getComponent('rooms.EventTile'); if (!haveTileForEvent(mxEv)) {
if (!EventTile.haveTileForEvent(mxEv)) {
return false; // no tile = no show return false; // no tile = no show
} }

View file

@ -18,7 +18,6 @@ limitations under the License.
import React from 'react'; import React from 'react';
import createReactClass from 'create-react-class'; import createReactClass from 'create-react-class';
import {ContentRepo} from "matrix-js-sdk";
import {MatrixClientPeg} from "../../MatrixClientPeg"; import {MatrixClientPeg} from "../../MatrixClientPeg";
import * as sdk from "../../index"; import * as sdk from "../../index";
import dis from "../../dispatcher"; import dis from "../../dispatcher";
@ -28,6 +27,7 @@ import PropTypes from 'prop-types';
import { _t } from '../../languageHandler'; import { _t } from '../../languageHandler';
import { instanceForInstanceId, protocolNameForInstanceId } from '../../utils/DirectoryUtils'; import { instanceForInstanceId, protocolNameForInstanceId } from '../../utils/DirectoryUtils';
import Analytics from '../../Analytics'; import Analytics from '../../Analytics';
import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo";
const MAX_NAME_LENGTH = 80; const MAX_NAME_LENGTH = 80;
const MAX_TOPIC_LENGTH = 160; const MAX_TOPIC_LENGTH = 160;
@ -463,7 +463,7 @@ export default createReactClass({
topic = `${topic.substring(0, MAX_TOPIC_LENGTH)}...`; topic = `${topic.substring(0, MAX_TOPIC_LENGTH)}...`;
} }
topic = linkifyAndSanitizeHtml(topic); topic = linkifyAndSanitizeHtml(topic);
const avatarUrl = ContentRepo.getHttpUriForMxc( const avatarUrl = getHttpUriForMxc(
MatrixClientPeg.get().getHomeserverUrl(), MatrixClientPeg.get().getHomeserverUrl(),
room.avatar_url, 32, 32, "crop", room.avatar_url, 32, 32, "crop",
); );

View file

@ -55,6 +55,7 @@ import SettingsStore, {SettingLevel} from "../../settings/SettingsStore";
import WidgetUtils from '../../utils/WidgetUtils'; import WidgetUtils from '../../utils/WidgetUtils';
import AccessibleButton from "../views/elements/AccessibleButton"; import AccessibleButton from "../views/elements/AccessibleButton";
import RightPanelStore from "../../stores/RightPanelStore"; import RightPanelStore from "../../stores/RightPanelStore";
import {haveTileForEvent} from "../views/rooms/EventTile";
const DEBUG = false; const DEBUG = false;
let debuglog = function() {}; let debuglog = function() {};
@ -1245,7 +1246,7 @@ export default createReactClass({
const roomId = mxEv.getRoomId(); const roomId = mxEv.getRoomId();
const room = cli.getRoom(roomId); const room = cli.getRoom(roomId);
if (!EventTile.haveTileForEvent(mxEv)) { if (!haveTileForEvent(mxEv)) {
// XXX: can this ever happen? It will make the result count // XXX: can this ever happen? It will make the result count
// not match the displayed count. // not match the displayed count.
continue; continue;

View file

@ -38,7 +38,7 @@ export class Tab {
} }
} }
export class TabbedView extends React.Component { export default class TabbedView extends React.Component {
static propTypes = { static propTypes = {
// The tabs to show // The tabs to show
tabs: PropTypes.arrayOf(PropTypes.instanceOf(Tab)).isRequired, tabs: PropTypes.arrayOf(PropTypes.instanceOf(Tab)).isRequired,

View file

@ -35,6 +35,7 @@ import { KeyCode } from '../../Keyboard';
import Timer from '../../utils/Timer'; import Timer from '../../utils/Timer';
import shouldHideEvent from '../../shouldHideEvent'; import shouldHideEvent from '../../shouldHideEvent';
import EditorStateTransfer from '../../utils/EditorStateTransfer'; import EditorStateTransfer from '../../utils/EditorStateTransfer';
import {haveTileForEvent} from "../views/rooms/EventTile";
const PAGINATE_SIZE = 20; const PAGINATE_SIZE = 20;
const INITIAL_SIZE = 20; const INITIAL_SIZE = 20;
@ -1179,7 +1180,7 @@ const TimelinePanel = createReactClass({
const shouldIgnore = !!ev.status || // local echo const shouldIgnore = !!ev.status || // local echo
(ignoreOwn && ev.sender && ev.sender.userId == myUserId); // own message (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) { if (isWithoutTile || !node) {
// don't start counting if the event should be ignored, // don't start counting if the event should be ignored,

View file

@ -16,11 +16,11 @@ limitations under the License.
import React from "react"; import React from "react";
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import createReactClass from 'create-react-class'; import createReactClass from 'create-react-class';
import {ContentRepo} from "matrix-js-sdk";
import {MatrixClientPeg} from "../../../MatrixClientPeg"; import {MatrixClientPeg} from "../../../MatrixClientPeg";
import Modal from '../../../Modal'; import Modal from '../../../Modal';
import * as sdk from "../../../index"; import * as sdk from "../../../index";
import * as Avatar from '../../../Avatar'; import * as Avatar from '../../../Avatar';
import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo";
export default createReactClass({ export default createReactClass({
displayName: 'RoomAvatar', displayName: 'RoomAvatar',
@ -82,7 +82,7 @@ export default createReactClass({
getImageUrls: function(props) { getImageUrls: function(props) {
return [ return [
ContentRepo.getHttpUriForMxc( getHttpUriForMxc(
MatrixClientPeg.get().getHomeserverUrl(), MatrixClientPeg.get().getHomeserverUrl(),
props.oobData.avatarUrl, props.oobData.avatarUrl,
Math.floor(props.width * window.devicePixelRatio), Math.floor(props.width * window.devicePixelRatio),

View file

@ -17,7 +17,7 @@ limitations under the License.
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import {Tab, TabbedView} from "../../structures/TabbedView"; import TabbedView, {Tab} from "../../structures/TabbedView";
import {_t, _td} from "../../../languageHandler"; import {_t, _td} from "../../../languageHandler";
import AdvancedRoomSettingsTab from "../settings/tabs/room/AdvancedRoomSettingsTab"; import AdvancedRoomSettingsTab from "../settings/tabs/room/AdvancedRoomSettingsTab";
import RolesRoomSettingsTab from "../settings/tabs/room/RolesRoomSettingsTab"; import RolesRoomSettingsTab from "../settings/tabs/room/RolesRoomSettingsTab";

View file

@ -17,7 +17,7 @@ limitations under the License.
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import {Tab, TabbedView} from "../../structures/TabbedView"; import TabbedView, {Tab} from "../../structures/TabbedView";
import {_t, _td} from "../../../languageHandler"; import {_t, _td} from "../../../languageHandler";
import GeneralUserSettingsTab from "../settings/tabs/user/GeneralUserSettingsTab"; import GeneralUserSettingsTab from "../settings/tabs/user/GeneralUserSettingsTab";
import SettingsStore from "../../../settings/SettingsStore"; import SettingsStore from "../../../settings/SettingsStore";

View file

@ -18,10 +18,10 @@ import * as sdk from '../../../index';
import React, {createRef} from 'react'; import React, {createRef} from 'react';
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import { linkifyElement } from '../../../HtmlUtils'; import { linkifyElement } from '../../../HtmlUtils';
import { ContentRepo } from 'matrix-js-sdk';
import {MatrixClientPeg} from '../../../MatrixClientPeg'; import {MatrixClientPeg} from '../../../MatrixClientPeg';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import createReactClass from 'create-react-class'; import createReactClass from 'create-react-class';
import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo";
export function getDisplayAliasForRoom(room) { export function getDisplayAliasForRoom(room) {
return room.canonicalAlias || (room.aliases ? room.aliases[0] : ""); return room.canonicalAlias || (room.aliases ? room.aliases[0] : "");
@ -101,7 +101,7 @@ export default createReactClass({
<td className="mx_RoomDirectory_roomAvatar"> <td className="mx_RoomDirectory_roomAvatar">
<BaseAvatar width={24} height={24} resizeMethod='crop' <BaseAvatar width={24} height={24} resizeMethod='crop'
name={name} idName={name} name={name} idName={name}
url={ContentRepo.getHttpUriForMxc( url={getHttpUriForMxc(
MatrixClientPeg.get().getHomeserverUrl(), MatrixClientPeg.get().getHomeserverUrl(),
room.avatarUrl, 24, 24, "crop")} /> room.avatarUrl, 24, 24, "crop")} />
</td> </td>

View file

@ -19,6 +19,7 @@ import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import createReactClass from 'create-react-class'; import createReactClass from 'create-react-class';
import * as sdk from '../../../index'; import * as sdk from '../../../index';
import {haveTileForEvent} from "./EventTile";
export default createReactClass({ export default createReactClass({
displayName: 'SearchResult', displayName: 'SearchResult',
@ -54,7 +55,7 @@ export default createReactClass({
if (!contextual) { if (!contextual) {
highlights = this.props.searchHighlights; highlights = this.props.searchHighlights;
} }
if (EventTile.haveTileForEvent(ev)) { if (haveTileForEvent(ev)) {
ret.push(<EventTile key={eventId+"+"+j} mxEvent={ev} contextual={contextual} highlights={highlights} ret.push(<EventTile key={eventId+"+"+j} mxEvent={ev} contextual={contextual} highlights={highlights}
permalinkCreator={this.props.permalinkCreator} permalinkCreator={this.props.permalinkCreator}
highlightLink={this.props.resultLink} highlightLink={this.props.resultLink}

View file

@ -22,6 +22,9 @@ import counterpart from 'counterpart';
import React from 'react'; import React from 'react';
import SettingsStore, {SettingLevel} from "./settings/SettingsStore"; 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/'; const i18nFolder = 'i18n/';
// Control whether to also return original, untranslated strings // Control whether to also return original, untranslated strings
@ -414,11 +417,10 @@ export function pickBestLanguage(langs) {
} }
function getLangsJson() { function getLangsJson() {
return new Promise((resolve, reject) => { return new Promise(async (resolve, reject) => {
let url; let url;
try { try {
// $webapp is a webpack resolve alias pointing to the output directory, see webpack config url = webpackLangJsonUrl;
url = require('$webapp/i18n/languages.json');
} catch (e) { } catch (e) {
url = i18nFolder + 'languages.json'; url = i18nFolder + 'languages.json';
} }

View file

@ -34,10 +34,15 @@ function isMasterRuleEnabled() {
return !masterRule.enabled; 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 { export class NotificationsEnabledController extends SettingController {
getValueOverride(level, roomId, calculatedValue, calculatedAtLevel) { getValueOverride(level, roomId, calculatedValue, calculatedAtLevel) {
const Notifier = require('../../Notifier'); // avoids cyclical references if (!getNotifier().isPossible()) return false;
if (!Notifier.isPossible()) return false;
if (calculatedValue === null || calculatedAtLevel === "default") { if (calculatedValue === null || calculatedAtLevel === "default") {
return isMasterRuleEnabled(); return isMasterRuleEnabled();
@ -47,18 +52,15 @@ export class NotificationsEnabledController extends SettingController {
} }
onChange(level, roomId, newValue) { onChange(level, roomId, newValue) {
const Notifier = require('../../Notifier'); // avoids cyclical references if (getNotifier().supportsDesktopNotifications()) {
getNotifier().setEnabled(newValue);
if (Notifier.supportsDesktopNotifications()) {
Notifier.setEnabled(newValue);
} }
} }
} }
export class NotificationBodyEnabledController extends SettingController { export class NotificationBodyEnabledController extends SettingController {
getValueOverride(level, roomId, calculatedValue) { getValueOverride(level, roomId, calculatedValue) {
const Notifier = require('../../Notifier'); // avoids cyclical references if (!getNotifier().isPossible()) return false;
if (!Notifier.isPossible()) return false;
if (calculatedValue === null) { if (calculatedValue === null) {
return isMasterRuleEnabled(); return isMasterRuleEnabled();
@ -70,8 +72,7 @@ export class NotificationBodyEnabledController extends SettingController {
export class AudioNotificationsEnabledController extends SettingController { export class AudioNotificationsEnabledController extends SettingController {
getValueOverride(level, roomId, calculatedValue) { getValueOverride(level, roomId, calculatedValue) {
const Notifier = require('../../Notifier'); // avoids cyclical references if (!getNotifier().isPossible()) return false;
if (!Notifier.isPossible()) return false;
// Note: Audio notifications are *not* enabled by default. // Note: Audio notifications are *not* enabled by default.
return calculatedValue; return calculatedValue;