Skip to content

Commit 3488f04

Browse files
author
Weblate
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 4c2dace + 92db2b8 commit 3488f04

3 files changed

Lines changed: 78 additions & 82 deletions

File tree

‎src/vector/getconfig.js‎

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,33 @@ export async function getVectorConfig(relativeLocation) {
3333
}
3434

3535
function getConfig(configJsonFilename) {
36-
let deferred = Promise.defer();
37-
38-
request(
39-
{ method: "GET", url: configJsonFilename },
40-
(err, response, body) => {
41-
if (err || response.status < 200 || response.status >= 300) {
42-
// Lack of a config isn't an error, we should
43-
// just use the defaults.
44-
// Also treat a blank config as no config, assuming
45-
// the status code is 0, because we don't get 404s
46-
// from file: URIs so this is the only way we can
47-
// not fail if the file doesn't exist when loading
48-
// from a file:// URI.
49-
if (response) {
50-
if (response.status == 404 || (response.status == 0 && body == '')) {
51-
deferred.resolve({});
36+
return new Promise(function(resolve, reject) {
37+
request(
38+
{ method: "GET", url: configJsonFilename },
39+
(err, response, body) => {
40+
if (err || response.status < 200 || response.status >= 300) {
41+
// Lack of a config isn't an error, we should
42+
// just use the defaults.
43+
// Also treat a blank config as no config, assuming
44+
// the status code is 0, because we don't get 404s
45+
// from file: URIs so this is the only way we can
46+
// not fail if the file doesn't exist when loading
47+
// from a file:// URI.
48+
if (response) {
49+
if (response.status == 404 || (response.status == 0 && body == '')) {
50+
resolve({});
51+
}
5252
}
53+
reject({err: err, response: response});
54+
return;
5355
}
54-
deferred.reject({err: err, response: response});
55-
return;
56-
}
57-
58-
// We parse the JSON ourselves rather than use the JSON
59-
// parameter, since this throws a parse error on empty
60-
// which breaks if there's no config.json and we're
61-
// loading from the filesystem (see above).
62-
deferred.resolve(JSON.parse(body));
63-
}
64-
);
6556

66-
return deferred.promise;
57+
// We parse the JSON ourselves rather than use the JSON
58+
// parameter, since this throws a parse error on empty
59+
// which breaks if there's no config.json and we're
60+
// loading from the filesystem (see above).
61+
resolve(JSON.parse(body));
62+
},
63+
);
64+
});
6765
}

‎src/vector/index.js‎

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ import CallHandler from 'matrix-react-sdk/lib/CallHandler';
6060

6161
import {getVectorConfig} from './getconfig';
6262

63+
let lastLocationHashSet = null;
64+
6365
// Disable warnings for now: we use deprecated bluebird functions
6466
// and need to migrate, but they spam the console with warnings.
6567
Promise.config({warnings: false});
6668

67-
let lastLocationHashSet = null;
68-
6969
function initRageshake() {
7070
rageshake.init().then(() => {
7171
console.log("Initialised rageshake: See https://bugs.chromium.org/p/chromium/issues/detail?id=583193 to fix line numbers on Chrome.");
@@ -179,37 +179,35 @@ function makeRegistrationUrl(params) {
179179
}
180180

181181
function getConfig(configJsonFilename) {
182-
let deferred = Promise.defer();
183-
184-
request(
185-
{ method: "GET", url: configJsonFilename },
186-
(err, response, body) => {
187-
if (err || response.status < 200 || response.status >= 300) {
188-
// Lack of a config isn't an error, we should
189-
// just use the defaults.
190-
// Also treat a blank config as no config, assuming
191-
// the status code is 0, because we don't get 404s
192-
// from file: URIs so this is the only way we can
193-
// not fail if the file doesn't exist when loading
194-
// from a file:// URI.
195-
if (response) {
196-
if (response.status == 404 || (response.status == 0 && body == '')) {
197-
deferred.resolve({});
182+
return new Promise(function(resolve, reject) {
183+
request(
184+
{ method: "GET", url: configJsonFilename },
185+
(err, response, body) => {
186+
if (err || response.status < 200 || response.status >= 300) {
187+
// Lack of a config isn't an error, we should
188+
// just use the defaults.
189+
// Also treat a blank config as no config, assuming
190+
// the status code is 0, because we don't get 404s
191+
// from file: URIs so this is the only way we can
192+
// not fail if the file doesn't exist when loading
193+
// from a file:// URI.
194+
if (response) {
195+
if (response.status == 404 || (response.status == 0 && body == '')) {
196+
resolve({});
197+
}
198198
}
199+
reject({err: err, response: response});
200+
return;
199201
}
200-
deferred.reject({err: err, response: response});
201-
return;
202-
}
203-
204-
// We parse the JSON ourselves rather than use the JSON
205-
// parameter, since this throws a parse error on empty
206-
// which breaks if there's no config.json and we're
207-
// loading from the filesystem (see above).
208-
deferred.resolve(JSON.parse(body));
209-
}
210-
);
211202

212-
return deferred.promise;
203+
// We parse the JSON ourselves rather than use the JSON
204+
// parameter, since this throws a parse error on empty
205+
// which breaks if there's no config.json and we're
206+
// loading from the filesystem (see above).
207+
resolve(JSON.parse(body));
208+
},
209+
);
210+
});
213211
}
214212

215213
function onTokenLoginCompleted() {

‎src/vector/platform/WebPlatform.js‎

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ export default class WebPlatform extends VectorBasePlatform {
6868
// annoyingly, the latest spec says this returns a
6969
// promise, but this is only supported in Chrome 46
7070
// and Firefox 47, so adapt the callback API.
71-
const defer = Promise.defer();
72-
global.Notification.requestPermission((result) => {
73-
defer.resolve(result);
71+
return new Promise(function(resolve, reject) {
72+
global.Notification.requestPermission((result) => {
73+
resolve(result);
74+
});
7475
});
75-
return defer.promise;
7676
}
7777

7878
displayNotification(title: string, msg: string, avatarUrl: string, room: Object) {
@@ -103,31 +103,31 @@ export default class WebPlatform extends VectorBasePlatform {
103103
}
104104

105105
_getVersion(): Promise<string> {
106-
const deferred = Promise.defer();
107-
108106
// We add a cachebuster to the request to make sure that we know about
109107
// the most recent version on the origin server. That might not
110108
// actually be the version we'd get on a reload (particularly in the
111109
// presence of intermediate caching proxies), but still: we're trying
112110
// to tell the user that there is a new version.
113-
request(
114-
{
115-
method: "GET",
116-
url: "version",
117-
qs: { cachebuster: Date.now() },
118-
},
119-
(err, response, body) => {
120-
if (err || response.status < 200 || response.status >= 300) {
121-
if (err === null) err = { status: response.status };
122-
deferred.reject(err);
123-
return;
124-
}
125-
126-
const ver = body.trim();
127-
deferred.resolve(ver);
128-
},
129-
);
130-
return deferred.promise;
111+
112+
return new Promise(function(resolve, reject) {
113+
request(
114+
{
115+
method: "GET",
116+
url: "version",
117+
qs: { cachebuster: Date.now() },
118+
},
119+
(err, response, body) => {
120+
if (err || response.status < 200 || response.status >= 300) {
121+
if (err === null) err = { status: response.status };
122+
reject(err);
123+
return;
124+
}
125+
126+
const ver = body.trim();
127+
resolve(ver);
128+
},
129+
);
130+
});
131131
}
132132

133133
getAppVersion(): Promise<string> {

0 commit comments

Comments
 (0)