Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Convert the more complicated CommonJS exports to ES6-style
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Dec 23, 2019
1 parent 344dac4 commit 4aec432
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 86 deletions.
6 changes: 3 additions & 3 deletions src/CallHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions src/ObjectUtils.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -76,15 +77,15 @@ module.exports.getKeyValueArrayDiffs = function(before, after) {
});

return results;
};
}

/**
* 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) {
export function shallowEqual(objA, objB) {
if (objA === objB) {
return true;
}
Expand All @@ -109,4 +110,4 @@ module.exports.shallowEqual = function(objA, objB) {
}

return true;
};
}
42 changes: 23 additions & 19 deletions src/Resend.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
},
};
}
}
28 changes: 14 additions & 14 deletions src/VectorConferenceHandler.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand All @@ -101,35 +102,34 @@ 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) {
return activeCall;
}
}
return null;
};

module.exports.ConferenceCall = ConferenceCall;
}

module.exports.slot = 'conference';
// TODO: Document this.
export const slot = 'conference';
4 changes: 1 addition & 3 deletions src/components/structures/RoomView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -2002,5 +2002,3 @@ export default createReactClass({
);
},
});

module.exports.RoomContext = RoomContext;
8 changes: 3 additions & 5 deletions src/components/views/rooms/EventTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand All @@ -895,7 +895,7 @@ module.exports.haveTileForEvent = function(e) {
} else {
return true;
}
};
}

function E2ePadlockUndecryptable(props) {
return (
Expand Down Expand Up @@ -964,5 +964,3 @@ class E2ePadlock extends React.Component {
);
}
}

module.exports.getHandlerTile = getHandlerTile;
13 changes: 7 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
};
}
5 changes: 3 additions & 2 deletions test/end-to-end-tests/src/rest/consent.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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();
Expand All @@ -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});
};
}
13 changes: 5 additions & 8 deletions test/end-to-end-tests/src/usecases/memberlist.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,17 +17,15 @@ 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;
}).map((m) => m.label)[0];
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) => {
Expand Down Expand Up @@ -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);
Expand All @@ -78,5 +77,3 @@ async function getMembersInMemberlist(session) {
return {label: el, displayName: await session.innerText(el)};
}));
}

module.exports.getMembersInMemberlist = getMembersInMemberlist;
9 changes: 5 additions & 4 deletions test/end-to-end-tests/src/usecases/settings.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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();
Expand All @@ -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");
Expand All @@ -51,4 +52,4 @@ module.exports.getE2EDeviceFromSettings = async function(session) {
await closeButton.click();
session.log.done();
return {id, key};
};
}
Loading

0 comments on commit 4aec432

Please sign in to comment.