From a5fb33de026711b0e5795f19b26999f83a827291 Mon Sep 17 00:00:00 2001 From: Aaron Raimist Date: Tue, 2 Oct 2018 19:20:03 -0500 Subject: [PATCH 1/5] Fix Promise.defer warnings in getconfig.js (#7409) Signed-off-by: Aaron Raimist --- src/vector/getconfig.js | 54 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/vector/getconfig.js b/src/vector/getconfig.js index f3e7bea168..868840c6ac 100644 --- a/src/vector/getconfig.js +++ b/src/vector/getconfig.js @@ -33,35 +33,33 @@ export async function getVectorConfig(relativeLocation) { } function getConfig(configJsonFilename) { - let deferred = Promise.defer(); - - request( - { method: "GET", url: configJsonFilename }, - (err, response, body) => { - if (err || response.status < 200 || response.status >= 300) { - // Lack of a config isn't an error, we should - // just use the defaults. - // Also treat a blank config as no config, assuming - // the status code is 0, because we don't get 404s - // from file: URIs so this is the only way we can - // not fail if the file doesn't exist when loading - // from a file:// URI. - if (response) { - if (response.status == 404 || (response.status == 0 && body == '')) { - deferred.resolve({}); + return new Promise(function(resolve, reject) { + request( + { method: "GET", url: configJsonFilename }, + (err, response, body) => { + if (err || response.status < 200 || response.status >= 300) { + // Lack of a config isn't an error, we should + // just use the defaults. + // Also treat a blank config as no config, assuming + // the status code is 0, because we don't get 404s + // from file: URIs so this is the only way we can + // not fail if the file doesn't exist when loading + // from a file:// URI. + if (response) { + if (response.status == 404 || (response.status == 0 && body == '')) { + resolve({}); + } } + reject({err: err, response: response}); + return; } - deferred.reject({err: err, response: response}); - return; + + // We parse the JSON ourselves rather than use the JSON + // parameter, since this throws a parse error on empty + // which breaks if there's no config.json and we're + // loading from the filesystem (see above). + resolve(JSON.parse(body)); } - - // We parse the JSON ourselves rather than use the JSON - // parameter, since this throws a parse error on empty - // which breaks if there's no config.json and we're - // loading from the filesystem (see above). - deferred.resolve(JSON.parse(body)); - } - ); - - return deferred.promise; + ); + }) } From 54c46df0dc7e2a249eac4459ebd61f1186f8d42b Mon Sep 17 00:00:00 2001 From: Aaron Raimist Date: Tue, 2 Oct 2018 19:27:19 -0500 Subject: [PATCH 2/5] Fix Promise.defer warnings in index.js (#7409) Signed-off-by: Aaron Raimist --- src/vector/index.js | 54 ++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/vector/index.js b/src/vector/index.js index fffdac1b05..fc64bbf829 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -179,37 +179,35 @@ function makeRegistrationUrl(params) { } function getConfig(configJsonFilename) { - let deferred = Promise.defer(); - - request( - { method: "GET", url: configJsonFilename }, - (err, response, body) => { - if (err || response.status < 200 || response.status >= 300) { - // Lack of a config isn't an error, we should - // just use the defaults. - // Also treat a blank config as no config, assuming - // the status code is 0, because we don't get 404s - // from file: URIs so this is the only way we can - // not fail if the file doesn't exist when loading - // from a file:// URI. - if (response) { - if (response.status == 404 || (response.status == 0 && body == '')) { - deferred.resolve({}); + return new Promise(function(resolve, reject) { + request( + { method: "GET", url: configJsonFilename }, + (err, response, body) => { + if (err || response.status < 200 || response.status >= 300) { + // Lack of a config isn't an error, we should + // just use the defaults. + // Also treat a blank config as no config, assuming + // the status code is 0, because we don't get 404s + // from file: URIs so this is the only way we can + // not fail if the file doesn't exist when loading + // from a file:// URI. + if (response) { + if (response.status == 404 || (response.status == 0 && body == '')) { + resolve({}); + } } + reject({err: err, response: response}); + return; } - deferred.reject({err: err, response: response}); - return; + + // We parse the JSON ourselves rather than use the JSON + // parameter, since this throws a parse error on empty + // which breaks if there's no config.json and we're + // loading from the filesystem (see above). + resolve(JSON.parse(body)); } - - // We parse the JSON ourselves rather than use the JSON - // parameter, since this throws a parse error on empty - // which breaks if there's no config.json and we're - // loading from the filesystem (see above). - deferred.resolve(JSON.parse(body)); - } - ); - - return deferred.promise; + ); + }) } function onTokenLoginCompleted() { From 401c85ad5b39aa350f4babc41ce9f52cf481fbec Mon Sep 17 00:00:00 2001 From: Aaron Raimist Date: Tue, 2 Oct 2018 19:34:57 -0500 Subject: [PATCH 3/5] Fix Promise.defer warnings in WebPlatform.js (#7409) Signed-off-by: Aaron Raimist --- src/vector/platform/WebPlatform.js | 48 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/vector/platform/WebPlatform.js b/src/vector/platform/WebPlatform.js index a3ea12e866..1cd440207e 100644 --- a/src/vector/platform/WebPlatform.js +++ b/src/vector/platform/WebPlatform.js @@ -68,11 +68,11 @@ export default class WebPlatform extends VectorBasePlatform { // annoyingly, the latest spec says this returns a // promise, but this is only supported in Chrome 46 // and Firefox 47, so adapt the callback API. - const defer = Promise.defer(); - global.Notification.requestPermission((result) => { - defer.resolve(result); - }); - return defer.promise; + return new Promise(function(resolve, reject) { + global.Notification.requestPermission((result) => { + resolve(result); + }); + }) } displayNotification(title: string, msg: string, avatarUrl: string, room: Object) { @@ -103,31 +103,31 @@ export default class WebPlatform extends VectorBasePlatform { } _getVersion(): Promise { - const deferred = Promise.defer(); - // We add a cachebuster to the request to make sure that we know about // the most recent version on the origin server. That might not // actually be the version we'd get on a reload (particularly in the // presence of intermediate caching proxies), but still: we're trying // to tell the user that there is a new version. - request( - { - method: "GET", - url: "version", - qs: { cachebuster: Date.now() }, - }, - (err, response, body) => { - if (err || response.status < 200 || response.status >= 300) { - if (err === null) err = { status: response.status }; - deferred.reject(err); - return; - } - const ver = body.trim(); - deferred.resolve(ver); - }, - ); - return deferred.promise; + return new Promise(function(resolve, reject) { + request( + { + method: "GET", + url: "version", + qs: { cachebuster: Date.now() }, + }, + (err, response, body) => { + if (err || response.status < 200 || response.status >= 300) { + if (err === null) err = { status: response.status }; + reject(err); + return; + } + + const ver = body.trim(); + resolve(ver); + }, + ); + }) } getAppVersion(): Promise { From d035efb14eeffa34596bac5e7930cfede7982ded Mon Sep 17 00:00:00 2001 From: Aaron Raimist Date: Fri, 5 Oct 2018 10:41:45 -0500 Subject: [PATCH 4/5] Fix lint warnings and turn warnings back on (#7409) Signed-off-by: Aaron Raimist --- src/vector/getconfig.js | 4 ++-- src/vector/index.js | 8 ++------ src/vector/platform/WebPlatform.js | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/vector/getconfig.js b/src/vector/getconfig.js index 868840c6ac..239ba8067a 100644 --- a/src/vector/getconfig.js +++ b/src/vector/getconfig.js @@ -59,7 +59,7 @@ function getConfig(configJsonFilename) { // which breaks if there's no config.json and we're // loading from the filesystem (see above). resolve(JSON.parse(body)); - } + }, ); - }) + }); } diff --git a/src/vector/index.js b/src/vector/index.js index fc64bbf829..4da035d9b5 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -60,10 +60,6 @@ import CallHandler from 'matrix-react-sdk/lib/CallHandler'; import {getVectorConfig} from './getconfig'; -// Disable warnings for now: we use deprecated bluebird functions -// and need to migrate, but they spam the console with warnings. -Promise.config({warnings: false}); - let lastLocationHashSet = null; function initRageshake() { @@ -205,9 +201,9 @@ function getConfig(configJsonFilename) { // which breaks if there's no config.json and we're // loading from the filesystem (see above). resolve(JSON.parse(body)); - } + }, ); - }) + }); } function onTokenLoginCompleted() { diff --git a/src/vector/platform/WebPlatform.js b/src/vector/platform/WebPlatform.js index 1cd440207e..cfe5134662 100644 --- a/src/vector/platform/WebPlatform.js +++ b/src/vector/platform/WebPlatform.js @@ -72,7 +72,7 @@ export default class WebPlatform extends VectorBasePlatform { global.Notification.requestPermission((result) => { resolve(result); }); - }) + }); } displayNotification(title: string, msg: string, avatarUrl: string, room: Object) { @@ -127,7 +127,7 @@ export default class WebPlatform extends VectorBasePlatform { resolve(ver); }, ); - }) + }); } getAppVersion(): Promise { From d836ad8dbca74a77046a24a5f02238d91204bccc Mon Sep 17 00:00:00 2001 From: Aaron Raimist Date: Fri, 5 Oct 2018 11:05:25 -0500 Subject: [PATCH 5/5] Undo turning warnings back on (#7409) I guess that turns on warnings for everything, not just riot-web Signed-off-by: Aaron Raimist --- src/vector/index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vector/index.js b/src/vector/index.js index 4da035d9b5..ec3cb4dc81 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -62,6 +62,10 @@ import {getVectorConfig} from './getconfig'; let lastLocationHashSet = null; +// Disable warnings for now: we use deprecated bluebird functions +// and need to migrate, but they spam the console with warnings. +Promise.config({warnings: false}); + function initRageshake() { rageshake.init().then(() => { console.log("Initialised rageshake: See https://bugs.chromium.org/p/chromium/issues/detail?id=583193 to fix line numbers on Chrome.");