Convert the more complicated CommonJS exports to ES6-style
This commit is contained in:
parent
344dac4fb9
commit
4aec432b30
14 changed files with 91 additions and 86 deletions
|
@ -302,7 +302,7 @@ function _onAction(payload) {
|
|||
switch (payload.action) {
|
||||
case 'place_call':
|
||||
{
|
||||
if (module.exports.getAnyActiveCall()) {
|
||||
if (callHandler.getAnyActiveCall()) {
|
||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||
Modal.createTrackedDialog('Call Handler', 'Existing Call', ErrorDialog, {
|
||||
title: _t('Existing Call'),
|
||||
|
@ -355,7 +355,7 @@ function _onAction(payload) {
|
|||
break;
|
||||
case 'incoming_call':
|
||||
{
|
||||
if (module.exports.getAnyActiveCall()) {
|
||||
if (callHandler.getAnyActiveCall()) {
|
||||
// ignore multiple incoming calls. in future, we may want a line-1/line-2 setup.
|
||||
// we avoid rejecting with "busy" in case the user wants to answer it on a different device.
|
||||
// in future we could signal a "local busy" as a warning to the caller.
|
||||
|
@ -523,7 +523,7 @@ if (!global.mxCallHandler) {
|
|||
|
||||
const callHandler = {
|
||||
getCallForRoom: function(roomId) {
|
||||
let call = module.exports.getCall(roomId);
|
||||
let call = callHandler.getCall(roomId);
|
||||
if (call) return call;
|
||||
|
||||
if (ConferenceHandler) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2016 OpenMarket Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -22,7 +23,7 @@ limitations under the License.
|
|||
* @return {Object[]} An array of objects with the form:
|
||||
* { key: $KEY, val: $VALUE, place: "add|del" }
|
||||
*/
|
||||
module.exports.getKeyValueArrayDiffs = function(before, after) {
|
||||
export function getKeyValueArrayDiffs(before, after) {
|
||||
const results = [];
|
||||
const delta = {};
|
||||
Object.keys(before).forEach(function(beforeKey) {
|
||||
|
@ -76,7 +77,7 @@ module.exports.getKeyValueArrayDiffs = function(before, after) {
|
|||
});
|
||||
|
||||
return results;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Shallow-compare two objects for equality: each key and value must be identical
|
||||
|
@ -84,7 +85,7 @@ module.exports.getKeyValueArrayDiffs = function(before, after) {
|
|||
* @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) {
|
||||
export function shallowEqual(objA, objB) {
|
||||
if (objA === objB) {
|
||||
return true;
|
||||
}
|
||||
|
@ -109,4 +110,4 @@ module.exports.shallowEqual = function(objA, objB) {
|
|||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2015, 2016 OpenMarket Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -18,40 +19,43 @@ import MatrixClientPeg from './MatrixClientPeg';
|
|||
import dis from './dispatcher';
|
||||
import { EventStatus } from 'matrix-js-sdk';
|
||||
|
||||
module.exports = {
|
||||
resendUnsentEvents: function(room) {
|
||||
room.getPendingEvents().filter(function(ev) {
|
||||
export default class Resend {
|
||||
static resendUnsentEvents(room) {
|
||||
room.getPendingEvents().filter(function (ev) {
|
||||
return ev.status === EventStatus.NOT_SENT;
|
||||
}).forEach(function(event) {
|
||||
module.exports.resend(event);
|
||||
}).forEach(function (event) {
|
||||
Resend.resend(event);
|
||||
});
|
||||
},
|
||||
cancelUnsentEvents: function(room) {
|
||||
room.getPendingEvents().filter(function(ev) {
|
||||
}
|
||||
|
||||
static cancelUnsentEvents(room) {
|
||||
room.getPendingEvents().filter(function (ev) {
|
||||
return ev.status === EventStatus.NOT_SENT;
|
||||
}).forEach(function(event) {
|
||||
module.exports.removeFromQueue(event);
|
||||
}).forEach(function (event) {
|
||||
Resend.removeFromQueue(event);
|
||||
});
|
||||
},
|
||||
resend: function(event) {
|
||||
}
|
||||
|
||||
static resend(event) {
|
||||
const room = MatrixClientPeg.get().getRoom(event.getRoomId());
|
||||
MatrixClientPeg.get().resendEvent(event, room).then(function(res) {
|
||||
MatrixClientPeg.get().resendEvent(event, room).then(function (res) {
|
||||
dis.dispatch({
|
||||
action: 'message_sent',
|
||||
event: event,
|
||||
});
|
||||
}, function(err) {
|
||||
}, function (err) {
|
||||
// XXX: temporary logging to try to diagnose
|
||||
// https://github.com/vector-im/riot-web/issues/3148
|
||||
console.log('Resend got send failure: ' + err.name + '('+err+')');
|
||||
console.log('Resend got send failure: ' + err.name + '(' + err + ')');
|
||||
|
||||
dis.dispatch({
|
||||
action: 'message_send_failed',
|
||||
event: event,
|
||||
});
|
||||
});
|
||||
},
|
||||
removeFromQueue: function(event) {
|
||||
}
|
||||
|
||||
static removeFromQueue(event) {
|
||||
MatrixClientPeg.get().cancelPendingEvent(event);
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2015, 2016 OpenMarket Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -28,10 +29,10 @@ import MatrixClientPeg from "./MatrixClientPeg";
|
|||
const USER_PREFIX = "fs_";
|
||||
const DOMAIN = "matrix.org";
|
||||
|
||||
function ConferenceCall(matrixClient, groupChatRoomId) {
|
||||
export function ConferenceCall(matrixClient, groupChatRoomId) {
|
||||
this.client = matrixClient;
|
||||
this.groupRoomId = groupChatRoomId;
|
||||
this.confUserId = module.exports.getConferenceUserIdForRoom(this.groupRoomId);
|
||||
this.confUserId = getConferenceUserIdForRoom(this.groupRoomId);
|
||||
}
|
||||
|
||||
ConferenceCall.prototype.setup = function() {
|
||||
|
@ -90,7 +91,7 @@ ConferenceCall.prototype._getConferenceUserRoom = function() {
|
|||
* @param {string} userId The user ID to check.
|
||||
* @return {boolean} True if it is a conference bot.
|
||||
*/
|
||||
module.exports.isConferenceUser = function(userId) {
|
||||
export function isConferenceUser(userId) {
|
||||
if (userId.indexOf("@" + USER_PREFIX) !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -101,26 +102,26 @@ module.exports.isConferenceUser = function(userId) {
|
|||
return /^!.+:.+/.test(decoded);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.getConferenceUserIdForRoom = function(roomId) {
|
||||
export function getConferenceUserIdForRoom(roomId) {
|
||||
// abuse browserify's core node Buffer support (strip padding ='s)
|
||||
const base64RoomId = new Buffer(roomId).toString("base64").replace(/=/g, "");
|
||||
return "@" + USER_PREFIX + base64RoomId + ":" + DOMAIN;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.createNewMatrixCall = function(client, roomId) {
|
||||
export function createNewMatrixCall(client, roomId) {
|
||||
const confCall = new ConferenceCall(
|
||||
client, roomId,
|
||||
);
|
||||
return confCall.setup();
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.getConferenceCallForRoom = function(roomId) {
|
||||
export function getConferenceCallForRoom(roomId) {
|
||||
// search for a conference 1:1 call for this group chat room ID
|
||||
const activeCall = CallHandler.getAnyActiveCall();
|
||||
if (activeCall && activeCall.confUserId) {
|
||||
const thisRoomConfUserId = module.exports.getConferenceUserIdForRoom(
|
||||
const thisRoomConfUserId = getConferenceUserIdForRoom(
|
||||
roomId,
|
||||
);
|
||||
if (thisRoomConfUserId === activeCall.confUserId) {
|
||||
|
@ -128,8 +129,7 @@ module.exports.getConferenceCallForRoom = function(roomId) {
|
|||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.ConferenceCall = ConferenceCall;
|
||||
|
||||
module.exports.slot = 'conference';
|
||||
// TODO: Document this.
|
||||
export const slot = 'conference';
|
||||
|
|
|
@ -66,7 +66,7 @@ if (DEBUG) {
|
|||
debuglog = console.log.bind(console);
|
||||
}
|
||||
|
||||
const RoomContext = PropTypes.shape({
|
||||
export const RoomContext = PropTypes.shape({
|
||||
canReact: PropTypes.bool.isRequired,
|
||||
canReply: PropTypes.bool.isRequired,
|
||||
room: PropTypes.instanceOf(Room),
|
||||
|
@ -2002,5 +2002,3 @@ export default createReactClass({
|
|||
);
|
||||
},
|
||||
});
|
||||
|
||||
module.exports.RoomContext = RoomContext;
|
||||
|
|
|
@ -75,7 +75,7 @@ for (const evType of ALL_RULE_TYPES) {
|
|||
stateEventTileTypes[evType] = 'messages.TextualEvent';
|
||||
}
|
||||
|
||||
function getHandlerTile(ev) {
|
||||
export function getHandlerTile(ev) {
|
||||
const type = ev.getType();
|
||||
|
||||
// don't show verification requests we're not involved in,
|
||||
|
@ -879,7 +879,7 @@ function isMessageEvent(ev) {
|
|||
return (messageTypes.includes(ev.getType()));
|
||||
}
|
||||
|
||||
module.exports.haveTileForEvent = function(e) {
|
||||
export function haveTileForEvent(e) {
|
||||
// Only messages have a tile (black-rectangle) if redacted
|
||||
if (e.isRedacted() && !isMessageEvent(e)) return false;
|
||||
|
||||
|
@ -895,7 +895,7 @@ module.exports.haveTileForEvent = function(e) {
|
|||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function E2ePadlockUndecryptable(props) {
|
||||
return (
|
||||
|
@ -964,5 +964,3 @@ class E2ePadlock extends React.Component {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.getHandlerTile = getHandlerTile;
|
||||
|
|
13
src/index.js
13
src/index.js
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2015, 2016 OpenMarket Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -16,14 +17,14 @@ limitations under the License.
|
|||
|
||||
import Skinner from './Skinner';
|
||||
|
||||
module.exports.loadSkin = function(skinObject) {
|
||||
export function loadSkin(skinObject) {
|
||||
Skinner.load(skinObject);
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.resetSkin = function() {
|
||||
export function resetSkin() {
|
||||
Skinner.reset();
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.getComponent = function(componentName) {
|
||||
export function getComponent(componentName) {
|
||||
return Skinner.getComponent(componentName);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2018 New Vector Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -18,7 +19,7 @@ const request = require('request-promise-native');
|
|||
const cheerio = require('cheerio');
|
||||
const url = require("url");
|
||||
|
||||
module.exports.approveConsent = async function(consentUrl) {
|
||||
export async function approveConsent(consentUrl) {
|
||||
const body = await request.get(consentUrl);
|
||||
const doc = cheerio.load(body);
|
||||
const v = doc("input[name=v]").val();
|
||||
|
@ -27,4 +28,4 @@ module.exports.approveConsent = async function(consentUrl) {
|
|||
const formAction = doc("form").attr("action");
|
||||
const absAction = url.resolve(consentUrl, formAction);
|
||||
await request.post(absAction).form({v, u, h});
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2018 New Vector Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +17,7 @@ limitations under the License.
|
|||
|
||||
const assert = require('assert');
|
||||
|
||||
async function openMemberInfo(session, name) {
|
||||
export async function openMemberInfo(session, name) {
|
||||
const membersAndNames = await getMembersInMemberlist(session);
|
||||
const matchingLabel = membersAndNames.filter((m) => {
|
||||
return m.displayName === name;
|
||||
|
@ -24,9 +25,7 @@ async function openMemberInfo(session, name) {
|
|||
await matchingLabel.click();
|
||||
}
|
||||
|
||||
module.exports.openMemberInfo = openMemberInfo;
|
||||
|
||||
module.exports.verifyDeviceForUser = async function(session, name, expectedDevice) {
|
||||
export async function verifyDeviceForUser(session, name, expectedDevice) {
|
||||
session.log.step(`verifies e2e device for ${name}`);
|
||||
const membersAndNames = await getMembersInMemberlist(session);
|
||||
const matchingLabel = membersAndNames.filter((m) => {
|
||||
|
@ -59,9 +58,9 @@ module.exports.verifyDeviceForUser = async function(session, name, expectedDevic
|
|||
const closeMemberInfo = await session.query(".mx_MemberInfo_cancel");
|
||||
await closeMemberInfo.click();
|
||||
session.log.done();
|
||||
};
|
||||
}
|
||||
|
||||
async function getMembersInMemberlist(session) {
|
||||
export async function getMembersInMemberlist(session) {
|
||||
const memberPanelButton = await session.query(".mx_RightPanel_membersButton");
|
||||
try {
|
||||
await session.query(".mx_RightPanel_headerButton_highlight", 500);
|
||||
|
@ -78,5 +77,3 @@ async function getMembersInMemberlist(session) {
|
|||
return {label: el, displayName: await session.innerText(el)};
|
||||
}));
|
||||
}
|
||||
|
||||
module.exports.getMembersInMemberlist = getMembersInMemberlist;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2018 New Vector Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -28,7 +29,7 @@ async function openSettings(session, section) {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports.enableLazyLoading = async function(session) {
|
||||
export async function enableLazyLoading(session) {
|
||||
session.log.step(`enables lazy loading of members in the lab settings`);
|
||||
const settingsButton = await session.query('.mx_BottomLeftMenu_settings');
|
||||
await settingsButton.click();
|
||||
|
@ -38,9 +39,9 @@ module.exports.enableLazyLoading = async function(session) {
|
|||
const closeButton = await session.query(".mx_RoomHeader_cancelButton");
|
||||
await closeButton.click();
|
||||
session.log.done();
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.getE2EDeviceFromSettings = async function(session) {
|
||||
export async function getE2EDeviceFromSettings(session) {
|
||||
session.log.step(`gets e2e device/key from settings`);
|
||||
await openSettings(session, "security");
|
||||
const deviceAndKey = await session.queryAll(".mx_SettingsTab_section .mx_SecurityUserSettingsTab_deviceInfo code");
|
||||
|
@ -51,4 +52,4 @@ module.exports.getE2EDeviceFromSettings = async function(session) {
|
|||
await closeButton.click();
|
||||
session.log.done();
|
||||
return {id, key};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2018 New Vector Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -16,7 +17,7 @@ limitations under the License.
|
|||
|
||||
const assert = require('assert');
|
||||
|
||||
module.exports.scrollToTimelineTop = async function(session) {
|
||||
export async function scrollToTimelineTop(session) {
|
||||
session.log.step(`scrolls to the top of the timeline`);
|
||||
await session.page.evaluate(() => {
|
||||
return Promise.resolve().then(async () => {
|
||||
|
@ -40,9 +41,9 @@ module.exports.scrollToTimelineTop = async function(session) {
|
|||
});
|
||||
});
|
||||
session.log.done();
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.receiveMessage = async function(session, expectedMessage) {
|
||||
export async function receiveMessage(session, expectedMessage) {
|
||||
session.log.step(`receives message "${expectedMessage.body}" from ${expectedMessage.sender}`);
|
||||
// wait for a response to come in that contains the message
|
||||
// crude, but effective
|
||||
|
@ -66,10 +67,10 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
|
|||
});
|
||||
assertMessage(lastMessage, expectedMessage);
|
||||
session.log.done();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
module.exports.checkTimelineContains = async function(session, expectedMessages, sendersDescription) {
|
||||
export async function checkTimelineContains(session, expectedMessages, sendersDescription) {
|
||||
session.log.step(`checks timeline contains ${expectedMessages.length} ` +
|
||||
`given messages${sendersDescription ? ` from ${sendersDescription}`:""}`);
|
||||
const eventTiles = await getAllEventTiles(session);
|
||||
|
@ -101,7 +102,7 @@ module.exports.checkTimelineContains = async function(session, expectedMessages,
|
|||
});
|
||||
|
||||
session.log.done();
|
||||
};
|
||||
}
|
||||
|
||||
function assertMessage(foundMessage, expectedMessage) {
|
||||
assert(foundMessage, `message ${JSON.stringify(expectedMessage)} not found in timeline`);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2019 New Vector Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -37,7 +38,7 @@ async function getSasCodes(session) {
|
|||
return sasLabels;
|
||||
}
|
||||
|
||||
module.exports.startSasVerifcation = async function(session, name) {
|
||||
export async function startSasVerifcation(session, name) {
|
||||
await startVerification(session, name);
|
||||
// expect "Verify device" dialog and click "Begin Verification"
|
||||
await assertDialog(session, "Verify device");
|
||||
|
@ -50,9 +51,9 @@ module.exports.startSasVerifcation = async function(session, name) {
|
|||
// click "Got it" when verification is done
|
||||
await acceptDialog(session);
|
||||
return sasCodes;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.acceptSasVerification = async function(session, name) {
|
||||
export async function acceptSasVerification(session, name) {
|
||||
await assertDialog(session, "Incoming Verification Request");
|
||||
const opponentLabelElement = await session.query(".mx_IncomingSasDialog_opponentProfile h2");
|
||||
const opponentLabel = await session.innerText(opponentLabelElement);
|
||||
|
@ -66,4 +67,4 @@ module.exports.acceptSasVerification = async function(session, name) {
|
|||
// click "Got it" when verification is done
|
||||
await acceptDialog(session);
|
||||
return sasCodes;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright 2018 New Vector Ltd
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -14,14 +15,14 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
module.exports.range = function(start, amount, step = 1) {
|
||||
export function range(start, amount, step = 1) {
|
||||
const r = [];
|
||||
for (let i = 0; i < amount; ++i) {
|
||||
r.push(start + (i * step));
|
||||
}
|
||||
return r;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.delay = function(ms) {
|
||||
export function delay(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
Copyright (c) 2008-2015 Pivotal Labs
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
@ -411,10 +412,10 @@ j$.MockDate = function() {
|
|||
return MockDate;
|
||||
}();
|
||||
|
||||
const clock = new j$.Clock(global, function() { return new j$.DelayedFunctionScheduler(); }, new j$.MockDate(global));
|
||||
const _clock = new j$.Clock(global, function() { return new j$.DelayedFunctionScheduler(); }, new j$.MockDate(global));
|
||||
|
||||
module.exports.clock = function() {
|
||||
return clock;
|
||||
};
|
||||
export function clock() {
|
||||
return _clock;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue