mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 03:36:07 +03:00
Consolidate random string generation to make Sonar happier (#8675)
* Consolidate random string generation to make Sonar happier * Update snapshots
This commit is contained in:
parent
9f1bffcd34
commit
fe21ec8715
4 changed files with 13 additions and 11 deletions
|
@ -18,6 +18,7 @@ limitations under the License.
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
import { Optional } from "matrix-events-sdk";
|
import { Optional } from "matrix-events-sdk";
|
||||||
|
import { randomString } from 'matrix-js-sdk/src/randomstring';
|
||||||
|
|
||||||
import { getCurrentLanguage, _t, _td, IVariables } from './languageHandler';
|
import { getCurrentLanguage, _t, _td, IVariables } from './languageHandler';
|
||||||
import PlatformPeg from './PlatformPeg';
|
import PlatformPeg from './PlatformPeg';
|
||||||
|
@ -155,9 +156,9 @@ const LAST_VISIT_TS_KEY = "mx_Riot_Analytics_lvts";
|
||||||
|
|
||||||
function getUid(): string {
|
function getUid(): string {
|
||||||
try {
|
try {
|
||||||
let data = localStorage && localStorage.getItem(UID_KEY);
|
let data = localStorage?.getItem(UID_KEY);
|
||||||
if (!data && localStorage) {
|
if (!data && localStorage) {
|
||||||
localStorage.setItem(UID_KEY, data = [...Array(16)].map(() => Math.random().toString(16)[2]).join(''));
|
localStorage.setItem(UID_KEY, data = randomString(16));
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
|
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
|
||||||
|
import { randomString } from 'matrix-js-sdk/src/randomstring';
|
||||||
|
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
|
@ -45,10 +46,9 @@ export default class MLocationBody extends React.Component<IBodyProps, IState> {
|
||||||
constructor(props: IBodyProps) {
|
constructor(props: IBodyProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
const randomString = Math.random().toString(16).slice(2, 10);
|
|
||||||
// multiple instances of same map might be in document
|
// multiple instances of same map might be in document
|
||||||
// eg thread and main timeline, reply
|
// eg thread and main timeline, reply
|
||||||
const idSuffix = `${props.mxEvent.getId()}_${randomString}`;
|
const idSuffix = `${props.mxEvent.getId()}_${randomString(8)}`;
|
||||||
this.mapId = `mx_MLocationBody_${idSuffix}`;
|
this.mapId = `mx_MLocationBody_${idSuffix}`;
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
|
|
@ -39,6 +39,7 @@ limitations under the License.
|
||||||
|
|
||||||
// the frequency with which we flush to indexeddb
|
// the frequency with which we flush to indexeddb
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
import { randomString } from "matrix-js-sdk/src/randomstring";
|
||||||
|
|
||||||
import { getCircularReplacer } from "../utils/JSON";
|
import { getCircularReplacer } from "../utils/JSON";
|
||||||
|
|
||||||
|
@ -140,7 +141,7 @@ export class IndexedDBLogStore {
|
||||||
private indexedDB: IDBFactory,
|
private indexedDB: IDBFactory,
|
||||||
private logger: ConsoleLogger,
|
private logger: ConsoleLogger,
|
||||||
) {
|
) {
|
||||||
this.id = "instance-" + Math.random() + Date.now();
|
this.id = "instance-" + randomString(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -58,7 +58,7 @@ exports[`MLocationBody <MLocationBody> without error renders map correctly 1`] =
|
||||||
permalinkCreator={Object {}}
|
permalinkCreator={Object {}}
|
||||||
>
|
>
|
||||||
<LocationBodyContent
|
<LocationBodyContent
|
||||||
mapId="mx_MLocationBody_$2_1f9acffa"
|
mapId="mx_MLocationBody_$2_HHHHHHHH"
|
||||||
mxEvent={
|
mxEvent={
|
||||||
Object {
|
Object {
|
||||||
"content": Object {
|
"content": Object {
|
||||||
|
@ -102,18 +102,18 @@ exports[`MLocationBody <MLocationBody> without error renders map correctly 1`] =
|
||||||
<Map
|
<Map
|
||||||
centerGeoUri="geo:51.5076,-0.1276"
|
centerGeoUri="geo:51.5076,-0.1276"
|
||||||
className="mx_MLocationBody_map"
|
className="mx_MLocationBody_map"
|
||||||
id="mx_MLocationBody_$2_1f9acffa"
|
id="mx_MLocationBody_$2_HHHHHHHH"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
onError={[Function]}
|
onError={[Function]}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className="mx_Map mx_MLocationBody_map"
|
className="mx_Map mx_MLocationBody_map"
|
||||||
id="mx_Map_mx_MLocationBody_$2_1f9acffa"
|
id="mx_Map_mx_MLocationBody_$2_HHHHHHHH"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
>
|
>
|
||||||
<SmartMarker
|
<SmartMarker
|
||||||
geoUri="geo:51.5076,-0.1276"
|
geoUri="geo:51.5076,-0.1276"
|
||||||
id="mx_MLocationBody_$2_1f9acffa-marker"
|
id="mx_MLocationBody_$2_HHHHHHHH-marker"
|
||||||
map={
|
map={
|
||||||
MockMap {
|
MockMap {
|
||||||
"_events": Object {
|
"_events": Object {
|
||||||
|
@ -165,11 +165,11 @@ exports[`MLocationBody <MLocationBody> without error renders map correctly 1`] =
|
||||||
>
|
>
|
||||||
<span>
|
<span>
|
||||||
<ForwardRef
|
<ForwardRef
|
||||||
id="mx_MLocationBody_$2_1f9acffa-marker"
|
id="mx_MLocationBody_$2_HHHHHHHH-marker"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className="mx_Marker mx_Marker_defaultColor"
|
className="mx_Marker mx_Marker_defaultColor"
|
||||||
id="mx_MLocationBody_$2_1f9acffa-marker"
|
id="mx_MLocationBody_$2_HHHHHHHH-marker"
|
||||||
>
|
>
|
||||||
<OptionalTooltip>
|
<OptionalTooltip>
|
||||||
<div
|
<div
|
||||||
|
|
Loading…
Reference in a new issue