Changes for v3.69.0
This commit is contained in:
committed by
RiotRobot
parent
2d1d1fb585
commit
c30b2637c5
@@ -135,9 +135,10 @@ export default class AutoRageshakeStore extends AsyncStoreWithClient<IState> {
|
||||
...eventInfo,
|
||||
recipient_rageshake: rageshakeURL,
|
||||
};
|
||||
this.matrixClient.sendToDevice(AUTO_RS_REQUEST, {
|
||||
[messageContent.user_id]: { [messageContent.device_id]: messageContent },
|
||||
});
|
||||
this.matrixClient.sendToDevice(
|
||||
AUTO_RS_REQUEST,
|
||||
new Map([["messageContent.user_id", new Map([[messageContent.device_id, messageContent]])]]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -275,7 +275,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
||||
if (deviceId === "*") {
|
||||
// Send the message to all devices we have keys for
|
||||
await client.encryptAndSendToDevices(
|
||||
Object.values(deviceInfoMap[userId]).map((deviceInfo) => ({
|
||||
Array.from(deviceInfoMap.get(userId).values()).map((deviceInfo) => ({
|
||||
userId,
|
||||
deviceInfo,
|
||||
})),
|
||||
@@ -284,7 +284,7 @@ export class StopGapWidgetDriver extends WidgetDriver {
|
||||
} else {
|
||||
// Send the message to a specific device
|
||||
await client.encryptAndSendToDevices(
|
||||
[{ userId, deviceInfo: deviceInfoMap[userId][deviceId] }],
|
||||
[{ userId, deviceInfo: deviceInfoMap.get(userId).get(deviceId) }],
|
||||
content,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
|
||||
import { Optional } from "matrix-events-sdk";
|
||||
import { compare } from "matrix-js-sdk/src/utils";
|
||||
import { compare, MapWithDefault, recursiveMapToObject } from "matrix-js-sdk/src/utils";
|
||||
|
||||
import SettingsStore from "../../settings/SettingsStore";
|
||||
import WidgetStore, { IApp } from "../WidgetStore";
|
||||
@@ -92,19 +92,17 @@ export const MAX_PINNED = 3;
|
||||
const MIN_WIDGET_WIDTH_PCT = 10; // 10%
|
||||
const MIN_WIDGET_HEIGHT_PCT = 2; // 2%
|
||||
|
||||
interface ContainerValue {
|
||||
ordered: IApp[];
|
||||
height?: number;
|
||||
distributions?: number[];
|
||||
}
|
||||
|
||||
export class WidgetLayoutStore extends ReadyWatchingStore {
|
||||
private static internalInstance: WidgetLayoutStore;
|
||||
|
||||
private byRoom: {
|
||||
[roomId: string]: Partial<{
|
||||
[container in Container]: {
|
||||
ordered: IApp[];
|
||||
height?: number | null;
|
||||
distributions?: number[];
|
||||
};
|
||||
}>;
|
||||
} = {};
|
||||
|
||||
// Map: room Id → container → ContainerValue
|
||||
private byRoom: MapWithDefault<string, Map<Container, ContainerValue>> = new MapWithDefault(() => new Map());
|
||||
private pinnedRef: string;
|
||||
private layoutRef: string;
|
||||
|
||||
@@ -138,7 +136,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
||||
}
|
||||
|
||||
protected async onNotReady(): Promise<void> {
|
||||
this.byRoom = {};
|
||||
this.byRoom = new MapWithDefault(() => new Map());
|
||||
|
||||
this.matrixClient?.off(RoomStateEvent.Events, this.updateRoomFromState);
|
||||
SettingsStore.unwatchSetting(this.pinnedRef);
|
||||
@@ -147,7 +145,8 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
||||
}
|
||||
|
||||
private updateAllRooms = (): void => {
|
||||
this.byRoom = {};
|
||||
this.byRoom = new MapWithDefault(() => new Map());
|
||||
|
||||
for (const room of this.matrixClient.getVisibleRooms()) {
|
||||
this.recalculateRoom(room);
|
||||
}
|
||||
@@ -180,12 +179,13 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
||||
public recalculateRoom(room: Room): void {
|
||||
const widgets = WidgetStore.instance.getApps(room.roomId);
|
||||
if (!widgets?.length) {
|
||||
this.byRoom[room.roomId] = {};
|
||||
this.byRoom.set(room.roomId, new Map());
|
||||
this.emitFor(room);
|
||||
return;
|
||||
}
|
||||
|
||||
const beforeChanges = JSON.stringify(this.byRoom[room.roomId]);
|
||||
const roomContainers = this.byRoom.getOrCreate(room.roomId);
|
||||
const beforeChanges = JSON.stringify(recursiveMapToObject(roomContainers));
|
||||
|
||||
const layoutEv = room.currentState.getStateEvents(WIDGET_LAYOUT_EVENT_TYPE, "");
|
||||
const legacyPinned = SettingsStore.getValue("Widgets.pinned", room.roomId);
|
||||
@@ -321,33 +321,35 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
||||
}
|
||||
|
||||
// Finally, fill in our cache and update
|
||||
this.byRoom[room.roomId] = {};
|
||||
const newRoomContainers = new Map();
|
||||
this.byRoom.set(room.roomId, newRoomContainers);
|
||||
if (topWidgets.length) {
|
||||
this.byRoom[room.roomId][Container.Top] = {
|
||||
newRoomContainers.set(Container.Top, {
|
||||
ordered: topWidgets,
|
||||
distributions: widths,
|
||||
height: maxHeight,
|
||||
};
|
||||
});
|
||||
}
|
||||
if (rightWidgets.length) {
|
||||
this.byRoom[room.roomId][Container.Right] = {
|
||||
newRoomContainers.set(Container.Right, {
|
||||
ordered: rightWidgets,
|
||||
};
|
||||
});
|
||||
}
|
||||
if (centerWidgets.length) {
|
||||
this.byRoom[room.roomId][Container.Center] = {
|
||||
newRoomContainers.set(Container.Center, {
|
||||
ordered: centerWidgets,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const afterChanges = JSON.stringify(this.byRoom[room.roomId]);
|
||||
const afterChanges = JSON.stringify(recursiveMapToObject(newRoomContainers));
|
||||
|
||||
if (afterChanges !== beforeChanges) {
|
||||
this.emitFor(room);
|
||||
}
|
||||
}
|
||||
|
||||
public getContainerWidgets(room: Optional<Room>, container: Container): IApp[] {
|
||||
return this.byRoom[room?.roomId]?.[container]?.ordered || [];
|
||||
return this.byRoom.get(room?.roomId)?.get(container)?.ordered || [];
|
||||
}
|
||||
|
||||
public isInContainer(room: Optional<Room>, widget: IApp, container: Container): boolean {
|
||||
@@ -367,7 +369,7 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
||||
|
||||
public getResizerDistributions(room: Room, container: Container): string[] {
|
||||
// yes, string.
|
||||
let distributions = this.byRoom[room.roomId]?.[container]?.distributions;
|
||||
let distributions = this.byRoom.get(room.roomId)?.get(container)?.distributions;
|
||||
if (!distributions || distributions.length < 2) return [];
|
||||
|
||||
// The distributor actually expects to be fed N-1 sizes and expands the middle section
|
||||
@@ -396,19 +398,19 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
||||
container: container,
|
||||
width: numbers[i],
|
||||
index: i,
|
||||
height: this.byRoom[room.roomId]?.[container]?.height || MIN_WIDGET_HEIGHT_PCT,
|
||||
height: this.byRoom.get(room.roomId)?.get(container)?.height || MIN_WIDGET_HEIGHT_PCT,
|
||||
};
|
||||
});
|
||||
this.updateUserLayout(room, localLayout);
|
||||
}
|
||||
|
||||
public getContainerHeight(room: Room, container: Container): number | null {
|
||||
return this.byRoom[room.roomId]?.[container]?.height ?? null; // let the default get returned if needed
|
||||
return this.byRoom.get(room.roomId)?.get(container)?.height ?? null; // let the default get returned if needed
|
||||
}
|
||||
|
||||
public setContainerHeight(room: Room, container: Container, height?: number): void {
|
||||
const widgets = this.getContainerWidgets(room, container);
|
||||
const widths = this.byRoom[room.roomId]?.[container]?.distributions;
|
||||
const widths = this.byRoom.get(room.roomId)?.get(container)?.distributions;
|
||||
const localLayout: Record<string, IStoredLayout> = {};
|
||||
widgets.forEach((w, i) => {
|
||||
localLayout[w.id] = {
|
||||
@@ -430,8 +432,8 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
||||
const newIdx = clamp(currentIdx + delta, 0, widgets.length);
|
||||
widgets.splice(newIdx, 0, widget);
|
||||
|
||||
const widths = this.byRoom[room.roomId]?.[container]?.distributions;
|
||||
const height = this.byRoom[room.roomId]?.[container]?.height;
|
||||
const widths = this.byRoom.get(room.roomId)?.get(container)?.distributions;
|
||||
const height = this.byRoom.get(room.roomId)?.get(container)?.height;
|
||||
const localLayout: Record<string, IStoredLayout> = {};
|
||||
widgets.forEach((w, i) => {
|
||||
localLayout[w.id] = {
|
||||
@@ -498,8 +500,8 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
||||
if (container === Container.Top) {
|
||||
const containerWidgets = this.getContainerWidgets(room, container);
|
||||
const idx = containerWidgets.findIndex((w) => w.id === widget.id);
|
||||
const widths = this.byRoom[room.roomId]?.[container]?.distributions;
|
||||
const height = this.byRoom[room.roomId]?.[container]?.height;
|
||||
const widths = this.byRoom.get(room.roomId)?.get(container)?.distributions;
|
||||
const height = this.byRoom.get(room.roomId)?.get(container)?.height;
|
||||
evContent.widgets[widget.id] = {
|
||||
...evContent.widgets[widget.id],
|
||||
height: height ? Math.round(height) : undefined,
|
||||
@@ -512,12 +514,12 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
||||
}
|
||||
|
||||
private getAllWidgets(room: Room): [IApp, Container][] {
|
||||
const containers = this.byRoom[room.roomId];
|
||||
const containers = this.byRoom.get(room.roomId);
|
||||
if (!containers) return [];
|
||||
|
||||
const ret: [IApp, Container][] = [];
|
||||
for (const container in containers) {
|
||||
const widgets = containers[container as Container].ordered;
|
||||
for (const [container, containerValue] of containers) {
|
||||
const widgets = containerValue.ordered;
|
||||
for (const widget of widgets) {
|
||||
ret.push([widget, container as Container]);
|
||||
}
|
||||
@@ -531,12 +533,12 @@ export class WidgetLayoutStore extends ReadyWatchingStore {
|
||||
for (const [widget, container] of allWidgets) {
|
||||
const containerWidgets = this.getContainerWidgets(room, container);
|
||||
const idx = containerWidgets.findIndex((w) => w.id === widget.id);
|
||||
const widths = this.byRoom[room.roomId]?.[container]?.distributions;
|
||||
const widths = this.byRoom.get(room.roomId)?.get(container)?.distributions;
|
||||
if (!newLayout[widget.id]) {
|
||||
newLayout[widget.id] = {
|
||||
container: container,
|
||||
index: idx,
|
||||
height: this.byRoom[room.roomId]?.[container]?.height,
|
||||
height: this.byRoom.get(room.roomId)?.get(container)?.height,
|
||||
width: widths?.[idx],
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user