Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into t3chguy/feat/room-list-widgets
Conflicts: src/components/views/elements/AppTile.js src/utils/WidgetUtils.ts
This commit is contained in:
commit
bec1d718e0
200 changed files with 7568 additions and 5549 deletions
|
@ -19,9 +19,13 @@ import {MatrixClientPeg} from '../MatrixClientPeg';
|
|||
const E2EE_WK_KEY = "io.element.e2ee";
|
||||
const E2EE_WK_KEY_DEPRECATED = "im.vector.riot.e2ee";
|
||||
|
||||
/* eslint-disable camelcase */
|
||||
export interface IE2EEWellKnown {
|
||||
default?: boolean;
|
||||
secure_backup_required?: boolean;
|
||||
secure_backup_setup_methods?: SecureBackupSetupMethod[];
|
||||
}
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
export function getE2EEWellKnown(): IE2EEWellKnown {
|
||||
const clientWellKnown = MatrixClientPeg.get().getClientWellKnown();
|
||||
|
@ -38,3 +42,27 @@ export function isSecureBackupRequired(): boolean {
|
|||
const wellKnown = getE2EEWellKnown();
|
||||
return wellKnown && wellKnown["secure_backup_required"] === true;
|
||||
}
|
||||
|
||||
export enum SecureBackupSetupMethod {
|
||||
Key = "key",
|
||||
Passphrase = "passphrase",
|
||||
}
|
||||
|
||||
export function getSecureBackupSetupMethods(): SecureBackupSetupMethod[] {
|
||||
const wellKnown = getE2EEWellKnown();
|
||||
if (
|
||||
!wellKnown ||
|
||||
!wellKnown["secure_backup_setup_methods"] ||
|
||||
!wellKnown["secure_backup_setup_methods"].length ||
|
||||
!(
|
||||
wellKnown["secure_backup_setup_methods"].includes(SecureBackupSetupMethod.Key) ||
|
||||
wellKnown["secure_backup_setup_methods"].includes(SecureBackupSetupMethod.Passphrase)
|
||||
)
|
||||
) {
|
||||
return [
|
||||
SecureBackupSetupMethod.Key,
|
||||
SecureBackupSetupMethod.Passphrase,
|
||||
];
|
||||
}
|
||||
return wellKnown["secure_backup_setup_methods"];
|
||||
}
|
||||
|
|
|
@ -26,18 +26,18 @@ import WidgetEchoStore from '../stores/WidgetEchoStore';
|
|||
import SettingsStore from "../settings/SettingsStore";
|
||||
import ActiveWidgetStore from "../stores/ActiveWidgetStore";
|
||||
import {IntegrationManagers} from "../integrations/IntegrationManagers";
|
||||
import {Capability} from "../widgets/WidgetApi";
|
||||
import {Room} from "matrix-js-sdk/src/models/room";
|
||||
import {WidgetType} from "../widgets/WidgetType";
|
||||
import {objectClone} from "./objects";
|
||||
import {_t} from "../languageHandler";
|
||||
import {IApp} from "../stores/WidgetStore";
|
||||
import {MatrixCapabilities} from "matrix-widget-api";
|
||||
import {IApp} from "../stores/WidgetStore"; // TODO @@
|
||||
|
||||
// How long we wait for the state event echo to come back from the server
|
||||
// before waitFor[Room/User]Widget rejects its promise
|
||||
const WIDGET_WAIT_TIME = 20000;
|
||||
|
||||
export interface IWidget {
|
||||
export interface IWidget { // TODO @@
|
||||
id: string;
|
||||
type: string;
|
||||
sender: string;
|
||||
|
@ -447,15 +447,14 @@ export default class WidgetUtils {
|
|||
static getCapWhitelistForAppTypeInRoomId(appType: string, roomId: string): Capability[] {
|
||||
const enableScreenshots = SettingsStore.getValue("enableWidgetScreenshots", roomId);
|
||||
|
||||
const capWhitelist = enableScreenshots ? [Capability.Screenshot] : [];
|
||||
const capWhitelist = enableScreenshots ? [MatrixCapabilities.Screenshots] : [];
|
||||
|
||||
// Obviously anyone that can add a widget can claim it's a jitsi widget,
|
||||
// so this doesn't really offer much over the set of domains we load
|
||||
// widgets from at all, but it probably makes sense for sanity.
|
||||
if (WidgetType.JITSI.matches(appType)) {
|
||||
capWhitelist.push(Capability.AlwaysOnScreen);
|
||||
capWhitelist.push(MatrixCapabilities.AlwaysOnScreen);
|
||||
}
|
||||
capWhitelist.push(Capability.ReceiveTerminate);
|
||||
|
||||
return capWhitelist;
|
||||
}
|
||||
|
@ -526,16 +525,4 @@ export default class WidgetUtils {
|
|||
IntegrationManagers.sharedInstance().getPrimaryManager().open(room, 'type_' + app.type, app.id);
|
||||
}
|
||||
}
|
||||
|
||||
static snapshotWidget(app: IApp): void {
|
||||
console.log("Requesting widget snapshot");
|
||||
ActiveWidgetStore.getWidgetMessaging(app.id).getScreenshot().catch((err) => {
|
||||
console.error("Failed to get screenshot", err);
|
||||
}).then((screenshot) => {
|
||||
dis.dispatch({
|
||||
action: 'picture_snapshot',
|
||||
file: screenshot,
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
export function hueToRGB(h, s, l) {
|
||||
const c = s * (1 - Math.abs(2 * l - 1));
|
||||
const x = c * (1 - Math.abs((h / 60) % 2 - 1));
|
||||
const m = l - c / 2;
|
||||
|
||||
let r = 0;
|
||||
let g = 0;
|
||||
let b = 0;
|
||||
|
||||
if (0 <= h && h < 60) {
|
||||
r = c;
|
||||
g = x;
|
||||
b = 0;
|
||||
} else if (60 <= h && h < 120) {
|
||||
r = x;
|
||||
g = c;
|
||||
b = 0;
|
||||
} else if (120 <= h && h < 180) {
|
||||
r = 0;
|
||||
g = c;
|
||||
b = x;
|
||||
} else if (180 <= h && h < 240) {
|
||||
r = 0;
|
||||
g = x;
|
||||
b = c;
|
||||
} else if (240 <= h && h < 300) {
|
||||
r = x;
|
||||
g = 0;
|
||||
b = c;
|
||||
} else if (300 <= h && h < 360) {
|
||||
r = c;
|
||||
g = 0;
|
||||
b = x;
|
||||
}
|
||||
|
||||
return [Math.round((r + m) * 255), Math.round((g + m) * 255), Math.round((b + m) * 255)];
|
||||
}
|
||||
|
||||
|
||||
export function textToHtmlRainbow(str) {
|
||||
const frequency = 360 / str.length;
|
||||
|
||||
return Array.from(str).map((c, i) => {
|
||||
const [r, g, b] = hueToRGB(i * frequency, 1.0, 0.5);
|
||||
return '<font color="#' +
|
||||
r.toString(16).padStart(2, "0") +
|
||||
g.toString(16).padStart(2, "0") +
|
||||
b.toString(16).padStart(2, "0") +
|
||||
'">' + c + '</font>';
|
||||
}).join("");
|
||||
}
|
88
src/utils/colour.ts
Normal file
88
src/utils/colour.ts
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
export function textToHtmlRainbow(str: string): string {
|
||||
const frequency = (2 * Math.PI) / str.length;
|
||||
|
||||
return Array.from(str)
|
||||
.map((c, i) => {
|
||||
if (c === " ") {
|
||||
return c;
|
||||
}
|
||||
const [a, b] = generateAB(i * frequency, 1);
|
||||
const [red, green, blue] = labToRGB(75, a, b);
|
||||
return (
|
||||
'<font color="#' +
|
||||
red.toString(16).padStart(2, "0") +
|
||||
green.toString(16).padStart(2, "0") +
|
||||
blue.toString(16).padStart(2, "0") +
|
||||
'">' +
|
||||
c +
|
||||
"</font>"
|
||||
);
|
||||
})
|
||||
.join("");
|
||||
}
|
||||
|
||||
function generateAB(hue: number, chroma: number): [number, number] {
|
||||
const a = chroma * 127 * Math.cos(hue);
|
||||
const b = chroma * 127 * Math.sin(hue);
|
||||
|
||||
return [a, b];
|
||||
}
|
||||
|
||||
function labToRGB(l: number, a: number, b: number): [number, number, number] {
|
||||
// https://en.wikipedia.org/wiki/CIELAB_color_space#Reverse_transformation
|
||||
// https://en.wikipedia.org/wiki/SRGB#The_forward_transformation_(CIE_XYZ_to_sRGB)
|
||||
|
||||
// Convert CIELAB to CIEXYZ (D65)
|
||||
let y = (l + 16) / 116;
|
||||
const x = adjustXYZ(y + a / 500) * 0.9505;
|
||||
const z = adjustXYZ(y - b / 200) * 1.089;
|
||||
|
||||
y = adjustXYZ(y);
|
||||
|
||||
// Linear transformation from CIEXYZ to RGB
|
||||
const red = 3.24096994 * x - 1.53738318 * y - 0.49861076 * z;
|
||||
const green = -0.96924364 * x + 1.8759675 * y + 0.04155506 * z;
|
||||
const blue = 0.05563008 * x - 0.20397696 * y + 1.05697151 * z;
|
||||
|
||||
return [adjustRGB(red), adjustRGB(green), adjustRGB(blue)];
|
||||
}
|
||||
|
||||
function adjustXYZ(v: number): number {
|
||||
if (v > 0.2069) {
|
||||
return Math.pow(v, 3);
|
||||
}
|
||||
return 0.1284 * v - 0.01771;
|
||||
}
|
||||
|
||||
function gammaCorrection(v: number): number {
|
||||
// Non-linear transformation to sRGB
|
||||
if (v <= 0.0031308) {
|
||||
return 12.92 * v;
|
||||
}
|
||||
return 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
|
||||
}
|
||||
|
||||
function adjustRGB(v: number): number {
|
||||
const corrected = gammaCorrection(v);
|
||||
|
||||
// Limits number between 0 and 1
|
||||
const limited = Math.min(Math.max(corrected, 0), 1);
|
||||
|
||||
return Math.round(limited * 255);
|
||||
}
|
21
src/utils/iterables.ts
Normal file
21
src/utils/iterables.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { arrayUnion } from "./arrays";
|
||||
|
||||
export function iterableUnion<T>(a: Iterable<T>, b: Iterable<T>): Iterable<T> {
|
||||
return arrayUnion(Array.from(a), Array.from(b));
|
||||
}
|
|
@ -44,3 +44,26 @@ export function mapKeyChanges<K, V>(a: Map<K, V>, b: Map<K, V>): K[] {
|
|||
const diff = mapDiff(a, b);
|
||||
return arrayMerge(diff.removed, diff.added, diff.changed);
|
||||
}
|
||||
|
||||
/**
|
||||
* A Map<K, V> with added utility.
|
||||
*/
|
||||
export class EnhancedMap<K, V> extends Map<K, V> {
|
||||
public constructor(entries?: Iterable<[K, V]>) {
|
||||
super(entries);
|
||||
}
|
||||
|
||||
public getOrCreate(key: K, def: V): V {
|
||||
if (this.has(key)) {
|
||||
return this.get(key);
|
||||
}
|
||||
this.set(key, def);
|
||||
return def;
|
||||
}
|
||||
|
||||
public remove(key: K): V {
|
||||
const v = this.get(key);
|
||||
this.delete(key);
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue