mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
provider higher-level rageshake fn for opened session
Co-authored-by: R Midhun Suresh <MidhunSureshR@users.noreply.github.com>
This commit is contained in:
parent
fef7af3b31
commit
bd3499056a
@ -16,11 +16,15 @@ limitations under the License.
|
||||
|
||||
import type {BlobHandle} from "../platform/web/dom/BlobHandle";
|
||||
import type {RequestFunction} from "../platform/types/types";
|
||||
import type {Platform} from "../platform/web/Platform";
|
||||
import type {ILogger} from "../logging/types";
|
||||
import type { IDBLogPersister } from "../logging/IDBLogPersister";
|
||||
import type { Session } from "../matrix/Session";
|
||||
|
||||
// see https://github.com/matrix-org/rageshake#readme
|
||||
type RageshakeData = {
|
||||
// A textual description of the problem. Included in the details.log.gz file.
|
||||
text: string | undefined;
|
||||
text?: string;
|
||||
// Application user-agent. Included in the details.log.gz file.
|
||||
userAgent: string;
|
||||
// Identifier for the application (eg 'riot-web'). Should correspond to a mapping configured in the configuration file for github issue reporting to work.
|
||||
@ -28,7 +32,7 @@ type RageshakeData = {
|
||||
// Application version. Included in the details.log.gz file.
|
||||
version: string;
|
||||
// Label to attach to the github issue, and include in the details file.
|
||||
label: string | undefined;
|
||||
label?: string;
|
||||
};
|
||||
|
||||
export async function submitLogsToRageshakeServer(data: RageshakeData, logsBlob: BlobHandle, submitUrl: string, request: RequestFunction): Promise<void> {
|
||||
@ -63,3 +67,28 @@ export async function submitLogsToRageshakeServer(data: RageshakeData, logsBlob:
|
||||
// we don't bother with reading report_url from the body as the rageshake server doesn't always return it
|
||||
// and would have to have CORS setup properly for us to be able to read it.
|
||||
}
|
||||
|
||||
/** @throws {Error} */
|
||||
export async function submitLogsFromSessionToDefaultServer(session: Session, platform: Platform): Promise<void> {
|
||||
const {bugReportEndpointUrl} = platform.config;
|
||||
if (!bugReportEndpointUrl) {
|
||||
throw new Error("no server configured to submit logs");
|
||||
}
|
||||
const logReporters = (platform.logger as ILogger).reporters;
|
||||
const exportReporter = logReporters.find(r => !!r["export"]) as IDBLogPersister | undefined;
|
||||
if (!exportReporter) {
|
||||
throw new Error("No logger that can export configured");
|
||||
}
|
||||
const logExport = await exportReporter.export();
|
||||
await submitLogsToRageshakeServer(
|
||||
{
|
||||
app: "hydrogen",
|
||||
userAgent: platform.description,
|
||||
version: platform.version,
|
||||
text: `Submit logs from settings for user ${session.userId} on device ${session.deviceId}`,
|
||||
},
|
||||
logExport.asBlob(),
|
||||
bugReportEndpointUrl,
|
||||
platform.request
|
||||
);
|
||||
}
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||
|
||||
import {ViewModel} from "../../ViewModel";
|
||||
import {KeyBackupViewModel} from "./KeyBackupViewModel.js";
|
||||
import {submitLogsToRageshakeServer} from "../../../domain/rageshake";
|
||||
import {submitLogsFromSessionToDefaultServer} from "../../../domain/rageshake";
|
||||
|
||||
class PushNotificationStatus {
|
||||
constructor() {
|
||||
@ -175,29 +175,13 @@ export class SettingsViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
async sendLogsToServer() {
|
||||
const {bugReportEndpointUrl} = this.platform.config;
|
||||
if (bugReportEndpointUrl) {
|
||||
this._logsFeedbackMessage = this.i18n`Sending logs…`;
|
||||
this._logsFeedbackMessage = this.i18n`Sending logs…`;
|
||||
try {
|
||||
await submitLogsFromSessionToDefaultServer(this._session, this.platform);
|
||||
this._logsFeedbackMessage = this.i18n`Logs sent succesfully!`;
|
||||
} catch (err) {
|
||||
this._logsFeedbackMessage = err.message;
|
||||
this.emitChange();
|
||||
try {
|
||||
const logExport = await this.logger.export();
|
||||
await submitLogsToRageshakeServer(
|
||||
{
|
||||
app: "hydrogen",
|
||||
userAgent: this.platform.description,
|
||||
version: DEFINE_VERSION,
|
||||
text: `Submit logs from settings for user ${this._session.userId} on device ${this._session.deviceId}`,
|
||||
},
|
||||
logExport.asBlob(),
|
||||
bugReportEndpointUrl,
|
||||
this.platform.request
|
||||
);
|
||||
this._logsFeedbackMessage = this.i18n`Logs sent succesfully!`;
|
||||
this.emitChange();
|
||||
} catch (err) {
|
||||
this._logsFeedbackMessage = err.message;
|
||||
this.emitChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user