Post-merge tidy up

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/21833/head
Michael Telatynski 2020-10-19 20:56:41 +01:00
parent bec1d718e0
commit 5ee0262da2
2 changed files with 12 additions and 20 deletions

View File

@ -16,6 +16,7 @@ limitations under the License.
import { Room } from "matrix-js-sdk/src/models/room"; import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { IWidget } from "matrix-widget-api";
import { ActionPayload } from "../dispatcher/payloads"; import { ActionPayload } from "../dispatcher/payloads";
import { AsyncStoreWithClient } from "./AsyncStoreWithClient"; import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
@ -30,18 +31,9 @@ import {UPDATE_EVENT} from "./AsyncStore";
interface IState {} interface IState {}
export interface IApp { export interface IApp extends IWidget {
id: string;
url: string;
type: string;
name: string;
roomId: string; roomId: string;
eventId: string; eventId: string;
creatorUserId: string;
waitForIframeLoad?: boolean;
data?: {
title?: string;
};
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
avatar_url: string; // MSC2765 https://github.com/matrix-org/matrix-doc/pull/2765 avatar_url: string; // MSC2765 https://github.com/matrix-org/matrix-doc/pull/2765
} }

View File

@ -30,14 +30,14 @@ import {Room} from "matrix-js-sdk/src/models/room";
import {WidgetType} from "../widgets/WidgetType"; import {WidgetType} from "../widgets/WidgetType";
import {objectClone} from "./objects"; import {objectClone} from "./objects";
import {_t} from "../languageHandler"; import {_t} from "../languageHandler";
import {MatrixCapabilities} from "matrix-widget-api"; import {Capability, IWidgetData, MatrixCapabilities} from "matrix-widget-api";
import {IApp} from "../stores/WidgetStore"; // TODO @@ import {IApp} from "../stores/WidgetStore"; // TODO @@
// How long we wait for the state event echo to come back from the server // How long we wait for the state event echo to come back from the server
// before waitFor[Room/User]Widget rejects its promise // before waitFor[Room/User]Widget rejects its promise
const WIDGET_WAIT_TIME = 20000; const WIDGET_WAIT_TIME = 20000;
export interface IWidget { // TODO @@ export interface IWidgetEvent {
id: string; id: string;
type: string; type: string;
sender: string; sender: string;
@ -230,7 +230,7 @@ export default class WidgetUtils {
widgetType: WidgetType, widgetType: WidgetType,
widgetUrl: string, widgetUrl: string,
widgetName: string, widgetName: string,
widgetData: object, widgetData: IWidgetData,
) { ) {
const content = { const content = {
type: widgetType.preferred, type: widgetType.preferred,
@ -332,7 +332,7 @@ export default class WidgetUtils {
* Get user specific widgets (not linked to a specific room) * Get user specific widgets (not linked to a specific room)
* @return {object} Event content object containing current / active user widgets * @return {object} Event content object containing current / active user widgets
*/ */
static getUserWidgets(): Record<string, IWidget> { static getUserWidgets(): Record<string, IWidgetEvent> {
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
if (!client) { if (!client) {
throw new Error('User not logged in'); throw new Error('User not logged in');
@ -348,7 +348,7 @@ export default class WidgetUtils {
* Get user specific widgets (not linked to a specific room) as an array * Get user specific widgets (not linked to a specific room) as an array
* @return {[object]} Array containing current / active user widgets * @return {[object]} Array containing current / active user widgets
*/ */
static getUserWidgetsArray(): IWidget[] { static getUserWidgetsArray(): IWidgetEvent[] {
return Object.values(WidgetUtils.getUserWidgets()); return Object.values(WidgetUtils.getUserWidgets());
} }
@ -356,7 +356,7 @@ export default class WidgetUtils {
* Get active stickerpicker widgets (stickerpickers are user widgets by nature) * Get active stickerpicker widgets (stickerpickers are user widgets by nature)
* @return {[object]} Array containing current / active stickerpicker widgets * @return {[object]} Array containing current / active stickerpicker widgets
*/ */
static getStickerpickerWidgets(): IWidget[] { static getStickerpickerWidgets(): IWidgetEvent[] {
const widgets = WidgetUtils.getUserWidgetsArray(); const widgets = WidgetUtils.getUserWidgetsArray();
return widgets.filter((widget) => widget.content && widget.content.type === "m.stickerpicker"); return widgets.filter((widget) => widget.content && widget.content.type === "m.stickerpicker");
} }
@ -365,12 +365,12 @@ export default class WidgetUtils {
* Get all integration manager widgets for this user. * Get all integration manager widgets for this user.
* @returns {Object[]} An array of integration manager user widgets. * @returns {Object[]} An array of integration manager user widgets.
*/ */
static getIntegrationManagerWidgets(): IWidget[] { static getIntegrationManagerWidgets(): IWidgetEvent[] {
const widgets = WidgetUtils.getUserWidgetsArray(); const widgets = WidgetUtils.getUserWidgetsArray();
return widgets.filter(w => w.content && w.content.type === "m.integration_manager"); return widgets.filter(w => w.content && w.content.type === "m.integration_manager");
} }
static getRoomWidgetsOfType(room: Room, type: WidgetType): IWidget[] { static getRoomWidgetsOfType(room: Room, type: WidgetType): IWidgetEvent[] {
const widgets = WidgetUtils.getRoomWidgets(room); const widgets = WidgetUtils.getRoomWidgets(room);
return (widgets || []).filter(w => { return (widgets || []).filter(w => {
const content = w.getContent(); const content = w.getContent();
@ -385,7 +385,7 @@ export default class WidgetUtils {
} }
const widgets = client.getAccountData('m.widgets'); const widgets = client.getAccountData('m.widgets');
if (!widgets) return; if (!widgets) return;
const userWidgets: IWidget[] = widgets.getContent() || {}; const userWidgets: IWidgetEvent[] = widgets.getContent() || {};
Object.entries(userWidgets).forEach(([key, widget]) => { Object.entries(userWidgets).forEach(([key, widget]) => {
if (widget.content && widget.content.type === "m.integration_manager") { if (widget.content && widget.content.type === "m.integration_manager") {
delete userWidgets[key]; delete userWidgets[key];
@ -415,7 +415,7 @@ export default class WidgetUtils {
} }
const widgets = client.getAccountData('m.widgets'); const widgets = client.getAccountData('m.widgets');
if (!widgets) return; if (!widgets) return;
const userWidgets: Record<string, IWidget> = widgets.getContent() || {}; const userWidgets: Record<string, IWidgetEvent> = widgets.getContent() || {};
Object.entries(userWidgets).forEach(([key, widget]) => { Object.entries(userWidgets).forEach(([key, widget]) => {
if (widget.content && widget.content.type === 'm.stickerpicker') { if (widget.content && widget.content.type === 'm.stickerpicker') {
delete userWidgets[key]; delete userWidgets[key];