Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit c30b263

Browse files
weeman1337RiotRobot
authored andcommitted
Changes for v3.69.0
1 parent 2d1d1fb commit c30b263

File tree

13 files changed

+175
-121
lines changed

13 files changed

+175
-121
lines changed

src/components/structures/MessagePanel.tsx

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
235235
// This is recomputed on each render. It's only stored on the component
236236
// for ease of passing the data around since it's computed in one pass
237237
// over all events.
238-
private readReceiptsByEvent: Record<string, IReadReceiptProps[]> = {};
238+
private readReceiptsByEvent: Map<string, IReadReceiptProps[]> = new Map();
239239

240240
// Track read receipts by user ID. For each user ID we've ever shown a
241241
// a read receipt for, we store an object:
@@ -254,7 +254,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
254254
// This is recomputed on each render, using the data from the previous
255255
// render as our fallback for any user IDs we can't match a receipt to a
256256
// displayed event in the current render cycle.
257-
private readReceiptsByUserId: Record<string, IReadReceiptForUser> = {};
257+
private readReceiptsByUserId: Map<string, IReadReceiptForUser> = new Map();
258258

259259
private readonly _showHiddenEvents: boolean;
260260
private isMounted = false;
@@ -624,7 +624,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
624624
// Note: the EventTile might still render a "sent/sending receipt" independent of
625625
// this information. When not providing read receipt information, the tile is likely
626626
// to assume that sent receipts are to be shown more often.
627-
this.readReceiptsByEvent = {};
627+
this.readReceiptsByEvent = new Map();
628628
if (this.props.showReadReceipts) {
629629
this.readReceiptsByEvent = this.getReadReceiptsByShownEvent();
630630
}
@@ -727,7 +727,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
727727
const eventId = mxEv.getId();
728728
const highlight = eventId === this.props.highlightedEventId;
729729

730-
const readReceipts = this.readReceiptsByEvent[eventId];
730+
const readReceipts = this.readReceiptsByEvent.get(eventId);
731731

732732
let isLastSuccessful = false;
733733
const isSentState = (s: EventStatus): boolean => !s || s === EventStatus.SENT;
@@ -846,17 +846,11 @@ export default class MessagePanel extends React.Component<IProps, IState> {
846846
// Get an object that maps from event ID to a list of read receipts that
847847
// should be shown next to that event. If a hidden event has read receipts,
848848
// they are folded into the receipts of the last shown event.
849-
private getReadReceiptsByShownEvent(): Record<string, IReadReceiptProps[]> {
850-
const receiptsByEvent: Record<string, IReadReceiptProps[]> = {};
851-
const receiptsByUserId: Record<
852-
string,
853-
{
854-
lastShownEventId: string;
855-
receipt: IReadReceiptProps;
856-
}
857-
> = {};
849+
private getReadReceiptsByShownEvent(): Map<string, IReadReceiptProps[]> {
850+
const receiptsByEvent: Map<string, IReadReceiptProps[]> = new Map();
851+
const receiptsByUserId: Map<string, IReadReceiptForUser> = new Map();
858852

859-
let lastShownEventId;
853+
let lastShownEventId: string;
860854
for (const event of this.props.events) {
861855
if (this.shouldShowEvent(event)) {
862856
lastShownEventId = event.getId();
@@ -865,9 +859,9 @@ export default class MessagePanel extends React.Component<IProps, IState> {
865859
continue;
866860
}
867861

868-
const existingReceipts = receiptsByEvent[lastShownEventId] || [];
862+
const existingReceipts = receiptsByEvent.get(lastShownEventId) || [];
869863
const newReceipts = this.getReadReceiptsForEvent(event);
870-
receiptsByEvent[lastShownEventId] = existingReceipts.concat(newReceipts);
864+
receiptsByEvent.set(lastShownEventId, existingReceipts.concat(newReceipts));
871865

872866
// Record these receipts along with their last shown event ID for
873867
// each associated user ID.
@@ -885,21 +879,21 @@ export default class MessagePanel extends React.Component<IProps, IState> {
885879
// someone which had one in the last. By looking through our previous
886880
// mapping of receipts by user ID, we can cover recover any receipts
887881
// that would have been lost by using the same event ID from last time.
888-
for (const userId in this.readReceiptsByUserId) {
889-
if (receiptsByUserId[userId]) {
882+
for (const userId of this.readReceiptsByUserId.keys()) {
883+
if (receiptsByUserId.get(userId)) {
890884
continue;
891885
}
892-
const { lastShownEventId, receipt } = this.readReceiptsByUserId[userId];
893-
const existingReceipts = receiptsByEvent[lastShownEventId] || [];
894-
receiptsByEvent[lastShownEventId] = existingReceipts.concat(receipt);
895-
receiptsByUserId[userId] = { lastShownEventId, receipt };
886+
const { lastShownEventId, receipt } = this.readReceiptsByUserId.get(userId);
887+
const existingReceipts = receiptsByEvent.get(lastShownEventId) || [];
888+
receiptsByEvent.set(lastShownEventId, existingReceipts.concat(receipt));
889+
receiptsByUserId.set(userId, { lastShownEventId, receipt });
896890
}
897891
this.readReceiptsByUserId = receiptsByUserId;
898892

899893
// After grouping receipts by shown events, do another pass to sort each
900894
// receipt list.
901-
for (const eventId in receiptsByEvent) {
902-
receiptsByEvent[eventId].sort((r1, r2) => {
895+
for (const receipts of receiptsByEvent.values()) {
896+
receipts.sort((r1, r2) => {
903897
return r2.ts - r1.ts;
904898
});
905899
}

src/components/views/dialogs/devtools/AccountData.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const RoomAccountDataEventEditor: React.FC<IEditorProps> = ({ mxEvent, on
5151
};
5252

5353
interface IProps extends IDevtoolsProps {
54-
events: Record<string, MatrixEvent>;
54+
events: Map<string, MatrixEvent>;
5555
Editor: React.FC<IEditorProps>;
5656
actionLabel: string;
5757
}
@@ -74,7 +74,7 @@ const BaseAccountDataExplorer: React.FC<IProps> = ({ events, Editor, actionLabel
7474
return (
7575
<BaseTool onBack={onBack} actionLabel={actionLabel} onAction={onAction}>
7676
<FilteredList query={query} onChange={setQuery}>
77-
{Object.entries(events).map(([eventType, ev]) => {
77+
{Array.from(events.entries()).map(([eventType, ev]) => {
7878
const onClick = (): void => {
7979
setEvent(ev);
8080
};

src/languageHandler.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import counterpart from "counterpart";
2121
import React from "react";
2222
import { logger } from "matrix-js-sdk/src/logger";
2323
import { Optional } from "matrix-events-sdk";
24+
import { MapWithDefault, safeSet } from "matrix-js-sdk/src/utils";
2425

2526
import SettingsStore from "./settings/SettingsStore";
2627
import PlatformPeg from "./PlatformPeg";
@@ -629,21 +630,16 @@ export class CustomTranslationOptions {
629630
function doRegisterTranslations(customTranslations: ICustomTranslations): void {
630631
// We convert the operator-friendly version into something counterpart can
631632
// consume.
632-
const langs: {
633-
// same structure, just flipped key order
634-
[lang: string]: {
635-
[str: string]: string;
636-
};
637-
} = {};
633+
// Map: lang → Record: string → translation
634+
const langs: MapWithDefault<string, Record<string, string>> = new MapWithDefault(() => ({}));
638635
for (const [str, translations] of Object.entries(customTranslations)) {
639636
for (const [lang, newStr] of Object.entries(translations)) {
640-
if (!langs[lang]) langs[lang] = {};
641-
langs[lang][str] = newStr;
637+
safeSet(langs.getOrCreate(lang), str, newStr);
642638
}
643639
}
644640

645641
// Finally, tell counterpart about our translations
646-
for (const [lang, translations] of Object.entries(langs)) {
642+
for (const [lang, translations] of langs) {
647643
counterpart.registerTranslations(lang, translations);
648644
}
649645
}

src/modules/ModuleRunner.ts

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

17+
import { safeSet } from "matrix-js-sdk/src/utils";
1718
import { TranslationStringsObject } from "@matrix-org/react-sdk-module-api/lib/types/translations";
1819
import { AnyLifecycle } from "@matrix-org/react-sdk-module-api/lib/lifecycles/types";
1920

2021
import { AppModule } from "./AppModule";
2122
import { ModuleFactory } from "./ModuleFactory";
23+
2224
import "./ModuleComponents";
2325

2426
/**
@@ -53,9 +55,10 @@ export class ModuleRunner {
5355
if (!i18n) continue;
5456

5557
for (const [lang, strings] of Object.entries(i18n)) {
56-
if (!merged[lang]) merged[lang] = {};
58+
safeSet(merged, lang, merged[lang] || {});
59+
5760
for (const [str, val] of Object.entries(strings)) {
58-
merged[lang][str] = val;
61+
safeSet(merged[lang], str, val);
5962
}
6063
}
6164
}

src/settings/handlers/RoomDeviceSettingsHandler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
1717

18+
import { safeSet } from "matrix-js-sdk/src/utils";
19+
1820
import { SettingLevel } from "../SettingLevel";
1921
import { WatchManager } from "../WatchManager";
2022
import AbstractLocalStorageSettingsHandler from "./AbstractLocalStorageSettingsHandler";
@@ -48,7 +50,7 @@ export default class RoomDeviceSettingsHandler extends AbstractLocalStorageSetti
4850
let value = this.read("mx_local_settings");
4951
if (!value) value = {};
5052
if (!value["blacklistUnverifiedDevicesPerRoom"]) value["blacklistUnverifiedDevicesPerRoom"] = {};
51-
value["blacklistUnverifiedDevicesPerRoom"][roomId] = newValue;
53+
safeSet(value["blacklistUnverifiedDevicesPerRoom"], roomId, newValue);
5254
this.setObject("mx_local_settings", value);
5355
this.watchers.notifyUpdate(settingName, roomId, SettingLevel.ROOM_DEVICE, newValue);
5456
return Promise.resolve();

src/stores/AutoRageshakeStore.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ export default class AutoRageshakeStore extends AsyncStoreWithClient<IState> {
135135
...eventInfo,
136136
recipient_rageshake: rageshakeURL,
137137
};
138-
this.matrixClient.sendToDevice(AUTO_RS_REQUEST, {
139-
[messageContent.user_id]: { [messageContent.device_id]: messageContent },
140-
});
138+
this.matrixClient.sendToDevice(
139+
AUTO_RS_REQUEST,
140+
new Map([["messageContent.user_id", new Map([[messageContent.device_id, messageContent]])]]),
141+
);
141142
}
142143
}
143144

src/stores/widgets/StopGapWidgetDriver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
275275
if (deviceId === "*") {
276276
// Send the message to all devices we have keys for
277277
await client.encryptAndSendToDevices(
278-
Object.values(deviceInfoMap[userId]).map((deviceInfo) => ({
278+
Array.from(deviceInfoMap.get(userId).values()).map((deviceInfo) => ({
279279
userId,
280280
deviceInfo,
281281
})),
@@ -284,7 +284,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
284284
} else {
285285
// Send the message to a specific device
286286
await client.encryptAndSendToDevices(
287-
[{ userId, deviceInfo: deviceInfoMap[userId][deviceId] }],
287+
[{ userId, deviceInfo: deviceInfoMap.get(userId).get(deviceId) }],
288288
content,
289289
);
290290
}

0 commit comments

Comments
 (0)