diff --git a/src/Analytics.js b/src/Analytics.js index 75b547d3d7..d0c7a52814 100644 --- a/src/Analytics.js +++ b/src/Analytics.js @@ -306,4 +306,4 @@ class Analytics { if (!global.mxAnalytics) { global.mxAnalytics = new Analytics(); } -module.exports = global.mxAnalytics; +export default global.mxAnalytics; diff --git a/src/Avatar.js b/src/Avatar.js index c74f21bd37..00d47c98f4 100644 --- a/src/Avatar.js +++ b/src/Avatar.js @@ -19,116 +19,114 @@ import {ContentRepo} from 'matrix-js-sdk'; import {MatrixClientPeg} from './MatrixClientPeg'; import DMRoomMap from './utils/DMRoomMap'; -module.exports = { - avatarUrlForMember: function(member, width, height, resizeMethod) { - let url = member.getAvatarUrl( - MatrixClientPeg.get().getHomeserverUrl(), - Math.floor(width * window.devicePixelRatio), - Math.floor(height * window.devicePixelRatio), - resizeMethod, - false, - false, - ); - if (!url) { - // member can be null here currently since on invites, the JS SDK - // does not have enough info to build a RoomMember object for - // the inviter. - url = this.defaultAvatarUrlForString(member ? member.userId : ''); +export function avatarUrlForMember(member, width, height, resizeMethod) { + let url = member.getAvatarUrl( + MatrixClientPeg.get().getHomeserverUrl(), + Math.floor(width * window.devicePixelRatio), + Math.floor(height * window.devicePixelRatio), + resizeMethod, + false, + false, + ); + if (!url) { + // member can be null here currently since on invites, the JS SDK + // does not have enough info to build a RoomMember object for + // the inviter. + url = defaultAvatarUrlForString(member ? member.userId : ''); + } + return url; +} + +export function avatarUrlForUser(user, width, height, resizeMethod) { + const url = ContentRepo.getHttpUriForMxc( + MatrixClientPeg.get().getHomeserverUrl(), user.avatarUrl, + Math.floor(width * window.devicePixelRatio), + Math.floor(height * window.devicePixelRatio), + resizeMethod, + ); + if (!url || url.length === 0) { + return null; + } + return url; +} + +export function defaultAvatarUrlForString(s) { + const images = ['03b381', '368bd6', 'ac3ba8']; + let total = 0; + for (let i = 0; i < s.length; ++i) { + total += s.charCodeAt(i); + } + return require('../res/img/' + images[total % images.length] + '.png'); +} + +/** + * returns the first (non-sigil) character of 'name', + * converted to uppercase + * @param {string} name + * @return {string} the first letter + */ +export function getInitialLetter(name) { + if (!name) { + // XXX: We should find out what causes the name to sometimes be falsy. + console.trace("`name` argument to `getInitialLetter` not supplied"); + return undefined; + } + if (name.length < 1) { + return undefined; + } + + let idx = 0; + const initial = name[0]; + if ((initial === '@' || initial === '#' || initial === '+') && name[1]) { + idx++; + } + + // string.codePointAt(0) would do this, but that isn't supported by + // some browsers (notably PhantomJS). + let chars = 1; + const first = name.charCodeAt(idx); + + // check if it’s the start of a surrogate pair + if (first >= 0xD800 && first <= 0xDBFF && name[idx+1]) { + const second = name.charCodeAt(idx+1); + if (second >= 0xDC00 && second <= 0xDFFF) { + chars++; } - return url; - }, + } - avatarUrlForUser: function(user, width, height, resizeMethod) { - const url = ContentRepo.getHttpUriForMxc( - MatrixClientPeg.get().getHomeserverUrl(), user.avatarUrl, - Math.floor(width * window.devicePixelRatio), - Math.floor(height * window.devicePixelRatio), - resizeMethod, - ); - if (!url || url.length === 0) { - return null; - } - return url; - }, + const firstChar = name.substring(idx, idx+chars); + return firstChar.toUpperCase(); +} - defaultAvatarUrlForString: function(s) { - const images = ['03b381', '368bd6', 'ac3ba8']; - let total = 0; - for (let i = 0; i < s.length; ++i) { - total += s.charCodeAt(i); - } - return require('../res/img/' + images[total % images.length] + '.png'); - }, +export function avatarUrlForRoom(room, width, height, resizeMethod) { + const explicitRoomAvatar = room.getAvatarUrl( + MatrixClientPeg.get().getHomeserverUrl(), + width, + height, + resizeMethod, + false, + ); + if (explicitRoomAvatar) { + return explicitRoomAvatar; + } - /** - * returns the first (non-sigil) character of 'name', - * converted to uppercase - * @param {string} name - * @return {string} the first letter - */ - getInitialLetter(name) { - if (!name) { - // XXX: We should find out what causes the name to sometimes be falsy. - console.trace("`name` argument to `getInitialLetter` not supplied"); - return undefined; - } - if (name.length < 1) { - return undefined; - } - - let idx = 0; - const initial = name[0]; - if ((initial === '@' || initial === '#' || initial === '+') && name[1]) { - idx++; - } - - // string.codePointAt(0) would do this, but that isn't supported by - // some browsers (notably PhantomJS). - let chars = 1; - const first = name.charCodeAt(idx); - - // check if it’s the start of a surrogate pair - if (first >= 0xD800 && first <= 0xDBFF && name[idx+1]) { - const second = name.charCodeAt(idx+1); - if (second >= 0xDC00 && second <= 0xDFFF) { - chars++; - } - } - - const firstChar = name.substring(idx, idx+chars); - return firstChar.toUpperCase(); - }, - - avatarUrlForRoom(room, width, height, resizeMethod) { - const explicitRoomAvatar = room.getAvatarUrl( + let otherMember = null; + const otherUserId = DMRoomMap.shared().getUserIdForRoomId(room.roomId); + if (otherUserId) { + otherMember = room.getMember(otherUserId); + } else { + // if the room is not marked as a 1:1, but only has max 2 members + // then still try to show any avatar (pref. other member) + otherMember = room.getAvatarFallbackMember(); + } + if (otherMember) { + return otherMember.getAvatarUrl( MatrixClientPeg.get().getHomeserverUrl(), width, height, resizeMethod, false, ); - if (explicitRoomAvatar) { - return explicitRoomAvatar; - } - - let otherMember = null; - const otherUserId = DMRoomMap.shared().getUserIdForRoomId(room.roomId); - if (otherUserId) { - otherMember = room.getMember(otherUserId); - } else { - // if the room is not marked as a 1:1, but only has max 2 members - // then still try to show any avatar (pref. other member) - otherMember = room.getAvatarFallbackMember(); - } - if (otherMember) { - return otherMember.getAvatarUrl( - MatrixClientPeg.get().getHomeserverUrl(), - width, - height, - resizeMethod, - false, - ); - } - return null; - }, -}; + } + return null; +} diff --git a/src/CallHandler.js b/src/CallHandler.js index 2c22b12a3d..33e15d3cc9 100644 --- a/src/CallHandler.js +++ b/src/CallHandler.js @@ -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) { @@ -583,4 +583,4 @@ if (global.mxCallHandler === undefined) { global.mxCallHandler = callHandler; } -module.exports = global.mxCallHandler; +export default global.mxCallHandler; diff --git a/src/Entities.js b/src/Entities.js index 3135953744..872a837f3a 100644 --- a/src/Entities.js +++ b/src/Entities.js @@ -105,36 +105,33 @@ class UserEntity extends Entity { } } +export function newEntity(jsx, matchFn) { + const entity = new Entity(); + entity.getJsx = function() { + return jsx; + }; + entity.matches = matchFn; + return entity; +} -module.exports = { - newEntity: function(jsx, matchFn) { - const entity = new Entity(); - entity.getJsx = function() { - return jsx; - }; - entity.matches = matchFn; - return entity; - }, +/** + * @param {RoomMember[]} members + * @return {Entity[]} + */ +export function fromRoomMembers(members) { + return members.map(function(m) { + return new MemberEntity(m); + }); +} - /** - * @param {RoomMember[]} members - * @return {Entity[]} - */ - fromRoomMembers: function(members) { - return members.map(function(m) { - return new MemberEntity(m); - }); - }, - - /** - * @param {User[]} users - * @param {boolean} showInviteButton - * @param {Function} inviteFn Called with the user ID. - * @return {Entity[]} - */ - fromUsers: function(users, showInviteButton, inviteFn) { - return users.map(function(u) { - return new UserEntity(u, showInviteButton, inviteFn); - }); - }, -}; +/** + * @param {User[]} users + * @param {boolean} showInviteButton + * @param {Function} inviteFn Called with the user ID. + * @return {Entity[]} + */ +export function fromUsers(users, showInviteButton, inviteFn) { + return users.map(function(u) { + return new UserEntity(u, showInviteButton, inviteFn); + }); +} diff --git a/src/ImageUtils.js b/src/ImageUtils.js index a83d94a633..c0f7b94b81 100644 --- a/src/ImageUtils.js +++ b/src/ImageUtils.js @@ -16,41 +16,38 @@ limitations under the License. 'use strict'; -module.exports = { - - /** - * Returns the actual height that an image of dimensions (fullWidth, fullHeight) - * will occupy if resized to fit inside a thumbnail bounding box of size - * (thumbWidth, thumbHeight). - * - * If the aspect ratio of the source image is taller than the aspect ratio of - * the thumbnail bounding box, then we return the thumbHeight parameter unchanged. - * Otherwise we return the thumbHeight parameter scaled down appropriately to - * reflect the actual height the scaled thumbnail occupies. - * - * This is very useful for calculating how much height a thumbnail will actually - * consume in the timeline, when performing scroll offset calcuations - * (e.g. scroll locking) - */ - thumbHeight: function(fullWidth, fullHeight, thumbWidth, thumbHeight) { - if (!fullWidth || !fullHeight) { - // Cannot calculate thumbnail height for image: missing w/h in metadata. We can't even - // log this because it's spammy - return undefined; - } - if (fullWidth < thumbWidth && fullHeight < thumbHeight) { - // no scaling needs to be applied - return fullHeight; - } - const widthMulti = thumbWidth / fullWidth; - const heightMulti = thumbHeight / fullHeight; - if (widthMulti < heightMulti) { - // width is the dominant dimension so scaling will be fixed on that - return Math.floor(widthMulti * fullHeight); - } else { - // height is the dominant dimension so scaling will be fixed on that - return Math.floor(heightMulti * fullHeight); - } - }, -}; +/** + * Returns the actual height that an image of dimensions (fullWidth, fullHeight) + * will occupy if resized to fit inside a thumbnail bounding box of size + * (thumbWidth, thumbHeight). + * + * If the aspect ratio of the source image is taller than the aspect ratio of + * the thumbnail bounding box, then we return the thumbHeight parameter unchanged. + * Otherwise we return the thumbHeight parameter scaled down appropriately to + * reflect the actual height the scaled thumbnail occupies. + * + * This is very useful for calculating how much height a thumbnail will actually + * consume in the timeline, when performing scroll offset calcuations + * (e.g. scroll locking) + */ +export function thumbHeight(fullWidth, fullHeight, thumbWidth, thumbHeight) { + if (!fullWidth || !fullHeight) { + // Cannot calculate thumbnail height for image: missing w/h in metadata. We can't even + // log this because it's spammy + return undefined; + } + if (fullWidth < thumbWidth && fullHeight < thumbHeight) { + // no scaling needs to be applied + return fullHeight; + } + const widthMulti = thumbWidth / fullWidth; + const heightMulti = thumbHeight / fullHeight; + if (widthMulti < heightMulti) { + // width is the dominant dimension so scaling will be fixed on that + return Math.floor(widthMulti * fullHeight); + } else { + // height is the dominant dimension so scaling will be fixed on that + return Math.floor(heightMulti * fullHeight); + } +} diff --git a/src/Notifier.js b/src/Notifier.js index 0c335a8030..b030f1b6f9 100644 --- a/src/Notifier.js +++ b/src/Notifier.js @@ -364,4 +364,4 @@ if (!global.mxNotifier) { global.mxNotifier = Notifier; } -module.exports = global.mxNotifier; +export default global.mxNotifier; diff --git a/src/ObjectUtils.js b/src/ObjectUtils.js index 07d8b465af..24dfe61d68 100644 --- a/src/ObjectUtils.js +++ b/src/ObjectUtils.js @@ -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; -}; +} diff --git a/src/PasswordReset.js b/src/PasswordReset.js index 31339eb4e5..320599f6d9 100644 --- a/src/PasswordReset.js +++ b/src/PasswordReset.js @@ -25,7 +25,7 @@ import { _t } from './languageHandler'; * the client owns the given email address, which is then passed to the password * API on the homeserver in question with the new password. */ -class PasswordReset { +export default class PasswordReset { /** * Configure the endpoints for password resetting. * @param {string} homeserverUrl The URL to the HS which has the account to reset. @@ -101,4 +101,3 @@ class PasswordReset { } } -module.exports = PasswordReset; diff --git a/src/PlatformPeg.js b/src/PlatformPeg.js index 5c1112e23b..34131fde7d 100644 --- a/src/PlatformPeg.js +++ b/src/PlatformPeg.js @@ -47,4 +47,4 @@ class PlatformPeg { if (!global.mxPlatformPeg) { global.mxPlatformPeg = new PlatformPeg(); } -module.exports = global.mxPlatformPeg; +export default global.mxPlatformPeg; diff --git a/src/Presence.js b/src/Presence.js index e3f5169c8f..2fc13a090b 100644 --- a/src/Presence.js +++ b/src/Presence.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd 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. @@ -104,4 +105,4 @@ class Presence { } } -module.exports = new Presence(); +export default new Presence(); diff --git a/src/Resend.js b/src/Resend.js index 31d541630c..1d73212340 100644 --- a/src/Resend.js +++ b/src/Resend.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. @@ -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); - }, -}; + } +} diff --git a/src/RoomListSorter.js b/src/RoomListSorter.js index c06cc60c97..0ff37a6af2 100644 --- a/src/RoomListSorter.js +++ b/src/RoomListSorter.js @@ -24,12 +24,8 @@ function tsOfNewestEvent(room) { } } -function mostRecentActivityFirst(roomList) { +export function mostRecentActivityFirst(roomList) { return roomList.sort(function(a, b) { return tsOfNewestEvent(b) - tsOfNewestEvent(a); }); } - -module.exports = { - mostRecentActivityFirst, -}; diff --git a/src/ScalarMessaging.js b/src/ScalarMessaging.js index daee7e3296..2211e513c3 100644 --- a/src/ScalarMessaging.js +++ b/src/ScalarMessaging.js @@ -658,30 +658,29 @@ const onMessage = function(event) { let listenerCount = 0; let openManagerUrl = null; -module.exports = { - startListening: function() { - if (listenerCount === 0) { - window.addEventListener("message", onMessage, false); - } - listenerCount += 1; - }, - stopListening: function() { - listenerCount -= 1; - if (listenerCount === 0) { - window.removeEventListener("message", onMessage); - } - if (listenerCount < 0) { - // Make an error so we get a stack trace - const e = new Error( - "ScalarMessaging: mismatched startListening / stopListening detected." + - " Negative count", - ); - console.error(e); - } - }, +export function startListening() { + if (listenerCount === 0) { + window.addEventListener("message", onMessage, false); + } + listenerCount += 1; +} - setOpenManagerUrl: function(url) { - openManagerUrl = url; - }, -}; +export function stopListening() { + listenerCount -= 1; + if (listenerCount === 0) { + window.removeEventListener("message", onMessage); + } + if (listenerCount < 0) { + // Make an error so we get a stack trace + const e = new Error( + "ScalarMessaging: mismatched startListening / stopListening detected." + + " Negative count", + ); + console.error(e); + } +} + +export function setOpenManagerUrl(url) { + openManagerUrl = url; +} diff --git a/src/Skinner.js b/src/Skinner.js index 06855691bd..3baecc9fb3 100644 --- a/src/Skinner.js +++ b/src/Skinner.js @@ -106,5 +106,5 @@ class Skinner { if (global.mxSkinner === undefined) { global.mxSkinner = new Skinner(); } -module.exports = global.mxSkinner; +export default global.mxSkinner; diff --git a/src/TextForEvent.js b/src/TextForEvent.js index 8a5bddf617..8290e17555 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -620,10 +620,8 @@ for (const evType of ALL_RULE_TYPES) { stateHandlers[evType] = textForMjolnirEvent; } -module.exports = { - textForEvent: function(ev) { - const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()]; - if (handler) return handler(ev); - return ''; - }, -}; +export function textForEvent(ev) { + const handler = (ev.isState() ? stateHandlers : handlers)[ev.getType()]; + if (handler) return handler(ev); + return ''; +} diff --git a/src/Unread.js b/src/Unread.js index 6aaa733f20..bbdd380b43 100644 --- a/src/Unread.js +++ b/src/Unread.js @@ -18,76 +18,74 @@ import {MatrixClientPeg} from "./MatrixClientPeg"; import shouldHideEvent from './shouldHideEvent'; import * as sdk from "./index"; -module.exports = { - /** - * Returns true iff this event arriving in a room should affect the room's - * count of unread messages - */ - eventTriggersUnreadCount: function(ev) { - if (ev.sender && ev.sender.userId == MatrixClientPeg.get().credentials.userId) { - return false; - } else if (ev.getType() == 'm.room.member') { - return false; - } else if (ev.getType() == 'm.room.third_party_invite') { - return false; - } else if (ev.getType() == 'm.call.answer' || ev.getType() == 'm.call.hangup') { - return false; - } else if (ev.getType() == 'm.room.message' && ev.getContent().msgtype == 'm.notify') { - return false; - } else if (ev.getType() == 'm.room.aliases' || ev.getType() == 'm.room.canonical_alias') { - return false; - } else if (ev.getType() == 'm.room.server_acl') { +/** + * Returns true iff this event arriving in a room should affect the room's + * count of unread messages + */ +export function eventTriggersUnreadCount(ev) { + if (ev.sender && ev.sender.userId == MatrixClientPeg.get().credentials.userId) { + return false; + } else if (ev.getType() == 'm.room.member') { + return false; + } else if (ev.getType() == 'm.room.third_party_invite') { + return false; + } else if (ev.getType() == 'm.call.answer' || ev.getType() == 'm.call.hangup') { + return false; + } else if (ev.getType() == 'm.room.message' && ev.getContent().msgtype == 'm.notify') { + return false; + } else if (ev.getType() == 'm.room.aliases' || ev.getType() == 'm.room.canonical_alias') { + return false; + } else if (ev.getType() == 'm.room.server_acl') { + return false; + } + const EventTile = sdk.getComponent('rooms.EventTile'); + return EventTile.haveTileForEvent(ev); +} + +export function doesRoomHaveUnreadMessages(room) { + const myUserId = MatrixClientPeg.get().credentials.userId; + + // get the most recent read receipt sent by our account. + // N.B. this is NOT a read marker (RM, aka "read up to marker"), + // despite the name of the method :(( + const readUpToId = room.getEventReadUpTo(myUserId); + + // as we don't send RRs for our own messages, make sure we special case that + // if *we* sent the last message into the room, we consider it not unread! + // Should fix: https://github.com/vector-im/riot-web/issues/3263 + // https://github.com/vector-im/riot-web/issues/2427 + // ...and possibly some of the others at + // https://github.com/vector-im/riot-web/issues/3363 + if (room.timeline.length && + room.timeline[room.timeline.length - 1].sender && + room.timeline[room.timeline.length - 1].sender.userId === myUserId) { + return false; + } + + // this just looks at whatever history we have, which if we've only just started + // up probably won't be very much, so if the last couple of events are ones that + // don't count, we don't know if there are any events that do count between where + // we have and the read receipt. We could fetch more history to try & find out, + // but currently we just guess. + + // Loop through messages, starting with the most recent... + for (let i = room.timeline.length - 1; i >= 0; --i) { + const ev = room.timeline[i]; + + if (ev.getId() == readUpToId) { + // If we've read up to this event, there's nothing more recent + // that counts and we can stop looking because the user's read + // this and everything before. return false; + } else if (!shouldHideEvent(ev) && eventTriggersUnreadCount(ev)) { + // We've found a message that counts before we hit + // the user's read receipt, so this room is definitely unread. + return true; } - const EventTile = sdk.getComponent('rooms.EventTile'); - return EventTile.haveTileForEvent(ev); - }, - - doesRoomHaveUnreadMessages: function(room) { - const myUserId = MatrixClientPeg.get().credentials.userId; - - // get the most recent read receipt sent by our account. - // N.B. this is NOT a read marker (RM, aka "read up to marker"), - // despite the name of the method :(( - const readUpToId = room.getEventReadUpTo(myUserId); - - // as we don't send RRs for our own messages, make sure we special case that - // if *we* sent the last message into the room, we consider it not unread! - // Should fix: https://github.com/vector-im/riot-web/issues/3263 - // https://github.com/vector-im/riot-web/issues/2427 - // ...and possibly some of the others at - // https://github.com/vector-im/riot-web/issues/3363 - if (room.timeline.length && - room.timeline[room.timeline.length - 1].sender && - room.timeline[room.timeline.length - 1].sender.userId === myUserId) { - return false; - } - - // this just looks at whatever history we have, which if we've only just started - // up probably won't be very much, so if the last couple of events are ones that - // don't count, we don't know if there are any events that do count between where - // we have and the read receipt. We could fetch more history to try & find out, - // but currently we just guess. - - // Loop through messages, starting with the most recent... - for (let i = room.timeline.length - 1; i >= 0; --i) { - const ev = room.timeline[i]; - - if (ev.getId() == readUpToId) { - // If we've read up to this event, there's nothing more recent - // that counts and we can stop looking because the user's read - // this and everything before. - return false; - } else if (!shouldHideEvent(ev) && this.eventTriggersUnreadCount(ev)) { - // We've found a message that counts before we hit - // the user's read receipt, so this room is definitely unread. - return true; - } - } - // If we got here, we didn't find a message that counted but didn't find - // the user's read receipt either, so we guess and say that the room is - // unread on the theory that false positives are better than false - // negatives here. - return true; - }, -}; + } + // If we got here, we didn't find a message that counted but didn't find + // the user's read receipt either, so we guess and say that the room is + // unread on the theory that false positives are better than false + // negatives here. + return true; +} diff --git a/src/VectorConferenceHandler.js b/src/VectorConferenceHandler.js index 0ade4c9daf..d0120136e1 100644 --- a/src/VectorConferenceHandler.js +++ b/src/VectorConferenceHandler.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. @@ -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'; diff --git a/src/WhoIsTyping.js b/src/WhoIsTyping.js index 8fce6d8311..d11cddf487 100644 --- a/src/WhoIsTyping.js +++ b/src/WhoIsTyping.js @@ -17,68 +17,66 @@ limitations under the License. import {MatrixClientPeg} from "./MatrixClientPeg"; import { _t } from './languageHandler'; -module.exports = { - usersTypingApartFromMeAndIgnored: function(room) { - return this.usersTyping( - room, [MatrixClientPeg.get().credentials.userId].concat(MatrixClientPeg.get().getIgnoredUsers()), - ); - }, +export function usersTypingApartFromMeAndIgnored(room) { + return usersTyping( + room, [MatrixClientPeg.get().credentials.userId].concat(MatrixClientPeg.get().getIgnoredUsers()), + ); +} - usersTypingApartFromMe: function(room) { - return this.usersTyping( - room, [MatrixClientPeg.get().credentials.userId], - ); - }, +export function usersTypingApartFromMe(room) { + return usersTyping( + room, [MatrixClientPeg.get().credentials.userId], + ); +} - /** - * Given a Room object and, optionally, a list of userID strings - * to exclude, return a list of user objects who are typing. - * @param {Room} room: room object to get users from. - * @param {string[]} exclude: list of user mxids to exclude. - * @returns {string[]} list of user objects who are typing. - */ - usersTyping: function(room, exclude) { - const whoIsTyping = []; +/** + * Given a Room object and, optionally, a list of userID strings + * to exclude, return a list of user objects who are typing. + * @param {Room} room: room object to get users from. + * @param {string[]} exclude: list of user mxids to exclude. + * @returns {string[]} list of user objects who are typing. + */ +export function usersTyping(room, exclude) { + const whoIsTyping = []; - if (exclude === undefined) { - exclude = []; - } + if (exclude === undefined) { + exclude = []; + } - const memberKeys = Object.keys(room.currentState.members); - for (let i = 0; i < memberKeys.length; ++i) { - const userId = memberKeys[i]; + const memberKeys = Object.keys(room.currentState.members); + for (let i = 0; i < memberKeys.length; ++i) { + const userId = memberKeys[i]; - if (room.currentState.members[userId].typing) { - if (exclude.indexOf(userId) === -1) { - whoIsTyping.push(room.currentState.members[userId]); - } + if (room.currentState.members[userId].typing) { + if (exclude.indexOf(userId) === -1) { + whoIsTyping.push(room.currentState.members[userId]); } } + } - return whoIsTyping; - }, + return whoIsTyping; +} - whoIsTypingString: function(whoIsTyping, limit) { - let othersCount = 0; - if (whoIsTyping.length > limit) { - othersCount = whoIsTyping.length - limit + 1; - } - if (whoIsTyping.length === 0) { - return ''; - } else if (whoIsTyping.length === 1) { - return _t('%(displayName)s is typing …', {displayName: whoIsTyping[0].name}); - } - const names = whoIsTyping.map(function(m) { - return m.name; +export function whoIsTypingString(whoIsTyping, limit) { + let othersCount = 0; + if (whoIsTyping.length > limit) { + othersCount = whoIsTyping.length - limit + 1; + } + if (whoIsTyping.length === 0) { + return ''; + } else if (whoIsTyping.length === 1) { + return _t('%(displayName)s is typing …', {displayName: whoIsTyping[0].name}); + } + const names = whoIsTyping.map(function(m) { + return m.name; + }); + if (othersCount>=1) { + return _t('%(names)s and %(count)s others are typing …', { + names: names.slice(0, limit - 1).join(', '), + count: othersCount, }); - if (othersCount>=1) { - return _t('%(names)s and %(count)s others are typing …', { - names: names.slice(0, limit - 1).join(', '), - count: othersCount, - }); - } else { - const lastPerson = names.pop(); - return _t('%(names)s and %(lastPerson)s are typing …', {names: names.join(', '), lastPerson: lastPerson}); - } - }, -}; + } else { + const lastPerson = names.pop(); + return _t('%(names)s and %(lastPerson)s are typing …', {names: names.join(', '), lastPerson: lastPerson}); + } +} diff --git a/src/async-components/views/dialogs/EncryptedEventDialog.js b/src/async-components/views/dialogs/EncryptedEventDialog.js index 45cc154906..1309efd811 100644 --- a/src/async-components/views/dialogs/EncryptedEventDialog.js +++ b/src/async-components/views/dialogs/EncryptedEventDialog.js @@ -22,7 +22,7 @@ import {MatrixClientPeg} from "../../../MatrixClientPeg"; const sdk = require('../../../index'); -module.exports = createReactClass({ +export default createReactClass({ displayName: 'EncryptedEventDialog', propTypes: { diff --git a/src/components/structures/CompatibilityPage.js b/src/components/structures/CompatibilityPage.js index 28c86f8dd8..9a3fdb5f39 100644 --- a/src/components/structures/CompatibilityPage.js +++ b/src/components/structures/CompatibilityPage.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> +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. @@ -20,7 +21,7 @@ import createReactClass from 'create-react-class'; import PropTypes from 'prop-types'; import { _t } from '../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'CompatibilityPage', propTypes: { onAccept: PropTypes.func, diff --git a/src/components/structures/FilePanel.js b/src/components/structures/FilePanel.js index 03fd2e187a..61b3d2d4b9 100644 --- a/src/components/structures/FilePanel.js +++ b/src/components/structures/FilePanel.js @@ -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. @@ -126,4 +127,4 @@ const FilePanel = createReactClass({ }, }); -module.exports = FilePanel; +export default FilePanel; diff --git a/src/components/structures/LeftPanel.js b/src/components/structures/LeftPanel.js index 080344abc6..4f70dc2a9a 100644 --- a/src/components/structures/LeftPanel.js +++ b/src/components/structures/LeftPanel.js @@ -308,4 +308,4 @@ const LeftPanel = createReactClass({ }, }); -module.exports = LeftPanel; +export default LeftPanel; diff --git a/src/components/structures/NotificationPanel.js b/src/components/structures/NotificationPanel.js index 70ea24ad17..c1a0ec9c4b 100644 --- a/src/components/structures/NotificationPanel.js +++ b/src/components/structures/NotificationPanel.js @@ -1,6 +1,7 @@ /* Copyright 2016 OpenMarket Ltd 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. @@ -60,4 +61,4 @@ const NotificationPanel = createReactClass({ }, }); -module.exports = NotificationPanel; +export default NotificationPanel; diff --git a/src/components/structures/RoomDirectory.js b/src/components/structures/RoomDirectory.js index 94a6d04b55..e06c00902b 100644 --- a/src/components/structures/RoomDirectory.js +++ b/src/components/structures/RoomDirectory.js @@ -36,7 +36,7 @@ function track(action) { Analytics.trackEvent('RoomDirectory', action); } -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomDirectory', propTypes: { diff --git a/src/components/structures/RoomStatusBar.js b/src/components/structures/RoomStatusBar.js index 487ccecd31..0839c364e5 100644 --- a/src/components/structures/RoomStatusBar.js +++ b/src/components/structures/RoomStatusBar.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd Copyright 2017, 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. @@ -38,7 +39,7 @@ function getUnsentMessages(room) { }); } -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomStatusBar', propTypes: { diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 198120428b..1cb9e7db5e 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -66,13 +66,13 @@ 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), }); -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomView', propTypes: { ConferenceHandler: PropTypes.any, @@ -2002,5 +2002,3 @@ module.exports = createReactClass({ ); }, }); - -module.exports.RoomContext = RoomContext; diff --git a/src/components/structures/ScrollPanel.js b/src/components/structures/ScrollPanel.js index 17583a22ed..c5725e1343 100644 --- a/src/components/structures/ScrollPanel.js +++ b/src/components/structures/ScrollPanel.js @@ -84,7 +84,7 @@ if (DEBUG_SCROLL) { * offset as normal. */ -module.exports = createReactClass({ +export default createReactClass({ displayName: 'ScrollPanel', propTypes: { diff --git a/src/components/structures/SearchBox.js b/src/components/structures/SearchBox.js index 0aa2e15f4c..faa20a68ba 100644 --- a/src/components/structures/SearchBox.js +++ b/src/components/structures/SearchBox.js @@ -24,7 +24,7 @@ import { throttle } from 'lodash'; import AccessibleButton from '../../components/views/elements/AccessibleButton'; import classNames from 'classnames'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'SearchBox', propTypes: { diff --git a/src/components/structures/TimelinePanel.js b/src/components/structures/TimelinePanel.js index 3996b74922..54539b63fb 100644 --- a/src/components/structures/TimelinePanel.js +++ b/src/components/structures/TimelinePanel.js @@ -1344,4 +1344,4 @@ const TimelinePanel = createReactClass({ }, }); -module.exports = TimelinePanel; +export default TimelinePanel; diff --git a/src/components/structures/UploadBar.js b/src/components/structures/UploadBar.js index adaf8824fc..1aec63f04e 100644 --- a/src/components/structures/UploadBar.js +++ b/src/components/structures/UploadBar.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. @@ -22,7 +23,7 @@ import dis from "../../dispatcher"; import filesize from "filesize"; import { _t } from '../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'UploadBar', propTypes: { room: PropTypes.object, diff --git a/src/components/structures/ViewSource.js b/src/components/structures/ViewSource.js index 391cbf6eef..326ba2c22f 100644 --- a/src/components/structures/ViewSource.js +++ b/src/components/structures/ViewSource.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> +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. @@ -23,7 +24,7 @@ import {_t} from "../../languageHandler"; import * as sdk from "../../index"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'ViewSource', propTypes: { diff --git a/src/components/structures/auth/ForgotPassword.js b/src/components/structures/auth/ForgotPassword.js index 01453f1322..4576067caa 100644 --- a/src/components/structures/auth/ForgotPassword.js +++ b/src/components/structures/auth/ForgotPassword.js @@ -40,7 +40,7 @@ const PHASE_EMAIL_SENT = 3; // User has clicked the link in email and completed reset const PHASE_DONE = 4; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'ForgotPassword', propTypes: { diff --git a/src/components/structures/auth/Login.js b/src/components/structures/auth/Login.js index bdc95d4b94..7bc2dbcbae 100644 --- a/src/components/structures/auth/Login.js +++ b/src/components/structures/auth/Login.js @@ -54,7 +54,7 @@ _td("General failure"); /** * A wire component which glues together login UI components and Login logic */ -module.exports = createReactClass({ +export default createReactClass({ displayName: 'Login', propTypes: { diff --git a/src/components/structures/auth/PostRegistration.js b/src/components/structures/auth/PostRegistration.js index 706ab54de4..8eef8dce11 100644 --- a/src/components/structures/auth/PostRegistration.js +++ b/src/components/structures/auth/PostRegistration.js @@ -22,7 +22,7 @@ import {MatrixClientPeg} from '../../../MatrixClientPeg'; import { _t } from '../../../languageHandler'; import AuthPage from "../../views/auth/AuthPage"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'PostRegistration', propTypes: { diff --git a/src/components/structures/auth/Registration.js b/src/components/structures/auth/Registration.js index bcdb1953ba..fdf2f51e00 100644 --- a/src/components/structures/auth/Registration.js +++ b/src/components/structures/auth/Registration.js @@ -41,7 +41,7 @@ const PHASE_REGISTRATION = 1; // Enable phases for registration const PHASES_ENABLED = true; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'Registration', propTypes: { diff --git a/src/components/views/auth/AuthFooter.js b/src/components/views/auth/AuthFooter.js index 39d636f9cc..4076141606 100644 --- a/src/components/views/auth/AuthFooter.js +++ b/src/components/views/auth/AuthFooter.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd 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. @@ -19,7 +20,7 @@ import { _t } from '../../../languageHandler'; import React from 'react'; import createReactClass from 'create-react-class'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'AuthFooter', render: function() { diff --git a/src/components/views/auth/AuthHeader.js b/src/components/views/auth/AuthHeader.js index abf9e8895e..133fd41359 100644 --- a/src/components/views/auth/AuthHeader.js +++ b/src/components/views/auth/AuthHeader.js @@ -19,7 +19,7 @@ import React from 'react'; import createReactClass from 'create-react-class'; import * as sdk from '../../../index'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'AuthHeader', render: function() { diff --git a/src/components/views/auth/CaptchaForm.js b/src/components/views/auth/CaptchaForm.js index f907a58026..2da837f029 100644 --- a/src/components/views/auth/CaptchaForm.js +++ b/src/components/views/auth/CaptchaForm.js @@ -24,7 +24,7 @@ const DIV_ID = 'mx_recaptcha'; /** * A pure UI component which displays a captcha form. */ -module.exports = createReactClass({ +export default createReactClass({ displayName: 'CaptchaForm', propTypes: { diff --git a/src/components/views/auth/CustomServerDialog.js b/src/components/views/auth/CustomServerDialog.js index a9a3a53f02..024951e6c0 100644 --- a/src/components/views/auth/CustomServerDialog.js +++ b/src/components/views/auth/CustomServerDialog.js @@ -19,7 +19,7 @@ import React from 'react'; import createReactClass from 'create-react-class'; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'CustomServerDialog', render: function() { diff --git a/src/components/views/auth/RegistrationForm.js b/src/components/views/auth/RegistrationForm.js index d85ad6b3b2..91f8e1b226 100644 --- a/src/components/views/auth/RegistrationForm.js +++ b/src/components/views/auth/RegistrationForm.js @@ -41,7 +41,7 @@ const PASSWORD_MIN_SCORE = 3; // safely unguessable: moderate protection from of /** * A pure UI component which displays a registration form. */ -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RegistrationForm', propTypes: { diff --git a/src/components/views/avatars/BaseAvatar.js b/src/components/views/avatars/BaseAvatar.js index 8218ffdfc6..1dd52c99fa 100644 --- a/src/components/views/avatars/BaseAvatar.js +++ b/src/components/views/avatars/BaseAvatar.js @@ -2,6 +2,7 @@ Copyright 2015, 2016 OpenMarket Ltd Copyright 2018 New Vector Ltd Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> +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. @@ -24,7 +25,7 @@ import * as AvatarLogic from '../../../Avatar'; import SettingsStore from "../../../settings/SettingsStore"; import AccessibleButton from '../elements/AccessibleButton'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'BaseAvatar', propTypes: { diff --git a/src/components/views/avatars/MemberAvatar.js b/src/components/views/avatars/MemberAvatar.js index 6961a00d6d..088490b9d1 100644 --- a/src/components/views/avatars/MemberAvatar.js +++ b/src/components/views/avatars/MemberAvatar.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. @@ -21,7 +22,7 @@ import * as Avatar from '../../../Avatar'; import * as sdk from "../../../index"; import dis from "../../../dispatcher"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'MemberAvatar', propTypes: { diff --git a/src/components/views/avatars/RoomAvatar.js b/src/components/views/avatars/RoomAvatar.js index 55fe7e07b7..3b51fae4b3 100644 --- a/src/components/views/avatars/RoomAvatar.js +++ b/src/components/views/avatars/RoomAvatar.js @@ -22,7 +22,7 @@ import Modal from '../../../Modal'; import * as sdk from "../../../index"; import * as Avatar from '../../../Avatar'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomAvatar', // Room may be left unset here, but if it is, diff --git a/src/components/views/context_menus/MessageContextMenu.js b/src/components/views/context_menus/MessageContextMenu.js index 3aec0e6752..6a049ce9b9 100644 --- a/src/components/views/context_menus/MessageContextMenu.js +++ b/src/components/views/context_menus/MessageContextMenu.js @@ -37,7 +37,7 @@ function canCancel(eventStatus) { return eventStatus === EventStatus.QUEUED || eventStatus === EventStatus.NOT_SENT; } -module.exports = createReactClass({ +export default createReactClass({ displayName: 'MessageContextMenu', propTypes: { diff --git a/src/components/views/context_menus/RoomTileContextMenu.js b/src/components/views/context_menus/RoomTileContextMenu.js index fa4f4f54ba..6e2bd8ebf5 100644 --- a/src/components/views/context_menus/RoomTileContextMenu.js +++ b/src/components/views/context_menus/RoomTileContextMenu.js @@ -63,7 +63,7 @@ const NotifOption = ({active, onClick, src, label}) => { ); }; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomTileContextMenu', propTypes: { diff --git a/src/components/views/create_room/CreateRoomButton.js b/src/components/views/create_room/CreateRoomButton.js index 1c44aed78c..adf3972eff 100644 --- a/src/components/views/create_room/CreateRoomButton.js +++ b/src/components/views/create_room/CreateRoomButton.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. @@ -19,7 +20,7 @@ import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'CreateRoomButton', propTypes: { onCreateRoom: PropTypes.func, diff --git a/src/components/views/create_room/Presets.js b/src/components/views/create_room/Presets.js index f512c3e2fd..0f18d11511 100644 --- a/src/components/views/create_room/Presets.js +++ b/src/components/views/create_room/Presets.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. @@ -25,7 +26,7 @@ const Presets = { Custom: "custom", }; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'CreateRoomPresets', propTypes: { onChange: PropTypes.func, diff --git a/src/components/views/create_room/RoomAlias.js b/src/components/views/create_room/RoomAlias.js index fd3e3365f7..bc5dec1468 100644 --- a/src/components/views/create_room/RoomAlias.js +++ b/src/components/views/create_room/RoomAlias.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. @@ -19,7 +20,7 @@ import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomAlias', propTypes: { // Specifying a homeserver will make magical things happen when you, diff --git a/src/components/views/dialogs/AddressPickerDialog.js b/src/components/views/dialogs/AddressPickerDialog.js index d32833b144..8867800d1e 100644 --- a/src/components/views/dialogs/AddressPickerDialog.js +++ b/src/components/views/dialogs/AddressPickerDialog.js @@ -43,7 +43,7 @@ const addressTypeName = { }; -module.exports = createReactClass({ +export default createReactClass({ displayName: "AddressPickerDialog", propTypes: { diff --git a/src/components/views/elements/DialogButtons.js b/src/components/views/elements/DialogButtons.js index e7b3a9c7eb..4e47e73052 100644 --- a/src/components/views/elements/DialogButtons.js +++ b/src/components/views/elements/DialogButtons.js @@ -1,6 +1,7 @@ /* Copyright 2017 Aidan Gauland 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. @@ -23,7 +24,7 @@ import { _t } from '../../../languageHandler'; /** * Basic container for buttons in modal dialogs. */ -module.exports = createReactClass({ +export default createReactClass({ displayName: "DialogButtons", propTypes: { diff --git a/src/components/views/elements/EditableText.js b/src/components/views/elements/EditableText.js index 5913682255..fbac63cbba 100644 --- a/src/components/views/elements/EditableText.js +++ b/src/components/views/elements/EditableText.js @@ -20,7 +20,7 @@ import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; import {Key} from "../../../Keyboard"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'EditableText', propTypes: { diff --git a/src/components/views/elements/InlineSpinner.js b/src/components/views/elements/InlineSpinner.js index 18711f90d3..ad70471d89 100644 --- a/src/components/views/elements/InlineSpinner.js +++ b/src/components/views/elements/InlineSpinner.js @@ -17,7 +17,7 @@ limitations under the License. import React from "react"; import createReactClass from 'create-react-class'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'InlineSpinner', render: function() { diff --git a/src/components/views/elements/MemberEventListSummary.js b/src/components/views/elements/MemberEventListSummary.js index c47e095e01..fc79fc87d0 100644 --- a/src/components/views/elements/MemberEventListSummary.js +++ b/src/components/views/elements/MemberEventListSummary.js @@ -24,7 +24,7 @@ import { formatCommaSeparatedList } from '../../../utils/FormattingUtils'; import * as sdk from "../../../index"; import {MatrixEvent} from "matrix-js-sdk"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'MemberEventListSummary', propTypes: { diff --git a/src/components/views/elements/MessageSpinner.js b/src/components/views/elements/MessageSpinner.js index f00fdcf576..1775fdd4d7 100644 --- a/src/components/views/elements/MessageSpinner.js +++ b/src/components/views/elements/MessageSpinner.js @@ -17,7 +17,7 @@ limitations under the License. import React from 'react'; import createReactClass from 'create-react-class'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'MessageSpinner', render: function() { diff --git a/src/components/views/elements/PersistentApp.js b/src/components/views/elements/PersistentApp.js index df1a3196d6..a807ed3b93 100644 --- a/src/components/views/elements/PersistentApp.js +++ b/src/components/views/elements/PersistentApp.js @@ -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. @@ -22,7 +23,7 @@ import WidgetUtils from '../../../utils/WidgetUtils'; import * as sdk from '../../../index'; import {MatrixClientPeg} from '../../../MatrixClientPeg'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'PersistentApp', getInitialState: function() { diff --git a/src/components/views/elements/PowerSelector.js b/src/components/views/elements/PowerSelector.js index e6babded32..2f4c08922a 100644 --- a/src/components/views/elements/PowerSelector.js +++ b/src/components/views/elements/PowerSelector.js @@ -22,7 +22,7 @@ import { _t } from '../../../languageHandler'; import Field from "./Field"; import {Key} from "../../../Keyboard"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'PowerSelector', propTypes: { diff --git a/src/components/views/elements/ProgressBar.js b/src/components/views/elements/ProgressBar.js index 3561763e51..045731ba38 100644 --- a/src/components/views/elements/ProgressBar.js +++ b/src/components/views/elements/ProgressBar.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. @@ -18,7 +19,7 @@ import React from "react"; import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'ProgressBar', propTypes: { value: PropTypes.number, diff --git a/src/components/views/elements/SettingsFlag.js b/src/components/views/elements/SettingsFlag.js index a3a6d18d33..15f17805a8 100644 --- a/src/components/views/elements/SettingsFlag.js +++ b/src/components/views/elements/SettingsFlag.js @@ -1,5 +1,6 @@ /* Copyright 2017 Travis Ralston +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. @@ -21,7 +22,7 @@ import SettingsStore from "../../../settings/SettingsStore"; import { _t } from '../../../languageHandler'; import ToggleSwitch from "./ToggleSwitch"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'SettingsFlag', propTypes: { name: PropTypes.string.isRequired, diff --git a/src/components/views/elements/Spinner.js b/src/components/views/elements/Spinner.js index 5d43e836cc..b1fe97d5d2 100644 --- a/src/components/views/elements/Spinner.js +++ b/src/components/views/elements/Spinner.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. @@ -17,7 +18,7 @@ limitations under the License. import React from "react"; import createReactClass from 'create-react-class'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'Spinner', render: function() { diff --git a/src/components/views/elements/TintableSvg.js b/src/components/views/elements/TintableSvg.js index 73ba375d59..3e0e41f411 100644 --- a/src/components/views/elements/TintableSvg.js +++ b/src/components/views/elements/TintableSvg.js @@ -1,5 +1,6 @@ /* Copyright 2015 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. @@ -83,4 +84,4 @@ Tinter.registerTintable(function() { } }); -module.exports = TintableSvg; +export default TintableSvg; diff --git a/src/components/views/elements/Tooltip.js b/src/components/views/elements/Tooltip.js index 8ff3ce9bdb..fd845d9db3 100644 --- a/src/components/views/elements/Tooltip.js +++ b/src/components/views/elements/Tooltip.js @@ -2,6 +2,7 @@ Copyright 2015, 2016 OpenMarket Ltd Copyright 2019 New Vector Ltd Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> +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. @@ -26,7 +27,7 @@ import classNames from 'classnames'; const MIN_TOOLTIP_HEIGHT = 25; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'Tooltip', propTypes: { diff --git a/src/components/views/elements/TooltipButton.js b/src/components/views/elements/TooltipButton.js index 7d50473469..a32044873b 100644 --- a/src/components/views/elements/TooltipButton.js +++ b/src/components/views/elements/TooltipButton.js @@ -19,7 +19,7 @@ import React from 'react'; import createReactClass from 'create-react-class'; import * as sdk from '../../../index'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'TooltipButton', getInitialState: function() { diff --git a/src/components/views/elements/TruncatedList.js b/src/components/views/elements/TruncatedList.js index e6a5e2ae32..9ce2395638 100644 --- a/src/components/views/elements/TruncatedList.js +++ b/src/components/views/elements/TruncatedList.js @@ -20,7 +20,7 @@ import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'TruncatedList', propTypes: { diff --git a/src/components/views/elements/UserSelector.js b/src/components/views/elements/UserSelector.js index 1010d4144c..706c6ed2e5 100644 --- a/src/components/views/elements/UserSelector.js +++ b/src/components/views/elements/UserSelector.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. @@ -19,7 +20,7 @@ import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'UserSelector', propTypes: { diff --git a/src/components/views/globals/MatrixToolbar.js b/src/components/views/globals/MatrixToolbar.js index aabf0810f8..ac449c39d7 100644 --- a/src/components/views/globals/MatrixToolbar.js +++ b/src/components/views/globals/MatrixToolbar.js @@ -20,7 +20,7 @@ import { _t } from '../../../languageHandler'; import Notifier from '../../../Notifier'; import AccessibleButton from '../../../components/views/elements/AccessibleButton'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'MatrixToolbar', hideToolbar: function() { diff --git a/src/components/views/groups/GroupMemberInfo.js b/src/components/views/groups/GroupMemberInfo.js index 2dd98f8160..e7516608c1 100644 --- a/src/components/views/groups/GroupMemberInfo.js +++ b/src/components/views/groups/GroupMemberInfo.js @@ -1,6 +1,7 @@ /* Copyright 2017 Vector Creations Ltd Copyright 2017 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. @@ -27,7 +28,7 @@ import { GroupMemberType } from '../../../groups'; import GroupStore from '../../../stores/GroupStore'; import AccessibleButton from '../elements/AccessibleButton'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'GroupMemberInfo', contextTypes: { diff --git a/src/components/views/groups/GroupRoomInfo.js b/src/components/views/groups/GroupRoomInfo.js index 42d8d89c69..63891a69f7 100644 --- a/src/components/views/groups/GroupRoomInfo.js +++ b/src/components/views/groups/GroupRoomInfo.js @@ -1,5 +1,6 @@ /* Copyright 2017 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. @@ -24,7 +25,7 @@ import * as sdk from '../../../index'; import { _t } from '../../../languageHandler'; import GroupStore from '../../../stores/GroupStore'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'GroupRoomInfo', contextTypes: { diff --git a/src/components/views/messages/MFileBody.js b/src/components/views/messages/MFileBody.js index 2177b110a5..3d93391d24 100644 --- a/src/components/views/messages/MFileBody.js +++ b/src/components/views/messages/MFileBody.js @@ -194,7 +194,7 @@ function computedStyle(element) { return cssText; } -module.exports = createReactClass({ +export default createReactClass({ displayName: 'MFileBody', getInitialState: function() { diff --git a/src/components/views/messages/MVideoBody.js b/src/components/views/messages/MVideoBody.js index dfbe632e1c..03f345e042 100644 --- a/src/components/views/messages/MVideoBody.js +++ b/src/components/views/messages/MVideoBody.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. @@ -23,7 +24,7 @@ import { decryptFile } from '../../../utils/DecryptFile'; import { _t } from '../../../languageHandler'; import SettingsStore from "../../../settings/SettingsStore"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'MVideoBody', propTypes: { diff --git a/src/components/views/messages/MessageEvent.js b/src/components/views/messages/MessageEvent.js index eae6b6f3e3..604cd19c93 100644 --- a/src/components/views/messages/MessageEvent.js +++ b/src/components/views/messages/MessageEvent.js @@ -21,7 +21,7 @@ import * as sdk from '../../../index'; import SettingsStore from "../../../settings/SettingsStore"; import {Mjolnir} from "../../../mjolnir/Mjolnir"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'MessageEvent', propTypes: { diff --git a/src/components/views/messages/RoomAvatarEvent.js b/src/components/views/messages/RoomAvatarEvent.js index 4ba7083bd2..78df6aa4a8 100644 --- a/src/components/views/messages/RoomAvatarEvent.js +++ b/src/components/views/messages/RoomAvatarEvent.js @@ -1,6 +1,7 @@ /* Copyright 2017 Vector Creations Ltd Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> +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. @@ -24,7 +25,7 @@ import * as sdk from '../../../index'; import Modal from '../../../Modal'; import AccessibleButton from '../elements/AccessibleButton'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomAvatarEvent', propTypes: { diff --git a/src/components/views/messages/RoomCreate.js b/src/components/views/messages/RoomCreate.js index 65539da785..b5749ced97 100644 --- a/src/components/views/messages/RoomCreate.js +++ b/src/components/views/messages/RoomCreate.js @@ -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. @@ -23,7 +24,7 @@ import { RoomPermalinkCreator } from '../../../utils/permalinks/Permalinks'; import { _t } from '../../../languageHandler'; import {MatrixClientPeg} from '../../../MatrixClientPeg'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomCreate', propTypes: { diff --git a/src/components/views/messages/TextualBody.js b/src/components/views/messages/TextualBody.js index a5697712ab..cf7a537166 100644 --- a/src/components/views/messages/TextualBody.js +++ b/src/components/views/messages/TextualBody.js @@ -35,7 +35,7 @@ import {IntegrationManagers} from "../../../integrations/IntegrationManagers"; import {isPermalinkHost} from "../../../utils/permalinks/Permalinks"; import {toRightOf} from "../../structures/ContextMenu"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'TextualBody', propTypes: { diff --git a/src/components/views/messages/TextualEvent.js b/src/components/views/messages/TextualEvent.js index ed63419029..1f48516f75 100644 --- a/src/components/views/messages/TextualEvent.js +++ b/src/components/views/messages/TextualEvent.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. @@ -19,7 +20,7 @@ import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; import * as TextForEvent from "../../../TextForEvent"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'TextualEvent', propTypes: { diff --git a/src/components/views/messages/UnknownBody.js b/src/components/views/messages/UnknownBody.js index ed2306de4f..2a19f324e8 100644 --- a/src/components/views/messages/UnknownBody.js +++ b/src/components/views/messages/UnknownBody.js @@ -18,7 +18,7 @@ import React from 'react'; import createReactClass from 'create-react-class'; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'UnknownBody', render: function() { diff --git a/src/components/views/room_settings/ColorSettings.js b/src/components/views/room_settings/ColorSettings.js index 952c49828b..1e06da0cd8 100644 --- a/src/components/views/room_settings/ColorSettings.js +++ b/src/components/views/room_settings/ColorSettings.js @@ -40,7 +40,7 @@ const ROOM_COLORS = [ // has a high possibility of being used in the nearish future. // Ref: https://github.com/vector-im/riot-web/issues/8421 -module.exports = createReactClass({ +export default createReactClass({ displayName: 'ColorSettings', propTypes: { diff --git a/src/components/views/room_settings/UrlPreviewSettings.js b/src/components/views/room_settings/UrlPreviewSettings.js index 7e94ccad09..5de355ebd7 100644 --- a/src/components/views/room_settings/UrlPreviewSettings.js +++ b/src/components/views/room_settings/UrlPreviewSettings.js @@ -1,7 +1,8 @@ /* Copyright 2016 OpenMarket Ltd Copyright 2017 Travis Ralston -Copyright 2018-2019 New Vector Ltd +Copyright 2018, 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. @@ -26,7 +27,7 @@ import dis from "../../../dispatcher"; import {MatrixClientPeg} from "../../../MatrixClientPeg"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'UrlPreviewSettings', propTypes: { diff --git a/src/components/views/rooms/AppsDrawer.js b/src/components/views/rooms/AppsDrawer.js index d73fb633a0..f81a5630a4 100644 --- a/src/components/views/rooms/AppsDrawer.js +++ b/src/components/views/rooms/AppsDrawer.js @@ -34,7 +34,7 @@ import SettingsStore from "../../../settings/SettingsStore"; // The maximum number of widgets that can be added in a room const MAX_WIDGETS = 2; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'AppsDrawer', propTypes: { diff --git a/src/components/views/rooms/AuxPanel.js b/src/components/views/rooms/AuxPanel.js index 297e64b152..50b25cb96f 100644 --- a/src/components/views/rooms/AuxPanel.js +++ b/src/components/views/rooms/AuxPanel.js @@ -29,7 +29,7 @@ import RateLimitedFunc from '../../../ratelimitedfunc'; import SettingsStore from "../../../settings/SettingsStore"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'AuxPanel', propTypes: { diff --git a/src/components/views/rooms/EventTile.js b/src/components/views/rooms/EventTile.js index de3af77946..73b2877775 100644 --- a/src/components/views/rooms/EventTile.js +++ b/src/components/views/rooms/EventTile.js @@ -71,7 +71,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, @@ -114,7 +114,7 @@ const MAX_READ_AVATARS = 5; // | '--------------------------------------' | // '----------------------------------------------------------' -module.exports = createReactClass({ +export default createReactClass({ displayName: 'EventTile', propTypes: { @@ -875,7 +875,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; @@ -891,7 +891,7 @@ module.exports.haveTileForEvent = function(e) { } else { return true; } -}; +} function E2ePadlockUndecryptable(props) { return ( @@ -960,5 +960,3 @@ class E2ePadlock extends React.Component { ); } } - -module.exports.getHandlerTile = getHandlerTile; diff --git a/src/components/views/rooms/ForwardMessage.js b/src/components/views/rooms/ForwardMessage.js index 4a6c560d2c..7e48071fe5 100644 --- a/src/components/views/rooms/ForwardMessage.js +++ b/src/components/views/rooms/ForwardMessage.js @@ -23,7 +23,7 @@ import dis from '../../../dispatcher'; import { KeyCode } from '../../../Keyboard'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'ForwardMessage', propTypes: { diff --git a/src/components/views/rooms/LinkPreviewWidget.js b/src/components/views/rooms/LinkPreviewWidget.js index f0b51ff299..548c722630 100644 --- a/src/components/views/rooms/LinkPreviewWidget.js +++ b/src/components/views/rooms/LinkPreviewWidget.js @@ -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. @@ -24,7 +25,7 @@ import * as sdk from "../../../index"; import Modal from "../../../Modal"; import * as ImageUtils from "../../../ImageUtils"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'LinkPreviewWidget', propTypes: { diff --git a/src/components/views/rooms/MemberInfo.js b/src/components/views/rooms/MemberInfo.js index f2e85369c4..2e7966e7aa 100644 --- a/src/components/views/rooms/MemberInfo.js +++ b/src/components/views/rooms/MemberInfo.js @@ -50,7 +50,7 @@ import AutoHideScrollbar from "../../structures/AutoHideScrollbar"; import {MatrixClientPeg} from "../../../MatrixClientPeg"; import {EventTimeline} from "matrix-js-sdk"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'MemberInfo', propTypes: { diff --git a/src/components/views/rooms/MemberList.js b/src/components/views/rooms/MemberList.js index 7d47bdb4b8..32025187d1 100644 --- a/src/components/views/rooms/MemberList.js +++ b/src/components/views/rooms/MemberList.js @@ -32,7 +32,7 @@ const INITIAL_LOAD_NUM_MEMBERS = 30; const INITIAL_LOAD_NUM_INVITED = 5; const SHOW_MORE_INCREMENT = 100; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'MemberList', getInitialState: function() { diff --git a/src/components/views/rooms/MemberTile.js b/src/components/views/rooms/MemberTile.js index c992b9d4f3..95e5495339 100644 --- a/src/components/views/rooms/MemberTile.js +++ b/src/components/views/rooms/MemberTile.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. @@ -22,7 +23,7 @@ import * as sdk from "../../../index"; import dis from "../../../dispatcher"; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'MemberTile', propTypes: { diff --git a/src/components/views/rooms/PinnedEventTile.js b/src/components/views/rooms/PinnedEventTile.js index d2715c3e63..28fc8fc338 100644 --- a/src/components/views/rooms/PinnedEventTile.js +++ b/src/components/views/rooms/PinnedEventTile.js @@ -25,7 +25,7 @@ import MemberAvatar from "../avatars/MemberAvatar"; import { _t } from '../../../languageHandler'; import {formatFullDate} from '../../../DateUtils'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'PinnedEventTile', propTypes: { mxRoom: PropTypes.object.isRequired, diff --git a/src/components/views/rooms/PinnedEventsPanel.js b/src/components/views/rooms/PinnedEventsPanel.js index e06e8f95a0..8630c0340e 100644 --- a/src/components/views/rooms/PinnedEventsPanel.js +++ b/src/components/views/rooms/PinnedEventsPanel.js @@ -1,5 +1,6 @@ /* Copyright 2017 Travis Ralston +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. @@ -23,7 +24,7 @@ import PinnedEventTile from "./PinnedEventTile"; import { _t } from '../../../languageHandler'; import PinningUtils from "../../../utils/PinningUtils"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'PinnedEventsPanel', propTypes: { // The Room from the js-sdk we're going to show pinned events for diff --git a/src/components/views/rooms/PresenceLabel.js b/src/components/views/rooms/PresenceLabel.js index 5cb34b473f..f9dcd7e89d 100644 --- a/src/components/views/rooms/PresenceLabel.js +++ b/src/components/views/rooms/PresenceLabel.js @@ -21,7 +21,7 @@ import createReactClass from 'create-react-class'; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'PresenceLabel', propTypes: { diff --git a/src/components/views/rooms/ReadReceiptMarker.js b/src/components/views/rooms/ReadReceiptMarker.js index d8ce58342a..5c80fbb737 100644 --- a/src/components/views/rooms/ReadReceiptMarker.js +++ b/src/components/views/rooms/ReadReceiptMarker.js @@ -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. @@ -32,7 +33,7 @@ try { } catch (e) { } -module.exports = createReactClass({ +export default createReactClass({ displayName: 'ReadReceiptMarker', propTypes: { diff --git a/src/components/views/rooms/RoomDropTarget.js b/src/components/views/rooms/RoomDropTarget.js index 1012b23105..61b7ca6d59 100644 --- a/src/components/views/rooms/RoomDropTarget.js +++ b/src/components/views/rooms/RoomDropTarget.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. @@ -17,7 +18,7 @@ limitations under the License. import React from 'react'; import createReactClass from 'create-react-class'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomDropTarget', render: function() { diff --git a/src/components/views/rooms/RoomHeader.js b/src/components/views/rooms/RoomHeader.js index 4c1452a29c..1b5ff164f1 100644 --- a/src/components/views/rooms/RoomHeader.js +++ b/src/components/views/rooms/RoomHeader.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. @@ -32,7 +33,7 @@ import SettingsStore from "../../../settings/SettingsStore"; import RoomHeaderButtons from '../right_panel/RoomHeaderButtons'; import E2EIcon from './E2EIcon'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomHeader', propTypes: { diff --git a/src/components/views/rooms/RoomList.js b/src/components/views/rooms/RoomList.js index ab15ab5a83..dd9258f1bf 100644 --- a/src/components/views/rooms/RoomList.js +++ b/src/components/views/rooms/RoomList.js @@ -48,7 +48,7 @@ function labelForTagName(tagName) { return tagName; } -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomList', propTypes: { diff --git a/src/components/views/rooms/RoomNameEditor.js b/src/components/views/rooms/RoomNameEditor.js index 0789da2724..b65d89ee6f 100644 --- a/src/components/views/rooms/RoomNameEditor.js +++ b/src/components/views/rooms/RoomNameEditor.js @@ -21,7 +21,7 @@ import {MatrixClientPeg} from "../../../MatrixClientPeg"; import * as sdk from "../../../index"; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomNameEditor', propTypes: { diff --git a/src/components/views/rooms/RoomPreviewBar.js b/src/components/views/rooms/RoomPreviewBar.js index 04139aa93d..cbc992d67f 100644 --- a/src/components/views/rooms/RoomPreviewBar.js +++ b/src/components/views/rooms/RoomPreviewBar.js @@ -43,7 +43,7 @@ const MessageCase = Object.freeze({ OtherError: "OtherError", }); -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomPreviewBar', propTypes: { diff --git a/src/components/views/rooms/RoomTile.js b/src/components/views/rooms/RoomTile.js index 10ed397727..16db17a9b7 100644 --- a/src/components/views/rooms/RoomTile.js +++ b/src/components/views/rooms/RoomTile.js @@ -33,7 +33,7 @@ import RoomViewStore from '../../../stores/RoomViewStore'; import SettingsStore from "../../../settings/SettingsStore"; import {_t} from "../../../languageHandler"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomTile', propTypes: { diff --git a/src/components/views/rooms/RoomTopicEditor.js b/src/components/views/rooms/RoomTopicEditor.js index ed55b66a9a..5decce02a9 100644 --- a/src/components/views/rooms/RoomTopicEditor.js +++ b/src/components/views/rooms/RoomTopicEditor.js @@ -20,7 +20,7 @@ import createReactClass from 'create-react-class'; import * as sdk from '../../../index'; import { _t } from "../../../languageHandler"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomTopicEditor', propTypes: { diff --git a/src/components/views/rooms/RoomUpgradeWarningBar.js b/src/components/views/rooms/RoomUpgradeWarningBar.js index dae5dbfa43..1240900e28 100644 --- a/src/components/views/rooms/RoomUpgradeWarningBar.js +++ b/src/components/views/rooms/RoomUpgradeWarningBar.js @@ -23,7 +23,7 @@ import Modal from '../../../Modal'; import { _t } from '../../../languageHandler'; import {MatrixClientPeg} from "../../../MatrixClientPeg"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'RoomUpgradeWarningBar', propTypes: { diff --git a/src/components/views/rooms/SearchBar.js b/src/components/views/rooms/SearchBar.js index c9a9308544..e89a5c72c1 100644 --- a/src/components/views/rooms/SearchBar.js +++ b/src/components/views/rooms/SearchBar.js @@ -20,7 +20,7 @@ import AccessibleButton from "../elements/AccessibleButton"; import classNames from "classnames"; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'SearchBar', getInitialState: function() { diff --git a/src/components/views/rooms/SearchResultTile.js b/src/components/views/rooms/SearchResultTile.js index 084d4baffc..bf34a56de3 100644 --- a/src/components/views/rooms/SearchResultTile.js +++ b/src/components/views/rooms/SearchResultTile.js @@ -1,5 +1,6 @@ /* Copyright 2015 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. @@ -19,7 +20,7 @@ import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; import * as sdk from '../../../index'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'SearchResult', propTypes: { diff --git a/src/components/views/rooms/SearchableEntityList.js b/src/components/views/rooms/SearchableEntityList.js index 0bd21635ba..807ddbf729 100644 --- a/src/components/views/rooms/SearchableEntityList.js +++ b/src/components/views/rooms/SearchableEntityList.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. @@ -182,4 +183,4 @@ const SearchableEntityList = createReactClass({ }, }); - module.exports = SearchableEntityList; +export default SearchableEntityList; diff --git a/src/components/views/rooms/TopUnreadMessagesBar.js b/src/components/views/rooms/TopUnreadMessagesBar.js index c7a1a22580..04805c799f 100644 --- a/src/components/views/rooms/TopUnreadMessagesBar.js +++ b/src/components/views/rooms/TopUnreadMessagesBar.js @@ -22,7 +22,7 @@ import createReactClass from 'create-react-class'; import { _t } from '../../../languageHandler'; import AccessibleButton from '../elements/AccessibleButton'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'TopUnreadMessagesBar', propTypes: { diff --git a/src/components/views/rooms/UserTile.js b/src/components/views/rooms/UserTile.js index 9fea1a3ad2..01bbe7d4d1 100644 --- a/src/components/views/rooms/UserTile.js +++ b/src/components/views/rooms/UserTile.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. @@ -20,7 +21,7 @@ import createReactClass from 'create-react-class'; import * as Avatar from '../../../Avatar'; import * as sdk from "../../../index"; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'UserTile', propTypes: { diff --git a/src/components/views/rooms/WhoIsTypingTile.js b/src/components/views/rooms/WhoIsTypingTile.js index 439ed67e40..e6ffb24621 100644 --- a/src/components/views/rooms/WhoIsTypingTile.js +++ b/src/components/views/rooms/WhoIsTypingTile.js @@ -23,7 +23,7 @@ import Timer from '../../../utils/Timer'; import {MatrixClientPeg} from '../../../MatrixClientPeg'; import MemberAvatar from '../avatars/MemberAvatar'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'WhoIsTypingTile', propTypes: { diff --git a/src/components/views/settings/ChangeAvatar.js b/src/components/views/settings/ChangeAvatar.js index 7d088d9a40..5b6b6ae3de 100644 --- a/src/components/views/settings/ChangeAvatar.js +++ b/src/components/views/settings/ChangeAvatar.js @@ -21,7 +21,7 @@ import {MatrixClientPeg} from "../../../MatrixClientPeg"; import * as sdk from '../../../index'; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'ChangeAvatar', propTypes: { initialAvatarUrl: PropTypes.string, diff --git a/src/components/views/settings/ChangeDisplayName.js b/src/components/views/settings/ChangeDisplayName.js index 846fac6a6c..fdc55a4f52 100644 --- a/src/components/views/settings/ChangeDisplayName.js +++ b/src/components/views/settings/ChangeDisplayName.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd 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. @@ -21,7 +22,7 @@ import * as sdk from '../../../index'; import {MatrixClientPeg} from '../../../MatrixClientPeg'; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'ChangeDisplayName', _getDisplayName: async function() { diff --git a/src/components/views/settings/ChangePassword.js b/src/components/views/settings/ChangePassword.js index dc41e5e2c8..2d8c4c4178 100644 --- a/src/components/views/settings/ChangePassword.js +++ b/src/components/views/settings/ChangePassword.js @@ -28,7 +28,7 @@ import Modal from "../../../Modal"; import sessionStore from '../../../stores/SessionStore'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'ChangePassword', propTypes: { diff --git a/src/components/views/settings/EnableNotificationsButton.js b/src/components/views/settings/EnableNotificationsButton.js index 1f65c39e6e..9ca591f30e 100644 --- a/src/components/views/settings/EnableNotificationsButton.js +++ b/src/components/views/settings/EnableNotificationsButton.js @@ -20,7 +20,7 @@ import Notifier from "../../../Notifier"; import dis from "../../../dispatcher"; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'EnableNotificationsButton', componentDidMount: function() { diff --git a/src/components/views/settings/Notifications.js b/src/components/views/settings/Notifications.js index f3448f7bb5..3bad8ba2bd 100644 --- a/src/components/views/settings/Notifications.js +++ b/src/components/views/settings/Notifications.js @@ -63,7 +63,7 @@ function portLegacyActions(actions) { } } -module.exports = createReactClass({ +export default createReactClass({ displayName: 'Notifications', phases: { diff --git a/src/components/views/voip/CallPreview.js b/src/components/views/voip/CallPreview.js index 24bc29515a..57bf35a719 100644 --- a/src/components/views/voip/CallPreview.js +++ b/src/components/views/voip/CallPreview.js @@ -1,5 +1,6 @@ /* Copyright 2017, 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. @@ -22,7 +23,7 @@ import CallHandler from '../../../CallHandler'; import dis from '../../../dispatcher'; import * as sdk from '../../../index'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'CallPreview', propTypes: { diff --git a/src/components/views/voip/CallView.js b/src/components/views/voip/CallView.js index 5b3b198472..70d7963bcb 100644 --- a/src/components/views/voip/CallView.js +++ b/src/components/views/voip/CallView.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. @@ -22,7 +23,7 @@ import * as sdk from '../../../index'; import {MatrixClientPeg} from '../../../MatrixClientPeg'; import { _t } from '../../../languageHandler'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'CallView', propTypes: { diff --git a/src/components/views/voip/IncomingCallBox.js b/src/components/views/voip/IncomingCallBox.js index 4304cac912..53e829b784 100644 --- a/src/components/views/voip/IncomingCallBox.js +++ b/src/components/views/voip/IncomingCallBox.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd 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. @@ -22,7 +23,7 @@ import dis from '../../../dispatcher'; import { _t } from '../../../languageHandler'; import * as sdk from '../../../index'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'IncomingCallBox', propTypes: { diff --git a/src/components/views/voip/VideoFeed.js b/src/components/views/voip/VideoFeed.js index 0faa227088..4210c60177 100644 --- a/src/components/views/voip/VideoFeed.js +++ b/src/components/views/voip/VideoFeed.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. @@ -18,7 +19,7 @@ import React, {createRef} from 'react'; import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; -module.exports = createReactClass({ +export default createReactClass({ displayName: 'VideoFeed', propTypes: { diff --git a/src/components/views/voip/VideoView.js b/src/components/views/voip/VideoView.js index fbb49ed367..eabf29813a 100644 --- a/src/components/views/voip/VideoView.js +++ b/src/components/views/voip/VideoView.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. @@ -34,7 +35,7 @@ function getFullScreenElement() { ); } -module.exports = createReactClass({ +export default createReactClass({ displayName: 'VideoView', propTypes: { diff --git a/src/createRoom.js b/src/createRoom.js index ac943663ff..867d6409eb 100644 --- a/src/createRoom.js +++ b/src/createRoom.js @@ -35,7 +35,7 @@ import {getAddressType} from "./UserAddress"; * @returns {Promise} which resolves to the room id, or null if the * action was aborted or failed. */ -function createRoom(opts) { +export default function createRoom(opts) { opts = opts || {}; if (opts.spinner === undefined) opts.spinner = true; @@ -139,5 +139,3 @@ function createRoom(opts) { return null; }); } - -module.exports = createRoom; diff --git a/src/dispatcher.js b/src/dispatcher.js index 5abdb29604..5dfaa11345 100644 --- a/src/dispatcher.js +++ b/src/dispatcher.js @@ -55,4 +55,4 @@ class MatrixDispatcher extends flux.Dispatcher { if (global.mxDispatcher === undefined) { global.mxDispatcher = new MatrixDispatcher(); } -module.exports = global.mxDispatcher; +export default global.mxDispatcher; diff --git a/src/email.js b/src/email.js index 3fd535c849..6e2ed69bb7 100644 --- a/src/email.js +++ b/src/email.js @@ -16,8 +16,6 @@ limitations under the License. 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); - }, -}; +export function looksValid(email) { + return EMAIL_ADDRESS_REGEX.test(email); +} diff --git a/src/extend.js b/src/extend.js index 4b3f028a94..263d802ab6 100644 --- a/src/extend.js +++ b/src/extend.js @@ -16,11 +16,11 @@ limitations under the License. 'use strict'; -module.exports = function(dest, src) { +export default function(dest, src) { for (const i in src) { if (src.hasOwnProperty(i)) { dest[i] = src[i]; } } return dest; -}; +} diff --git a/src/index.js b/src/index.js index 7d0547d9c9..008e15ad90 100644 --- a/src/index.js +++ b/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); -}; +} diff --git a/src/indexing/EventIndexPeg.js b/src/indexing/EventIndexPeg.js index 75f0fa66ba..3746591b1f 100644 --- a/src/indexing/EventIndexPeg.js +++ b/src/indexing/EventIndexPeg.js @@ -110,4 +110,4 @@ class EventIndexPeg { if (!global.mxEventIndexPeg) { global.mxEventIndexPeg = new EventIndexPeg(); } -module.exports = global.mxEventIndexPeg; +export default global.mxEventIndexPeg; diff --git a/src/notifications/ContentRules.js b/src/notifications/ContentRules.js index f7e722dbfe..8c285220c7 100644 --- a/src/notifications/ContentRules.js +++ b/src/notifications/ContentRules.js @@ -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. @@ -16,9 +17,9 @@ limitations under the License. 'use strict'; -const PushRuleVectorState = require('./PushRuleVectorState'); +import {PushRuleVectorState} from "./PushRuleVectorState"; -module.exports = { +export class ContentRules { /** * Extract the keyword rules from a list of rules, and parse them * into a form which is useful for Vector's UI. @@ -30,7 +31,7 @@ module.exports = { * externalRules: a list of other keyword rules, with states other than * vectorState */ - parseContentRules: function(rulesets) { + static parseContentRules(rulesets) { // first categorise the keyword rules in terms of their actions const contentRules = this._categoriseContentRules(rulesets); @@ -79,9 +80,9 @@ module.exports = { externalRules: contentRules.other, }; } - }, + } - _categoriseContentRules: function(rulesets) { + static _categoriseContentRules(rulesets) { const contentRules = {on: [], on_but_disabled: [], loud: [], loud_but_disabled: [], other: []}; for (const kind in rulesets.global) { for (let i = 0; i < Object.keys(rulesets.global[kind]).length; ++i) { @@ -116,5 +117,5 @@ module.exports = { } } return contentRules; - }, -}; + } +} diff --git a/src/notifications/NotificationUtils.js b/src/notifications/NotificationUtils.js index 79c1b38f6d..bf393da060 100644 --- a/src/notifications/NotificationUtils.js +++ b/src/notifications/NotificationUtils.js @@ -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. @@ -16,14 +17,14 @@ limitations under the License. 'use strict'; -module.exports = { +export class NotificationUtils { // Encodes a dictionary of { // "notify": true/false, // "sound": string or undefined, // "highlight: true/false, // } // to a list of push actions. - encodeActions: function(action) { + static encodeActions(action) { const notify = action.notify; const sound = action.sound; const highlight = action.highlight; @@ -41,7 +42,7 @@ module.exports = { } else { return ["dont_notify"]; } - }, + } // Decode a list of actions to a dictionary of { // "notify": true/false, @@ -49,7 +50,7 @@ module.exports = { // "highlight: true/false, // } // If the actions couldn't be decoded then returns null. - decodeActions: function(actions) { + static decodeActions(actions) { let notify = false; let sound = null; let highlight = false; @@ -85,5 +86,5 @@ module.exports = { result.sound = sound; } return result; - }, -}; + } +} diff --git a/src/notifications/PushRuleVectorState.js b/src/notifications/PushRuleVectorState.js index f4ba365b6d..263226ce1c 100644 --- a/src/notifications/PushRuleVectorState.js +++ b/src/notifications/PushRuleVectorState.js @@ -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. @@ -16,42 +17,44 @@ limitations under the License. 'use strict'; -const StandardActions = require('./StandardActions'); -const NotificationUtils = require('./NotificationUtils'); +import {StandardActions} from "./StandardActions"; +import {NotificationUtils} from "./NotificationUtils"; -const states = { - /** The push rule is disabled */ - OFF: "off", +export class PushRuleVectorState { + // Backwards compatibility (things should probably be using .states instead) + static OFF = "off"; + static ON = "on"; + static LOUD = "loud"; - /** The user will receive push notification for this rule */ - ON: "on", - - /** The user will receive push notification for this rule with sound and - highlight if this is legitimate */ - LOUD: "loud", -}; - - -module.exports = { /** * Enum for state of a push rule as defined by the Vector UI. * @readonly * @enum {string} */ - states: states, + static states = { + /** The push rule is disabled */ + OFF: PushRuleVectorState.OFF, + + /** The user will receive push notification for this rule */ + ON: PushRuleVectorState.ON, + + /** The user will receive push notification for this rule with sound and + highlight if this is legitimate */ + LOUD: PushRuleVectorState.LOUD, + }; /** * Convert a PushRuleVectorState to a list of actions * * @return [object] list of push-rule actions */ - actionsFor: function(pushRuleVectorState) { - if (pushRuleVectorState === this.ON) { + static actionsFor(pushRuleVectorState) { + if (pushRuleVectorState === PushRuleVectorState.ON) { return StandardActions.ACTION_NOTIFY; - } else if (pushRuleVectorState === this.LOUD) { + } else if (pushRuleVectorState === PushRuleVectorState.LOUD) { return StandardActions.ACTION_HIGHLIGHT_DEFAULT_SOUND; } - }, + } /** * Convert a pushrule's actions to a PushRuleVectorState. @@ -60,7 +63,7 @@ module.exports = { * category or in PushRuleVectorState.LOUD, regardless of its enabled * state. Returns null if it does not match these categories. */ - contentRuleVectorStateKind: function(rule) { + static contentRuleVectorStateKind(rule) { const decoded = NotificationUtils.decodeActions(rule.actions); if (!decoded) { @@ -78,16 +81,12 @@ module.exports = { let stateKind = null; switch (tweaks) { case 0: - stateKind = this.ON; + stateKind = PushRuleVectorState.ON; break; case 2: - stateKind = this.LOUD; + stateKind = PushRuleVectorState.LOUD; break; } return stateKind; - }, -}; - -for (const k in states) { - module.exports[k] = states[k]; + } } diff --git a/src/notifications/StandardActions.js b/src/notifications/StandardActions.js index 15f645d5f7..b54cea332a 100644 --- a/src/notifications/StandardActions.js +++ b/src/notifications/StandardActions.js @@ -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. @@ -16,16 +17,16 @@ limitations under the License. 'use strict'; -const NotificationUtils = require('./NotificationUtils'); +import {NotificationUtils} from "./NotificationUtils"; const encodeActions = NotificationUtils.encodeActions; -module.exports = { - ACTION_NOTIFY: encodeActions({notify: true}), - ACTION_NOTIFY_DEFAULT_SOUND: encodeActions({notify: true, sound: "default"}), - ACTION_NOTIFY_RING_SOUND: encodeActions({notify: true, sound: "ring"}), - ACTION_HIGHLIGHT: encodeActions({notify: true, highlight: true}), - ACTION_HIGHLIGHT_DEFAULT_SOUND: encodeActions({notify: true, sound: "default", highlight: true}), - ACTION_DONT_NOTIFY: encodeActions({notify: false}), - ACTION_DISABLED: null, -}; +export class StandardActions { + static ACTION_NOTIFY = encodeActions({notify: true}); + static ACTION_NOTIFY_DEFAULT_SOUND = encodeActions({notify: true, sound: "default"}); + static ACTION_NOTIFY_RING_SOUND = encodeActions({notify: true, sound: "ring"}); + static ACTION_HIGHLIGHT = encodeActions({notify: true, highlight: true}); + static ACTION_HIGHLIGHT_DEFAULT_SOUND = encodeActions({notify: true, sound: "default", highlight: true}); + static ACTION_DONT_NOTIFY = encodeActions({notify: false}); + static ACTION_DISABLED = null; +} diff --git a/src/notifications/VectorPushRulesDefinitions.js b/src/notifications/VectorPushRulesDefinitions.js index b15fb4ccd7..98d197a004 100644 --- a/src/notifications/VectorPushRulesDefinitions.js +++ b/src/notifications/VectorPushRulesDefinitions.js @@ -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. @@ -17,10 +18,9 @@ limitations under the License. 'use strict'; import { _td } from '../languageHandler'; - -const StandardActions = require('./StandardActions'); -const PushRuleVectorState = require('./PushRuleVectorState'); -const { decodeActions } = require('./NotificationUtils'); +import {StandardActions} from "./StandardActions"; +import {PushRuleVectorState} from "./PushRuleVectorState"; +import {NotificationUtils} from "./NotificationUtils"; class VectorPushRuleDefinition { constructor(opts) { @@ -51,8 +51,8 @@ class VectorPushRuleDefinition { // value: true vs. unspecified for highlight (which defaults to // true, making them equivalent). if (enabled && - JSON.stringify(decodeActions(rule.actions)) === - JSON.stringify(decodeActions(vectorStateToActions))) { + JSON.stringify(NotificationUtils.decodeActions(rule.actions)) === + JSON.stringify(NotificationUtils.decodeActions(vectorStateToActions))) { return state; } } @@ -68,7 +68,7 @@ class VectorPushRuleDefinition { /** * The descriptions of rules managed by the Vector UI. */ -module.exports = { +export const VectorPushRulesDefinitions = { // Messages containing user's display name ".m.rule.contains_display_name": new VectorPushRuleDefinition({ kind: "override", diff --git a/src/notifications/index.js b/src/notifications/index.js index 8ed77e9d41..7c400ad8b3 100644 --- a/src/notifications/index.js +++ b/src/notifications/index.js @@ -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. @@ -16,9 +17,7 @@ limitations under the License. 'use strict'; -module.exports = { - NotificationUtils: require('./NotificationUtils'), - PushRuleVectorState: require('./PushRuleVectorState'), - VectorPushRulesDefinitions: require('./VectorPushRulesDefinitions'), - ContentRules: require('./ContentRules'), -}; +export * from "./NotificationUtils"; +export * from "./PushRuleVectorState"; +export * from "./VectorPushRulesDefinitions"; +export * from "./ContentRules"; diff --git a/src/rageshake/rageshake.js b/src/rageshake/rageshake.js index 47bab38079..a9d17e77c9 100644 --- a/src/rageshake/rageshake.js +++ b/src/rageshake/rageshake.js @@ -432,77 +432,73 @@ function selectQuery(store, keyRange, resultMapper) { }); } - -module.exports = { - - /** - * Configure rage shaking support for sending bug reports. - * Modifies globals. - * @return {Promise} Resolves when set up. - */ - init: function() { - if (global.mx_rage_initPromise) { - return global.mx_rage_initPromise; - } - global.mx_rage_logger = new ConsoleLogger(); - global.mx_rage_logger.monkeyPatch(window.console); - - // just *accessing* indexedDB throws an exception in firefox with - // indexeddb disabled. - let indexedDB; - try { - indexedDB = window.indexedDB; - } catch (e) {} - - if (indexedDB) { - global.mx_rage_store = new IndexedDBLogStore(indexedDB, global.mx_rage_logger); - global.mx_rage_initPromise = global.mx_rage_store.connect(); - return global.mx_rage_initPromise; - } - global.mx_rage_initPromise = Promise.resolve(); +/** + * Configure rage shaking support for sending bug reports. + * Modifies globals. + * @return {Promise} Resolves when set up. + */ +export function init() { + if (global.mx_rage_initPromise) { return global.mx_rage_initPromise; - }, + } + global.mx_rage_logger = new ConsoleLogger(); + global.mx_rage_logger.monkeyPatch(window.console); - flush: function() { - if (!global.mx_rage_store) { - return; - } - global.mx_rage_store.flush(); - }, + // just *accessing* indexedDB throws an exception in firefox with + // indexeddb disabled. + let indexedDB; + try { + indexedDB = window.indexedDB; + } catch (e) {} - /** - * Clean up old logs. - * @return Promise Resolves if cleaned logs. - */ - cleanup: async function() { - if (!global.mx_rage_store) { - return; - } - await global.mx_rage_store.consume(); - }, + if (indexedDB) { + global.mx_rage_store = new IndexedDBLogStore(indexedDB, global.mx_rage_logger); + global.mx_rage_initPromise = global.mx_rage_store.connect(); + return global.mx_rage_initPromise; + } + global.mx_rage_initPromise = Promise.resolve(); + return global.mx_rage_initPromise; +} - /** - * Get a recent snapshot of the logs, ready for attaching to a bug report - * - * @return {Array<{lines: string, id, string}>} list of log data - */ - getLogsForReport: async function() { - if (!global.mx_rage_logger) { - throw new Error( - "No console logger, did you forget to call init()?", - ); - } - // If in incognito mode, store is null, but we still want bug report - // sending to work going off the in-memory console logs. - if (global.mx_rage_store) { - // flush most recent logs - await global.mx_rage_store.flush(); - return await global.mx_rage_store.consume(); - } else { - return [{ - lines: global.mx_rage_logger.flush(true), - id: "-", - }]; - } - }, -}; +export function flush() { + if (!global.mx_rage_store) { + return; + } + global.mx_rage_store.flush(); +} + +/** + * Clean up old logs. + * @return Promise Resolves if cleaned logs. + */ +export async function cleanup() { + if (!global.mx_rage_store) { + return; + } + await global.mx_rage_store.consume(); +} + +/** + * Get a recent snapshot of the logs, ready for attaching to a bug report + * + * @return {Array<{lines: string, id, string}>} list of log data + */ +export async function getLogsForReport() { + if (!global.mx_rage_logger) { + throw new Error( + "No console logger, did you forget to call init()?", + ); + } + // If in incognito mode, store is null, but we still want bug report + // sending to work going off the in-memory console logs. + if (global.mx_rage_store) { + // flush most recent logs + await global.mx_rage_store.flush(); + return await global.mx_rage_store.consume(); + } else { + return [{ + lines: global.mx_rage_logger.flush(true), + id: "-", + }]; + } +} diff --git a/src/rageshake/submit-rageshake.js b/src/rageshake/submit-rageshake.js index 019da10d52..2c1dd7e16f 100644 --- a/src/rageshake/submit-rageshake.js +++ b/src/rageshake/submit-rageshake.js @@ -22,7 +22,7 @@ import {MatrixClientPeg} from '../MatrixClientPeg'; import PlatformPeg from '../PlatformPeg'; import { _t } from '../languageHandler'; -import rageshake from './rageshake'; +import * as rageshake from './rageshake'; // polyfill textencoder if necessary diff --git a/src/resizer/index.js b/src/resizer/index.js index bc4c8f388c..7c4b2bd493 100644 --- a/src/resizer/index.js +++ b/src/resizer/index.js @@ -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,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import FixedDistributor from "./distributors/fixed"; -import CollapseDistributor from "./distributors/collapse"; -import RoomSubListDistributor from "./distributors/roomsublist"; -import Resizer from "./resizer"; - -module.exports = { - Resizer, - FixedDistributor, - CollapseDistributor, - RoomSubListDistributor, -}; +export FixedDistributor from "./distributors/fixed"; +export CollapseDistributor from "./distributors/collapse"; +export RoomSubListDistributor from "./distributors/roomsublist"; +export Resizer from "./resizer"; diff --git a/src/stores/GroupStore.js b/src/stores/GroupStore.js index f691a33e6f..6aad6aeaec 100644 --- a/src/stores/GroupStore.js +++ b/src/stores/GroupStore.js @@ -340,4 +340,4 @@ let singletonGroupStore = null; if (!singletonGroupStore) { singletonGroupStore = new GroupStore(); } -module.exports = singletonGroupStore; +export default singletonGroupStore; diff --git a/src/stores/LifecycleStore.js b/src/stores/LifecycleStore.js index 91dcf0aebb..904f29f7b3 100644 --- a/src/stores/LifecycleStore.js +++ b/src/stores/LifecycleStore.js @@ -1,6 +1,7 @@ /* Copyright 2017 Vector Creations Ltd 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. @@ -79,4 +80,4 @@ let singletonLifecycleStore = null; if (!singletonLifecycleStore) { singletonLifecycleStore = new LifecycleStore(); } -module.exports = singletonLifecycleStore; +export default singletonLifecycleStore; diff --git a/src/stores/MessageComposerStore.js b/src/stores/MessageComposerStore.js index ab2dbfedec..3c7440e10b 100644 --- a/src/stores/MessageComposerStore.js +++ b/src/stores/MessageComposerStore.js @@ -1,5 +1,6 @@ /* Copyright 2017, 2018 Vector Creations 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. @@ -63,4 +64,4 @@ let singletonMessageComposerStore = null; if (!singletonMessageComposerStore) { singletonMessageComposerStore = new MessageComposerStore(); } -module.exports = singletonMessageComposerStore; +export default singletonMessageComposerStore; diff --git a/src/stores/RoomViewStore.js b/src/stores/RoomViewStore.js index a96174234a..d9204193e4 100644 --- a/src/stores/RoomViewStore.js +++ b/src/stores/RoomViewStore.js @@ -1,6 +1,7 @@ /* Copyright 2017 Vector Creations Ltd Copyright 2017, 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. @@ -357,4 +358,4 @@ let singletonRoomViewStore = null; if (!singletonRoomViewStore) { singletonRoomViewStore = new RoomViewStore(); } -module.exports = singletonRoomViewStore; +export default singletonRoomViewStore; diff --git a/src/stores/SessionStore.js b/src/stores/SessionStore.js index ad58f1e93d..f38bc046d0 100644 --- a/src/stores/SessionStore.js +++ b/src/stores/SessionStore.js @@ -1,5 +1,6 @@ /* Copyright 2017 Vector Creations 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. @@ -86,4 +87,4 @@ let singletonSessionStore = null; if (!singletonSessionStore) { singletonSessionStore = new SessionStore(); } -module.exports = singletonSessionStore; +export default singletonSessionStore; diff --git a/src/stores/WidgetEchoStore.js b/src/stores/WidgetEchoStore.js index 0d14ed1d60..33fa45c635 100644 --- a/src/stores/WidgetEchoStore.js +++ b/src/stores/WidgetEchoStore.js @@ -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. @@ -105,4 +106,4 @@ let singletonWidgetEchoStore = null; if (!singletonWidgetEchoStore) { singletonWidgetEchoStore = new WidgetEchoStore(); } -module.exports = singletonWidgetEchoStore; +export default singletonWidgetEchoStore; diff --git a/test/components/stub-component.js b/test/components/stub-component.js index 9264792ffb..5638ada09d 100644 --- a/test/components/stub-component.js +++ b/test/components/stub-component.js @@ -4,7 +4,7 @@ import React from 'react'; import createReactClass from 'create-react-class'; -module.exports = function(opts) { +export default function(opts) { opts = opts || {}; if (!opts.displayName) { opts.displayName = 'StubComponent'; diff --git a/test/end-to-end-tests/src/logbuffer.js b/test/end-to-end-tests/src/logbuffer.js index d586dc8b84..db4be33e8d 100644 --- a/test/end-to-end-tests/src/logbuffer.js +++ b/test/end-to-end-tests/src/logbuffer.js @@ -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,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -module.exports = class LogBuffer { +export default class LogBuffer { constructor(page, eventName, eventMapper, reduceAsync=false, initialValue = "") { this.buffer = initialValue; page.on(eventName, (arg) => { diff --git a/test/end-to-end-tests/src/logger.js b/test/end-to-end-tests/src/logger.js index 283d07f163..42a9544e4d 100644 --- a/test/end-to-end-tests/src/logger.js +++ b/test/end-to-end-tests/src/logger.js @@ -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,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -module.exports = class Logger { +export default class Logger { constructor(username) { this.indent = 0; this.username = username; diff --git a/test/end-to-end-tests/src/rest/consent.js b/test/end-to-end-tests/src/rest/consent.js index 1e36f541a3..5c424cd6e8 100644 --- a/test/end-to-end-tests/src/rest/consent.js +++ b/test/end-to-end-tests/src/rest/consent.js @@ -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}); -}; +} diff --git a/test/end-to-end-tests/src/rest/creator.js b/test/end-to-end-tests/src/rest/creator.js index fde54014b2..c4ddee0581 100644 --- a/test/end-to-end-tests/src/rest/creator.js +++ b/test/end-to-end-tests/src/rest/creator.js @@ -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. @@ -31,7 +32,7 @@ function execAsync(command, options) { }); } -module.exports = class RestSessionCreator { +export default class RestSessionCreator { constructor(synapseSubdir, hsUrl, cwd) { this.synapseSubdir = synapseSubdir; this.hsUrl = hsUrl; diff --git a/test/end-to-end-tests/src/rest/multi.js b/test/end-to-end-tests/src/rest/multi.js index e58b9f3f57..d4cd5c765c 100644 --- a/test/end-to-end-tests/src/rest/multi.js +++ b/test/end-to-end-tests/src/rest/multi.js @@ -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 Logger = require('../logger'); -module.exports = class RestMultiSession { +export default class RestMultiSession { constructor(sessions, groupName) { this.log = new Logger(groupName); this.sessions = sessions; diff --git a/test/end-to-end-tests/src/rest/room.js b/test/end-to-end-tests/src/rest/room.js index 429a29c31a..b3ba725336 100644 --- a/test/end-to-end-tests/src/rest/room.js +++ b/test/end-to-end-tests/src/rest/room.js @@ -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. @@ -17,7 +18,7 @@ limitations under the License. const uuidv4 = require('uuid/v4'); /* no pun intented */ -module.exports = class RestRoom { +export default class RestRoom { constructor(session, roomId, log) { this.session = session; this._roomId = roomId; diff --git a/test/end-to-end-tests/src/rest/session.js b/test/end-to-end-tests/src/rest/session.js index 5b97824f5c..344493968c 100644 --- a/test/end-to-end-tests/src/rest/session.js +++ b/test/end-to-end-tests/src/rest/session.js @@ -19,7 +19,7 @@ const Logger = require('../logger'); const RestRoom = require('./room'); const {approveConsent} = require('./consent'); -module.exports = class RestSession { +export default class RestSession { constructor(credentials) { this.log = new Logger(credentials.userId); this._credentials = credentials; diff --git a/test/end-to-end-tests/src/scenarios/directory.js b/test/end-to-end-tests/src/scenarios/directory.js index 3ae728a5b7..cf995ae1a8 100644 --- a/test/end-to-end-tests/src/scenarios/directory.js +++ b/test/end-to-end-tests/src/scenarios/directory.js @@ -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. @@ -21,7 +22,7 @@ const {receiveMessage} = require('../usecases/timeline'); const {createRoom} = require('../usecases/create-room'); const changeRoomSettings = require('../usecases/room-settings'); -module.exports = async function roomDirectoryScenarios(alice, bob) { +export default async function roomDirectoryScenarios(alice, bob) { console.log(" creating a public room and join through directory:"); const room = 'test'; await createRoom(alice, room); diff --git a/test/end-to-end-tests/src/scenarios/e2e-encryption.js b/test/end-to-end-tests/src/scenarios/e2e-encryption.js index 8df374bacb..2a002da66b 100644 --- a/test/end-to-end-tests/src/scenarios/e2e-encryption.js +++ b/test/end-to-end-tests/src/scenarios/e2e-encryption.js @@ -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. @@ -23,7 +24,7 @@ const changeRoomSettings = require('../usecases/room-settings'); const {startSasVerifcation, acceptSasVerification} = require('../usecases/verify'); const assert = require('assert'); -module.exports = async function e2eEncryptionScenarios(alice, bob) { +export default async function e2eEncryptionScenarios(alice, bob) { console.log(" creating an e2e encrypted room and join through invite:"); const room = "secrets"; await createRoom(bob, room); diff --git a/test/end-to-end-tests/src/scenarios/lazy-loading.js b/test/end-to-end-tests/src/scenarios/lazy-loading.js index be5a91bb71..651397e426 100644 --- a/test/end-to-end-tests/src/scenarios/lazy-loading.js +++ b/test/end-to-end-tests/src/scenarios/lazy-loading.js @@ -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. @@ -27,7 +28,7 @@ const {getMembersInMemberlist} = require('../usecases/memberlist'); const changeRoomSettings = require('../usecases/room-settings'); const assert = require('assert'); -module.exports = async function lazyLoadingScenarios(alice, bob, charlies) { +export default async function lazyLoadingScenarios(alice, bob, charlies) { console.log(" creating a room for lazy loading member scenarios:"); const charly1to5 = charlies.slice("charly-1..5", 0, 5); const charly6to10 = charlies.slice("charly-6..10", 5); diff --git a/test/end-to-end-tests/src/session.js b/test/end-to-end-tests/src/session.js index 65cec6fef0..b17e55efa4 100644 --- a/test/end-to-end-tests/src/session.js +++ b/test/end-to-end-tests/src/session.js @@ -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. @@ -21,7 +22,7 @@ const {delay} = require('./util'); const DEFAULT_TIMEOUT = 20000; -module.exports = class RiotSession { +export default class RiotSession { constructor(browser, page, username, riotserver, hsUrl) { this.browser = browser; this.page = page; diff --git a/test/end-to-end-tests/src/usecases/accept-invite.js b/test/end-to-end-tests/src/usecases/accept-invite.js index 085c60aa6a..d17f583a77 100644 --- a/test/end-to-end-tests/src/usecases/accept-invite.js +++ b/test/end-to-end-tests/src/usecases/accept-invite.js @@ -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,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -module.exports = async function acceptInvite(session, name) { +export default async function acceptInvite(session, name) { session.log.step(`accepts "${name}" invite`); //TODO: brittle selector const invitesHandles = await session.queryAll('.mx_RoomTile_name.mx_RoomTile_invite'); diff --git a/test/end-to-end-tests/src/usecases/create-room.js b/test/end-to-end-tests/src/usecases/create-room.js index 75abdc78f4..7ca3826c71 100644 --- a/test/end-to-end-tests/src/usecases/create-room.js +++ b/test/end-to-end-tests/src/usecases/create-room.js @@ -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,12 +15,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -async function openRoomDirectory(session) { +export async function openRoomDirectory(session) { const roomDirectoryButton = await session.query('.mx_LeftPanel_explore .mx_AccessibleButton'); await roomDirectoryButton.click(); } -async function createRoom(session, roomName) { +export async function createRoom(session, roomName) { session.log.step(`creates room "${roomName}"`); const roomListHeaders = await session.queryAll('.mx_RoomSubList_labelContainer'); @@ -42,5 +43,3 @@ async function createRoom(session, roomName) { await session.query('.mx_MessageComposer'); session.log.done(); } - -module.exports = {openRoomDirectory, createRoom}; diff --git a/test/end-to-end-tests/src/usecases/dialog.js b/test/end-to-end-tests/src/usecases/dialog.js index 7b5d4d09fa..72d024fc79 100644 --- a/test/end-to-end-tests/src/usecases/dialog.js +++ b/test/end-to-end-tests/src/usecases/dialog.js @@ -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,20 +17,20 @@ limitations under the License. const assert = require('assert'); -async function assertDialog(session, expectedTitle) { +export async function assertDialog(session, expectedTitle) { const titleElement = await session.query(".mx_Dialog .mx_Dialog_title"); const dialogHeader = await session.innerText(titleElement); assert(dialogHeader, expectedTitle); } -async function acceptDialog(session, expectedTitle) { +export async function acceptDialog(session, expectedTitle) { const foundDialog = await acceptDialogMaybe(session, expectedTitle); if (!foundDialog) { throw new Error("could not find a dialog"); } } -async function acceptDialogMaybe(session, expectedTitle) { +export async function acceptDialogMaybe(session, expectedTitle) { let primaryButton = null; try { primaryButton = await session.query(".mx_Dialog .mx_Dialog_primary"); @@ -42,9 +43,3 @@ async function acceptDialogMaybe(session, expectedTitle) { await primaryButton.click(); return true; } - -module.exports = { - assertDialog, - acceptDialog, - acceptDialogMaybe, -}; diff --git a/test/end-to-end-tests/src/usecases/invite.js b/test/end-to-end-tests/src/usecases/invite.js index 814ecd30a6..fc91e4ce16 100644 --- a/test/end-to-end-tests/src/usecases/invite.js +++ b/test/end-to-end-tests/src/usecases/invite.js @@ -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,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -module.exports = async function invite(session, userId) { +export default async function invite(session, userId) { session.log.step(`invites "${userId}" to room`); await session.delay(1000); const memberPanelButton = await session.query(".mx_RightPanel_membersButton"); diff --git a/test/end-to-end-tests/src/usecases/join.js b/test/end-to-end-tests/src/usecases/join.js index bc292a0768..4fbc134598 100644 --- a/test/end-to-end-tests/src/usecases/join.js +++ b/test/end-to-end-tests/src/usecases/join.js @@ -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 {openRoomDirectory} = require('./create-room'); -module.exports = async function join(session, roomName) { +export default async function join(session, roomName) { session.log.step(`joins room "${roomName}"`); await openRoomDirectory(session); const roomInput = await session.query('.mx_DirectorySearchBox input'); diff --git a/test/end-to-end-tests/src/usecases/memberlist.js b/test/end-to-end-tests/src/usecases/memberlist.js index 42601b6610..8d2aacf35c 100644 --- a/test/end-to-end-tests/src/usecases/memberlist.js +++ b/test/end-to-end-tests/src/usecases/memberlist.js @@ -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; diff --git a/test/end-to-end-tests/src/usecases/room-settings.js b/test/end-to-end-tests/src/usecases/room-settings.js index 7655d2d066..d853cf92e4 100644 --- a/test/end-to-end-tests/src/usecases/room-settings.js +++ b/test/end-to-end-tests/src/usecases/room-settings.js @@ -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. @@ -29,7 +30,7 @@ async function setSettingsToggle(session, toggle, enabled) { } } -module.exports = async function changeRoomSettings(session, settings) { +export default async function changeRoomSettings(session, settings) { session.log.startGroup(`changes the room settings`); /// XXX delay is needed here, possibly because the header is being rerendered /// click doesn't do anything otherwise diff --git a/test/end-to-end-tests/src/usecases/settings.js b/test/end-to-end-tests/src/usecases/settings.js index ec675157f2..411ec3b497 100644 --- a/test/end-to-end-tests/src/usecases/settings.js +++ b/test/end-to-end-tests/src/usecases/settings.js @@ -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}; -}; +} diff --git a/test/end-to-end-tests/src/usecases/signup.js b/test/end-to-end-tests/src/usecases/signup.js index fd2b948572..381b87ec9e 100644 --- a/test/end-to-end-tests/src/usecases/signup.js +++ b/test/end-to-end-tests/src/usecases/signup.js @@ -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 = async function signup(session, username, password, homeserver) { +export default async function signup(session, username, password, homeserver) { session.log.step("signs up"); await session.goto(session.url('/#/register')); // change the homeserver by clicking the advanced section diff --git a/test/end-to-end-tests/src/usecases/timeline.js b/test/end-to-end-tests/src/usecases/timeline.js index 3ff9e0f5b4..8a18e2653f 100644 --- a/test/end-to-end-tests/src/usecases/timeline.js +++ b/test/end-to-end-tests/src/usecases/timeline.js @@ -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`); diff --git a/test/end-to-end-tests/src/usecases/verify.js b/test/end-to-end-tests/src/usecases/verify.js index 11ff98d097..a8b71cfe5c 100644 --- a/test/end-to-end-tests/src/usecases/verify.js +++ b/test/end-to-end-tests/src/usecases/verify.js @@ -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; -}; +} diff --git a/test/end-to-end-tests/src/util.js b/test/end-to-end-tests/src/util.js index 699b11b5ce..cafe929eca 100644 --- a/test/end-to-end-tests/src/util.js +++ b/test/end-to-end-tests/src/util.js @@ -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)); -}; +} diff --git a/test/mock-clock.js b/test/mock-clock.js index 103e186c1f..7cad0e9483 100644 --- a/test/mock-clock.js +++ b/test/mock-clock.js @@ -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; +}