Skip to content

Commit

Permalink
feat(subtree): add bug-reporting patch and fix dep path issues
Browse files Browse the repository at this point in the history
  • Loading branch information
marc.sirisak committed Apr 11, 2024
1 parent a93c61f commit eeeb7f8
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import DialogButtons from "../elements/DialogButtons";
import { sendSentryReport } from "../../../sentry";
import defaultDispatcher from "../../../dispatcher/dispatcher";
import { Action } from "../../../dispatcher/actions";
import { MatrixClientPeg } from '../../../MatrixClientPeg'; // :TCHAP:
import TchapUtils from "../../../../../../src/tchap/util/TchapUtils"; // :TCHAP:

interface IProps {
Expand Down Expand Up @@ -122,32 +121,25 @@ export default class BugReportDialog extends React.Component<IProps, IState> {
this.setState({ busy: true, progress: null, err: null });
this.sendProgressCallback(_t("bug_reporting|preparing_logs"));

// :TCHAP: customise report : add email, prefix with "tchap-web"
const client = MatrixClientPeg.get();
const customFields = {};
client.getThreePids().then(result => {
result.threepids.forEach(threepid => {
return customFields[threepid.medium] = threepid.address;
});
return customFields;
}).then(customFields => {
// is this a voip report ? Add it in "context" field
if (this.props.label === "voip-feedback") {
customFields.context = "voip";
// :TCHAP: add custom fields if it's a voip report
Promise.resolve().then(() => {
if (this.props.label !== "voip-feedback") {
return Promise.resolve({});
}

const customFields: Record<string, string> = {};
customFields.context = "voip";
return TchapUtils.isCurrentlyUsingBluetooth().then(isCurrentlyUsingBluetooth => {
customFields.audio_input = isCurrentlyUsingBluetooth ? "headset_bluetooth" : "device";
return customFields;
})
});
}).then(customFields => {
return sendBugReport(SdkConfig.get().bug_report_endpoint_url, {
userText,
sendLogs: true,
progressCallback: this.sendProgressCallback,
labels: this.props.label ? [this.props.label] : [],
customApp: 'tchap-web', // :TCHAP:
customFields: customFields, // :TCHAP:
customFields: customFields,
});
// end :TCHAP:
}).then(
Expand Down Expand Up @@ -184,7 +176,6 @@ export default class BugReportDialog extends React.Component<IProps, IState> {
sendLogs: true,
progressCallback: this.downloadProgressCallback,
labels: this.props.label ? [this.props.label] : [],
customApp: 'tchap-web', // :TCHAP: we don't add email here. You know your own email already.
});

this.setState({
Expand Down Expand Up @@ -271,13 +262,15 @@ export default class BugReportDialog extends React.Component<IProps, IState> {
/>
{progress}
{error}
<DialogButtons
primaryButton={_t("bug_reporting|send_logs")}
onPrimaryButtonClick={this.onSubmit}
focus={true}
hasCancel={false}
disabled={this.state.busy}
/>
<div className="mx_BugReportDialog_send_logs">
<DialogButtons
primaryButton={_t("bug_reporting|send_logs")}
onPrimaryButtonClick={this.onSubmit}
focus={true}
hasCancel={false}
disabled={this.state.busy}
/>
</div>

<div className="mx_BugReportDialog_download">
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ async function collectBaseInformation(body: FormData, opts: IOpts): Promise<void
const touchInput = matchesMediaQuery("(pointer: coarse)");

body.append("text", opts.userText || "User did not supply any additional text.");
/* :TCHAP: rename app - for bugreport rageshakes
body.append("app", opts.customApp || "element-web");
*/
body.append("app", "tchap-web");
// end :TCHAP:
body.append("version", version ?? "UNKNOWN");
body.append("user_agent", userAgent);
body.append("installed_pwa", installedPWA);
Expand All @@ -129,6 +133,10 @@ async function collectClientInfo(client: MatrixClient, body: FormData): Promise<
await collectRecoveryInfo(client, cryptoApi, body);
}

// :TCHAP: add user email - for bugreport rageshakes
await collectUserEmail(client, body);
// end :TCHAP:

await collectSynapseSpecific(client, body);
}

Expand Down Expand Up @@ -316,6 +324,16 @@ async function collectLogs(
body.append("compressed-log", new Blob([buf]), entry.id);
}
}

// :TCHAP:
async function collectUserEmail(client: MatrixClient, body: FormData): Promise<void> {
const result = await client.getThreePids(); //it generates a API calls which is acceptable because feedbacks submit are not so frequent (unfortunately)
result.threepids.forEach(threepid => {
body.append(threepid.medium, threepid.address);
});
}
// end :TCHAP:

/**
* Send a bug report.
*
Expand Down Expand Up @@ -412,13 +430,20 @@ export async function submitFeedback(
version = await PlatformPeg.get()?.getAppVersion();
} catch (err) {} // PlatformPeg already logs this.


const body = new FormData();
if (label) body.append("label", label);
body.append("text", comment);
body.append("can_contact", canContact ? "yes" : "no");

/* :TCHAP: rename app and add email - for feedback rageshakes
body.append("app", "element-web");
*/
body.append("app", "tchap-web");
const client = MatrixClientPeg.get();
if(client) {
await collectUserEmail(client, body);
}
// end :TCHAP:
body.append("version", version || "UNKNOWN");
body.append("platform", PlatformPeg.get()?.getHumanReadableName() ?? "n/a");
body.append("user_id", MatrixClientPeg.get()?.getUserId() ?? "n/a");
Expand All @@ -428,13 +453,6 @@ export async function submitFeedback(
}

const bugReportEndpointUrl = SdkConfig.get().bug_report_endpoint_url;
//:tchap: add email in body
const client = MatrixClientPeg.get();
const result = await client.getThreePids();//it generates a API calls which is acceptable because feedbacks submit are not so frequent (unfortunately)
result.threepids.forEach(threepid => {
body.append(threepid.medium, threepid.address);
});
//:tchap: end

if (bugReportEndpointUrl) {
await submitReport(bugReportEndpointUrl, body, () => {});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"coverage": "yarn test --coverage",
"analyse:unused-exports": "ts-node ./scripts/analyse_unused_exports.ts",
"patch-package": "patch-package",
"patches-reapply": "cd linked-dependencies/matrix-react-sdk; git checkout .; cd ../matrix-js-sdk; git checkout .; cd ../..; ./scripts/tchap/apply_patches.sh",
"patches-reapply": "cd ./yarn-linked-dependencies/matrix-js-sdk; git checkout .; cd ../..; ./scripts/tchap/apply_patches.sh",
"patch-make": "node scripts/tchap/makePatch.ts",
"analyse:webpack-bundles": "webpack-bundle-analyzer webpack-stats.json webapp",
"update:jitsi": "curl -s https://meet.element.io/libs/external_api.min.js > ./res/jitsi_external_api.min.js"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from "react";
import { RenderResult, fireEvent, render } from "@testing-library/react";

import BugReportDialog from "~tchap-web/yarn-linked-dependencies/matrix-react-sdk/src/components/views/dialogs/BugReportDialog";
import { flushPromises } from "~tchap-web/yarn-linked-dependencies/matrix-react-sdk/test/test-utils";
import SdkConfig from "~tchap-web/yarn-linked-dependencies/matrix-react-sdk/src/SdkConfig";
import BugReportDialog from "~linked-dep/matrix-react-sdk/src/components/views/dialogs/BugReportDialog";
import { flushPromises } from "~linked-dep/matrix-react-sdk/test/test-utils";
import SdkConfig from "~linked-dep/matrix-react-sdk/src/SdkConfig";

describe("<BugReportDialog>", () => {
const bugReportUrl = "/bug/report/url";
Expand All @@ -22,9 +22,7 @@ describe("<BugReportDialog>", () => {

beforeEach(() => {
// Mocking trick to mock a default export : use requireActual.
const actual = jest.requireActual(
"~tchap-web/yarn-linked-dependencies/matrix-react-sdk/src/rageshake/submit-rageshake",
);
const actual = jest.requireActual("~linked-dep/matrix-react-sdk/src/rageshake/submit-rageshake");
sendBugReportSpy = jest.spyOn(actual, "default").mockResolvedValue(bugReportUrl);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { render, screen } from "@testing-library/react";
import { mocked } from "jest-mock";

import { MatrixEvent } from "~tchap-web/yarn-linked-dependencies/matrix-js-sdk/src/matrix";
import LegacyCallEvent from "~tchap-web/yarn-linked-dependencies/matrix-react-sdk/src/components/views/messages/LegacyCallEvent";
import LegacyCallEventGrouper from "~tchap-web/yarn-linked-dependencies/matrix-react-sdk/src/components/structures/LegacyCallEventGrouper";
import { CallErrorCode, CallState } from "~tchap-web/yarn-linked-dependencies/matrix-js-sdk/src/webrtc/call";
import BugReportDialog from "~tchap-web/yarn-linked-dependencies/matrix-react-sdk/src/components/views/dialogs/BugReportDialog";
import Modal from "~tchap-web/yarn-linked-dependencies/matrix-react-sdk/src/Modal";
import LegacyCallEvent from "~linked-dep/matrix-react-sdk/src/components/views/messages/LegacyCallEvent";
import LegacyCallEventGrouper from "~linked-dep/matrix-react-sdk/src/components/structures/LegacyCallEventGrouper";
import { CallErrorCode, CallState } from "~tchap-web-dep/matrix-js-sdk/src/webrtc/call";
import BugReportDialog from "~linked-dep/matrix-react-sdk/src/components/views/dialogs/BugReportDialog";
import Modal from "~linked-dep/matrix-react-sdk/src/Modal";

const THEIR_USER_ID = "@them:here";

Expand Down
7 changes: 2 additions & 5 deletions test/unit-tests/tchap/rageshake/submit-rageshake-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ import {
} from "matrix-js-sdk/src/matrix";
import fetchMock from "fetch-mock-jest";

import {
getMockClientWithEventEmitter,
mockClientMethodsCrypto,
} from "~tchap-web-dep/matrix-react-sdk/test/test-utils";
import { collectBugReport } from "~tchap-web-dep/matrix-react-sdk/src/rageshake/submit-rageshake";
import { getMockClientWithEventEmitter, mockClientMethodsCrypto } from "~linked-dep/matrix-react-sdk/test/test-utils";
import { collectBugReport } from "~linked-dep/matrix-react-sdk/src/rageshake/submit-rageshake";

/**
* Based on react-sdk's test, removed unused things. Maybe this test has more mocks than strictly necessary.
Expand Down

0 comments on commit eeeb7f8

Please sign in to comment.