Skip to content

Commit 6423f7c

Browse files
committed
rageshake: factor out submission to a separate file
This will mean we can load it asyncronously in future, if we want.
1 parent 4efb2b6 commit 6423f7c

3 files changed

Lines changed: 83 additions & 63 deletions

File tree

‎src/components/views/dialogs/BugReportDialog.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
import React from 'react';
1818
import sdk from 'matrix-react-sdk';
19-
import rageshake from '../../../vector/rageshake';
19+
import submit_rageshake from '../../../vector/submit-rageshake';
2020
import SdkConfig from 'matrix-react-sdk/lib/SdkConfig';
2121

2222
export default class BugReportDialog extends React.Component {
@@ -48,7 +48,7 @@ export default class BugReportDialog extends React.Component {
4848
return;
4949
}
5050
this.setState({ busy: true, err: null });
51-
rageshake.sendBugReport(
51+
submit_rageshake(
5252
SdkConfig.get().bug_report_endpoint_url, userText, sendLogs,
5353
).then(() => {
5454
this.setState({ busy: false });

‎src/vector/rageshake.js‎

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import PlatformPeg from 'matrix-react-sdk/lib/PlatformPeg';
18-
import request from "browser-request";
1917
import q from "q";
2018

2119
// This module contains all the code needed to log the console, persist it to
@@ -454,63 +452,4 @@ module.exports = {
454452
}];
455453
}
456454
},
457-
458-
/**
459-
* Send a bug report.
460-
* @param {string} bugReportEndpoint HTTP url to send the report to
461-
* @param {string} userText Any additional user input.
462-
* @param {boolean} sendLogs True to send logs
463-
* @return {Promise} Resolved when the bug report is sent.
464-
*/
465-
sendBugReport: async function(bugReportEndpoint, userText, sendLogs) {
466-
if (!bugReportEndpoint) {
467-
throw new Error("No bug report endpoint has been set.");
468-
}
469-
470-
let version = "UNKNOWN";
471-
try {
472-
version = await PlatformPeg.get().getAppVersion();
473-
}
474-
catch (err) {} // PlatformPeg already logs this.
475-
476-
let userAgent = "UNKNOWN";
477-
if (window.navigator && window.navigator.userAgent) {
478-
userAgent = window.navigator.userAgent;
479-
}
480-
481-
console.log("Sending bug report.");
482-
483-
let logs = [];
484-
if (sendLogs) {
485-
logs = await this.getLogsForReport();
486-
}
487-
488-
await q.Promise((resolve, reject) => {
489-
request({
490-
method: "POST",
491-
url: bugReportEndpoint,
492-
body: {
493-
logs: logs,
494-
text: (
495-
userText || "User did not supply any additional text."
496-
),
497-
app: 'riot-web',
498-
version: version,
499-
user_agent: userAgent,
500-
},
501-
json: true,
502-
timeout: 5 * 60 * 1000,
503-
}, (err, res) => {
504-
if (err) {
505-
reject(err);
506-
return;
507-
}
508-
if (res.status < 200 || res.status >= 400) {
509-
reject(new Error(`HTTP ${res.status}`));
510-
return;
511-
}
512-
resolve();
513-
})
514-
});
515-
}
516455
};

‎src/vector/submit-rageshake.js‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
Copyright 2017 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import q from "q";
18+
import request from "browser-request";
19+
20+
import PlatformPeg from 'matrix-react-sdk/lib/PlatformPeg';
21+
22+
import rageshake from './rageshake'
23+
24+
/**
25+
* Send a bug report.
26+
* @param {string} bugReportEndpoint HTTP url to send the report to
27+
* @param {string} userText Any additional user input.
28+
* @param {boolean} sendLogs True to send logs
29+
* @return {Promise} Resolved when the bug report is sent.
30+
*/
31+
export default async function sendBugReport(bugReportEndpoint, userText, sendLogs) {
32+
if (!bugReportEndpoint) {
33+
throw new Error("No bug report endpoint has been set.");
34+
}
35+
36+
let version = "UNKNOWN";
37+
try {
38+
version = await PlatformPeg.get().getAppVersion();
39+
}
40+
catch (err) {} // PlatformPeg already logs this.
41+
42+
let userAgent = "UNKNOWN";
43+
if (window.navigator && window.navigator.userAgent) {
44+
userAgent = window.navigator.userAgent;
45+
}
46+
47+
console.log("Sending bug report.");
48+
49+
let logs = [];
50+
if (sendLogs) {
51+
logs = await rageshake.getLogsForReport();
52+
}
53+
54+
await q.Promise((resolve, reject) => {
55+
request({
56+
method: "POST",
57+
url: bugReportEndpoint,
58+
body: {
59+
logs: logs,
60+
text: (
61+
userText || "User did not supply any additional text."
62+
),
63+
app: 'riot-web',
64+
version: version,
65+
user_agent: userAgent,
66+
},
67+
json: true,
68+
timeout: 5 * 60 * 1000,
69+
}, (err, res) => {
70+
if (err) {
71+
reject(err);
72+
return;
73+
}
74+
if (res.status < 200 || res.status >= 400) {
75+
reject(new Error(`HTTP ${res.status}`));
76+
return;
77+
}
78+
resolve();
79+
})
80+
});
81+
}

0 commit comments

Comments
 (0)