From eeeb7f8fe62a5534ead6698b892822946ced1d22 Mon Sep 17 00:00:00 2001 From: "marc.sirisak" Date: Thu, 11 Apr 2024 10:53:17 +0000 Subject: [PATCH] feat(subtree): add bug-reporting patch and fix dep path issues --- .../views/dialogs/BugReportDialog.tsx | 41 ++++++++----------- .../src/rageshake/submit-rageshake.ts | 34 +++++++++++---- package.json | 2 +- .../views/dialogs/BugReportDialog-test.tsx | 10 ++--- .../views/messages/LegacyCallEvent-test.tsx | 10 ++--- .../tchap/rageshake/submit-rageshake-test.ts | 7 +--- 6 files changed, 55 insertions(+), 49 deletions(-) diff --git a/linked-dependencies/matrix-react-sdk/src/components/views/dialogs/BugReportDialog.tsx b/linked-dependencies/matrix-react-sdk/src/components/views/dialogs/BugReportDialog.tsx index 51baf28156..c7df84ae0a 100644 --- a/linked-dependencies/matrix-react-sdk/src/components/views/dialogs/BugReportDialog.tsx +++ b/linked-dependencies/matrix-react-sdk/src/components/views/dialogs/BugReportDialog.tsx @@ -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 { @@ -122,32 +121,25 @@ export default class BugReportDialog extends React.Component { 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 = {}; + 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( @@ -184,7 +176,6 @@ export default class BugReportDialog extends React.Component { 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({ @@ -271,13 +262,15 @@ export default class BugReportDialog extends React.Component { /> {progress} {error} - +
+ +

diff --git a/linked-dependencies/matrix-react-sdk/src/rageshake/submit-rageshake.ts b/linked-dependencies/matrix-react-sdk/src/rageshake/submit-rageshake.ts index 3034aaa280..c93d459233 100644 --- a/linked-dependencies/matrix-react-sdk/src/rageshake/submit-rageshake.ts +++ b/linked-dependencies/matrix-react-sdk/src/rageshake/submit-rageshake.ts @@ -102,7 +102,11 @@ async function collectBaseInformation(body: FormData, opts: IOpts): Promise { + 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. * @@ -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"); @@ -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, () => {}); diff --git a/package.json b/package.json index b55af842bd..796799565e 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/test/unit-tests/tchap/components/views/dialogs/BugReportDialog-test.tsx b/test/unit-tests/tchap/components/views/dialogs/BugReportDialog-test.tsx index b223c12d23..eaa3bdea9e 100644 --- a/test/unit-tests/tchap/components/views/dialogs/BugReportDialog-test.tsx +++ b/test/unit-tests/tchap/components/views/dialogs/BugReportDialog-test.tsx @@ -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("", () => { const bugReportUrl = "/bug/report/url"; @@ -22,9 +22,7 @@ describe("", () => { 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); }); diff --git a/test/unit-tests/tchap/components/views/messages/LegacyCallEvent-test.tsx b/test/unit-tests/tchap/components/views/messages/LegacyCallEvent-test.tsx index 0e26acf9b4..702bd1bd8e 100644 --- a/test/unit-tests/tchap/components/views/messages/LegacyCallEvent-test.tsx +++ b/test/unit-tests/tchap/components/views/messages/LegacyCallEvent-test.tsx @@ -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"; diff --git a/test/unit-tests/tchap/rageshake/submit-rageshake-test.ts b/test/unit-tests/tchap/rageshake/submit-rageshake-test.ts index 7b10bd49ba..a83c49c383 100644 --- a/test/unit-tests/tchap/rageshake/submit-rageshake-test.ts +++ b/test/unit-tests/tchap/rageshake/submit-rageshake-test.ts @@ -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.