diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 4d44e9839c..3c7da9496e 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -116,12 +116,12 @@ export function loadSession(opts) { */ export function attemptTokenLogin(queryParams, defaultDeviceDisplayName) { if (!queryParams.loginToken) { - return q(false); + return Promise.resolve(false); } if (!queryParams.homeserver) { console.warn("Cannot log in with token: can't determine HS URL to use"); - return q(false); + return Promise.resolve(false); } // create a temporary MatrixClient to do the login @@ -197,7 +197,7 @@ function _registerAsGuest(hsUrl, isUrl, defaultDeviceDisplayName) { // localStorage (e.g. teamToken, isGuest etc.) function _restoreFromLocalStorage() { if (!localStorage) { - return q(false); + return Promise.resolve(false); } const hsUrl = localStorage.getItem("mx_hs_url"); const isUrl = localStorage.getItem("mx_is_url") || 'https://matrix.org'; @@ -229,7 +229,7 @@ function _restoreFromLocalStorage() { } } else { console.log("No previous session found."); - return q(false); + return Promise.resolve(false); } } diff --git a/src/Login.js b/src/Login.js index 038813cd62..049b79c2f4 100644 --- a/src/Login.js +++ b/src/Login.js @@ -144,7 +144,7 @@ export default class Login { const client = this._createTemporaryClient(); return client.login('m.login.password', loginParams).then(function(data) { - return q({ + return Promise.resolve({ homeserverUrl: self._hsUrl, identityServerUrl: self._isUrl, userId: data.user_id, @@ -160,7 +160,7 @@ export default class Login { }); return fbClient.login('m.login.password', loginParams).then(function(data) { - return q({ + return Promise.resolve({ homeserverUrl: self._fallbackHsUrl, identityServerUrl: self._isUrl, userId: data.user_id, diff --git a/src/Rooms.js b/src/Rooms.js index 44d7bedcce..2e3f4457f0 100644 --- a/src/Rooms.js +++ b/src/Rooms.js @@ -102,7 +102,7 @@ export function guessAndSetDMRoom(room, isDirect) { */ export function setDMRoom(roomId, userId) { if (MatrixClientPeg.get().isGuest()) { - return q(); + return Promise.resolve(); } const mDirectEvent = MatrixClientPeg.get().getAccountData('m.direct'); diff --git a/src/ScalarAuthClient.js b/src/ScalarAuthClient.js index 9702d21add..0275dcd1f7 100644 --- a/src/ScalarAuthClient.js +++ b/src/ScalarAuthClient.js @@ -39,7 +39,7 @@ class ScalarAuthClient { // Returns a scalar_token string getScalarToken() { var tok = window.localStorage.getItem("mx_scalar_token"); - if (tok) return q(tok); + if (tok) return Promise.resolve(tok); // No saved token, so do the dance to get one. First, we // need an openid bearer token from the HS. diff --git a/src/UserSettingsStore.js b/src/UserSettingsStore.js index 8c04f35d02..4c66c90598 100644 --- a/src/UserSettingsStore.js +++ b/src/UserSettingsStore.js @@ -48,7 +48,7 @@ export default { loadThreePids: function() { if (MatrixClientPeg.get().isGuest()) { - return q({ + return Promise.resolve({ threepids: [], }); // guests can't poke 3pid endpoint } diff --git a/src/autocomplete/Autocompleter.js b/src/autocomplete/Autocompleter.js index 236c0aa0f2..6b8cd66ae2 100644 --- a/src/autocomplete/Autocompleter.js +++ b/src/autocomplete/Autocompleter.js @@ -57,7 +57,7 @@ export async function getCompletions(query: string, selection: SelectionRange, f state (== "fulfilled" || "rejected") and value. */ const completionsList = await Q.allSettled( PROVIDERS.map(provider => { - return Q(provider.getCompletions(query, selection, force)) + return Promise.resolve(provider.getCompletions(query, selection, force)) .timeout(PROVIDER_COMPLETION_TIMEOUT); }), ); diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 8bc91fdc18..b4fd469441 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -323,9 +323,9 @@ module.exports = React.createClass({ return; } - // the extra q() ensures that synchronous exceptions hit the same codepath as + // the extra Promise.resolve() ensures that synchronous exceptions hit the same codepath as // asynchronous ones. - return q().then(() => { + return Promise.resolve().then(() => { return Lifecycle.loadSession({ fragmentQueryParams: this.props.startingFragmentQueryParams, enableGuest: this.props.enableGuest, @@ -694,7 +694,7 @@ module.exports = React.createClass({ // Wait for the first sync to complete so that if a room does have an alias, // it would have been retrieved. - let waitFor = q(null); + let waitFor = Promise.resolve(null); if (!this.firstSyncComplete) { if (!this.firstSyncPromise) { console.warn('Cannot view a room before first sync. room_id:', roomInfo.room_id); diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 306cbe922d..451f01a633 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -788,7 +788,7 @@ module.exports = React.createClass({ onSearchResultsFillRequest: function(backwards) { if (!backwards) { - return q(false); + return Promise.resolve(false); } if (this.state.searchResults.next_batch) { @@ -798,7 +798,7 @@ module.exports = React.createClass({ return this._handleSearchResult(searchPromise); } else { debuglog("no more search results"); - return q(false); + return Promise.resolve(false); } }, @@ -859,7 +859,7 @@ module.exports = React.createClass({ return; } - q().then(() => { + Promise.resolve().then(() => { const signUrl = this.props.thirdPartyInvite ? this.props.thirdPartyInvite.inviteSignUrl : undefined; dis.dispatch({ @@ -878,7 +878,7 @@ module.exports = React.createClass({ } } } - return q(); + return Promise.resolve(); }); }, diff --git a/src/components/structures/ScrollPanel.js b/src/components/structures/ScrollPanel.js index 0a593c29ac..95ab586e03 100644 --- a/src/components/structures/ScrollPanel.js +++ b/src/components/structures/ScrollPanel.js @@ -145,7 +145,7 @@ module.exports = React.createClass({ return { stickyBottom: true, startAtBottom: true, - onFillRequest: function(backwards) { return q(false); }, + onFillRequest: function(backwards) { return Promise.resolve(false); }, onUnfillRequest: function(backwards, scrollToken) {}, onScroll: function() {}, }; diff --git a/src/components/structures/TimelinePanel.js b/src/components/structures/TimelinePanel.js index 4dcb9c5ef8..dc9c0fc9ba 100644 --- a/src/components/structures/TimelinePanel.js +++ b/src/components/structures/TimelinePanel.js @@ -311,13 +311,13 @@ var TimelinePanel = React.createClass({ if (!this.state[canPaginateKey]) { debuglog("TimelinePanel: have given up", dir, "paginating this timeline"); - return q(false); + return Promise.resolve(false); } if(!this._timelineWindow.canPaginate(dir)) { debuglog("TimelinePanel: can't", dir, "paginate any further"); this.setState({[canPaginateKey]: false}); - return q(false); + return Promise.resolve(false); } debuglog("TimelinePanel: Initiating paginate; backwards:"+backwards); diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 0907c3e261..3558e0c278 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -203,7 +203,7 @@ module.exports = React.createClass({ this._addThreepid = null; if (PlatformPeg.get()) { - q().then(() => { + Promise.resolve().then(() => { return PlatformPeg.get().getAppVersion(); }).done((appVersion) => { if (this._unmounted) return; @@ -301,7 +301,7 @@ module.exports = React.createClass({ }, _refreshMediaDevices: function() { - q().then(() => { + Promise.resolve().then(() => { return CallMediaHandler.getDevices(); }).then((mediaDevices) => { // console.log("got mediaDevices", mediaDevices, this._unmounted); diff --git a/src/components/structures/login/Registration.js b/src/components/structures/login/Registration.js index a2e2d02bb0..fe05ba4cfd 100644 --- a/src/components/structures/login/Registration.js +++ b/src/components/structures/login/Registration.js @@ -180,7 +180,7 @@ module.exports = React.createClass({ // will just nop. The point of this being we might not have the email address // that the user registered with at this stage (depending on whether this // is the client they initiated registration). - let trackPromise = q(null); + let trackPromise = Promise.resolve(null); if (this._rtsClient && extra.emailSid) { // Track referral if this.props.referrer set, get team_token in order to // retrieve team config and see welcome page etc. @@ -232,7 +232,7 @@ module.exports = React.createClass({ _setupPushers: function(matrixClient) { if (!this.props.brand) { - return q(); + return Promise.resolve(); } return matrixClient.getPushers().then((resp)=>{ const pushers = resp.pushers; diff --git a/src/components/views/elements/EditableTextContainer.js b/src/components/views/elements/EditableTextContainer.js index f986587966..aeb32c07ec 100644 --- a/src/components/views/elements/EditableTextContainer.js +++ b/src/components/views/elements/EditableTextContainer.js @@ -148,5 +148,5 @@ EditableTextContainer.defaultProps = { initialValue: "", placeholder: "", blurToSubmit: false, - onSubmit: function(v) {return q(); }, + onSubmit: function(v) {return Promise.resolve(); }, }; diff --git a/src/components/views/messages/MImageBody.js b/src/components/views/messages/MImageBody.js index cd80785749..dcc073c80e 100644 --- a/src/components/views/messages/MImageBody.js +++ b/src/components/views/messages/MImageBody.js @@ -123,7 +123,7 @@ module.exports = React.createClass({ this.fixupHeight(); const content = this.props.mxEvent.getContent(); if (content.file !== undefined && this.state.decryptedUrl === null) { - let thumbnailPromise = q(null); + let thumbnailPromise = Promise.resolve(null); if (content.info.thumbnail_file) { thumbnailPromise = decryptFile( content.info.thumbnail_file, diff --git a/src/components/views/messages/MVideoBody.js b/src/components/views/messages/MVideoBody.js index 10008a8e46..06c233e012 100644 --- a/src/components/views/messages/MVideoBody.js +++ b/src/components/views/messages/MVideoBody.js @@ -89,7 +89,7 @@ module.exports = React.createClass({ componentDidMount: function() { const content = this.props.mxEvent.getContent(); if (content.file !== undefined && this.state.decryptedUrl === null) { - var thumbnailPromise = q(null); + var thumbnailPromise = Promise.resolve(null); if (content.info.thumbnail_file) { thumbnailPromise = decryptFile( content.info.thumbnail_file diff --git a/src/components/views/room_settings/ColorSettings.js b/src/components/views/room_settings/ColorSettings.js index 763c402d6f..b37802d304 100644 --- a/src/components/views/room_settings/ColorSettings.js +++ b/src/components/views/room_settings/ColorSettings.js @@ -72,7 +72,7 @@ module.exports = React.createClass({ saveSettings: function() { // : Promise if (!this.state.hasChanged) { - return q(); // They didn't explicitly give a color to save. + return Promise.resolve(); // They didn't explicitly give a color to save. } var originalState = this.getInitialState(); if (originalState.primary_color !== this.state.primary_color || @@ -92,7 +92,7 @@ module.exports = React.createClass({ } }); } - return q(); // no color diff + return Promise.resolve(); // no color diff }, _getColorIndex: function(scheme) { diff --git a/src/components/views/rooms/Autocomplete.js b/src/components/views/rooms/Autocomplete.js index a3315f61aa..10c9d405ac 100644 --- a/src/components/views/rooms/Autocomplete.js +++ b/src/components/views/rooms/Autocomplete.js @@ -64,7 +64,7 @@ export default class Autocomplete extends React.Component { // Hide the autocomplete box hide: true, }); - return Q(null); + return Promise.resolve(null); } let autocompleteDelay = UserSettingsStore.getLocalSetting('autocompleteDelay', 200); diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index caa9f1bdaf..270b2a54d5 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -305,25 +305,25 @@ module.exports = React.createClass({ }, saveAliases: function() { - if (!this.refs.alias_settings) { return [q()]; } + if (!this.refs.alias_settings) { return [Promise.resolve()]; } return this.refs.alias_settings.saveSettings(); }, saveColor: function() { - if (!this.refs.color_settings) { return q(); } + if (!this.refs.color_settings) { return Promise.resolve(); } return this.refs.color_settings.saveSettings(); }, saveUrlPreviewSettings: function() { - if (!this.refs.url_preview_settings) { return q(); } + if (!this.refs.url_preview_settings) { return Promise.resolve(); } return this.refs.url_preview_settings.saveSettings(); }, saveEnableEncryption: function() { - if (!this.refs.encrypt) { return q(); } + if (!this.refs.encrypt) { return Promise.resolve(); } var encrypt = this.refs.encrypt.checked; - if (!encrypt) { return q(); } + if (!encrypt) { return Promise.resolve(); } var roomId = this.props.room.roomId; return MatrixClientPeg.get().sendStateEvent( diff --git a/src/createRoom.js b/src/createRoom.js index 3b95c29b4c..74e4b3c2fc 100644 --- a/src/createRoom.js +++ b/src/createRoom.js @@ -42,7 +42,7 @@ function createRoom(opts) { const client = MatrixClientPeg.get(); if (client.isGuest()) { dis.dispatch({action: 'view_set_mxid'}); - return q(null); + return Promise.resolve(null); } const defaultPreset = opts.dmUserId ? 'trusted_private_chat' : 'private_chat'; @@ -92,7 +92,7 @@ function createRoom(opts) { if (opts.dmUserId) { return Rooms.setDMRoom(roomId, opts.dmUserId); } else { - return q(); + return Promise.resolve(); } }).then(function() { // NB createRoom doesn't block on the client seeing the echo that the diff --git a/src/utils/DecryptFile.js b/src/utils/DecryptFile.js index b9ef33ea6c..8054805409 100644 --- a/src/utils/DecryptFile.js +++ b/src/utils/DecryptFile.js @@ -53,7 +53,7 @@ export function readBlobAsDataUri(file) { export function decryptFile(file) { const url = MatrixClientPeg.get().mxcUrlToHttp(file.url); // Download the encrypted file as an array buffer. - return q(fetch(url)).then(function(response) { + return Promise.resolve(fetch(url)).then(function(response) { return response.arrayBuffer(); }).then(function(responseData) { // Decrypt the array buffer using the information taken from diff --git a/test/components/structures/ScrollPanel-test.js b/test/components/structures/ScrollPanel-test.js index 0f8b2416cd..670633c6fd 100644 --- a/test/components/structures/ScrollPanel-test.js +++ b/test/components/structures/ScrollPanel-test.js @@ -58,7 +58,7 @@ var Tester = React.createClass({ if (handler) { res = handler(); } else { - res = q(false); + res = Promise.resolve(false); } if (defer) { @@ -168,7 +168,7 @@ describe('ScrollPanel', function() { const sp = tester.scrollPanel(); let retriesRemaining = 1; const awaitReady = function() { - return q().then(() => { + return Promise.resolve().then(() => { if (sp._pendingFillRequests.b === false && sp._pendingFillRequests.f === false ) { @@ -195,7 +195,7 @@ describe('ScrollPanel', function() { it('should handle scrollEvent strangeness', function() { const events = []; - return q().then(() => { + return Promise.resolve().then(() => { // initialise with a load of events for (let i = 0; i < 20; i++) { events.push(i+80); @@ -227,7 +227,7 @@ describe('ScrollPanel', function() { it('should not get stuck in #528 workaround', function(done) { var events = []; - q().then(() => { + Promise.resolve().then(() => { // initialise with a bunch of events for (var i = 0; i < 40; i++) { events.push(i); diff --git a/test/components/structures/TimelinePanel-test.js b/test/components/structures/TimelinePanel-test.js index 7822e14e2c..56bde195ee 100644 --- a/test/components/structures/TimelinePanel-test.js +++ b/test/components/structures/TimelinePanel-test.js @@ -145,7 +145,7 @@ describe('TimelinePanel', function() { // panel isn't paginating var awaitPaginationCompletion = function() { if(!panel.state.forwardPaginating) - return q(); + return Promise.resolve(); else return q.delay(0).then(awaitPaginationCompletion); }; @@ -214,7 +214,7 @@ describe('TimelinePanel', function() { client.paginateEventTimeline = sinon.spy((tl, opts) => { console.log("paginate:", opts); expect(opts.backwards).toBe(true); - return q(true); + return Promise.resolve(true); }); var rendered = ReactDOM.render( diff --git a/test/components/views/dialogs/InteractiveAuthDialog-test.js b/test/components/views/dialogs/InteractiveAuthDialog-test.js index 2816b987aa..969396865e 100644 --- a/test/components/views/dialogs/InteractiveAuthDialog-test.js +++ b/test/components/views/dialogs/InteractiveAuthDialog-test.js @@ -50,7 +50,7 @@ describe('InteractiveAuthDialog', function () { it('Should successfully complete a password flow', function() { const onFinished = sinon.spy(); - const doRequest = sinon.stub().returns(q({a:1})); + const doRequest = sinon.stub().returns(Promise.resolve({a:1})); // tell the stub matrixclient to return a real userid var client = MatrixClientPeg.get(); diff --git a/test/stores/RoomViewStore-test.js b/test/stores/RoomViewStore-test.js index a0f804da18..be598de8da 100644 --- a/test/stores/RoomViewStore-test.js +++ b/test/stores/RoomViewStore-test.js @@ -39,7 +39,7 @@ describe('RoomViewStore', function() { }); it('can be used to view a room by alias and join', function(done) { - peg.get().getRoomIdForAlias.returns(q({room_id: "!randomcharacters:aser.ver"})); + peg.get().getRoomIdForAlias.returns(Promise.resolve({room_id: "!randomcharacters:aser.ver"})); peg.get().joinRoom = (roomAddress) => { expect(roomAddress).toBe("#somealias2:aser.ver"); done(); diff --git a/test/test-utils.js b/test/test-utils.js index 8f6b5c15e7..23f16a2e4c 100644 --- a/test/test-utils.js +++ b/test/test-utils.js @@ -75,12 +75,12 @@ export function createTestClient() { on: sinon.stub(), removeListener: sinon.stub(), isRoomEncrypted: sinon.stub().returns(false), - peekInRoom: sinon.stub().returns(q(mkStubRoom())), + peekInRoom: sinon.stub().returns(Promise.resolve(mkStubRoom())), - paginateEventTimeline: sinon.stub().returns(q()), - sendReadReceipt: sinon.stub().returns(q()), - getRoomIdForAlias: sinon.stub().returns(q()), - getProfileInfo: sinon.stub().returns(q({})), + paginateEventTimeline: sinon.stub().returns(Promise.resolve()), + sendReadReceipt: sinon.stub().returns(Promise.resolve()), + getRoomIdForAlias: sinon.stub().returns(Promise.resolve()), + getProfileInfo: sinon.stub().returns(Promise.resolve({})), getAccountData: (type) => { return mkEvent({ type, @@ -89,9 +89,9 @@ export function createTestClient() { }); }, setAccountData: sinon.stub(), - sendTyping: sinon.stub().returns(q({})), - sendTextMessage: () => q({}), - sendHtmlMessage: () => q({}), + sendTyping: sinon.stub().returns(Promise.resolve({})), + sendTextMessage: () => Promise.resolve({}), + sendHtmlMessage: () => Promise.resolve({}), getSyncState: () => "SYNCING", generateClientSecret: () => "t35tcl1Ent5ECr3T", isGuest: () => false, @@ -101,13 +101,13 @@ export function createTestClient() { export function createTestRtsClient(teamMap, sidMap) { return { getTeamsConfig() { - return q(Object.keys(teamMap).map((token) => teamMap[token])); + return Promise.resolve(Object.keys(teamMap).map((token) => teamMap[token])); }, trackReferral(referrer, emailSid, clientSecret) { - return q({team_token: sidMap[emailSid]}); + return Promise.resolve({team_token: sidMap[emailSid]}); }, getTeam(teamToken) { - return q(teamMap[teamToken]); + return Promise.resolve(teamMap[teamToken]); }, }; }