q(...) -> Promise.resolve
``` find src test -name '*.js' | xargs perl -i -pe 's/\b[qQ]\(/Promise.resolve(/' ```
This commit is contained in:
parent
a06bd84213
commit
0254d2b3a2
25 changed files with 57 additions and 57 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -48,7 +48,7 @@ export default {
|
|||
|
||||
loadThreePids: function() {
|
||||
if (MatrixClientPeg.get().isGuest()) {
|
||||
return q({
|
||||
return Promise.resolve({
|
||||
threepids: [],
|
||||
}); // guests can't poke 3pid endpoint
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}),
|
||||
);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -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() {},
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -148,5 +148,5 @@ EditableTextContainer.defaultProps = {
|
|||
initialValue: "",
|
||||
placeholder: "",
|
||||
blurToSubmit: false,
|
||||
onSubmit: function(v) {return q(); },
|
||||
onSubmit: function(v) {return Promise.resolve(); },
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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]);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue