Fix typescript errors

This commit is contained in:
RMidhunSuresh 2023-01-24 18:08:29 +05:30
parent 26476324dc
commit 374fb08c98
No known key found for this signature in database
3 changed files with 21 additions and 13 deletions

View File

@ -17,14 +17,15 @@ limitations under the License.
import {ErrorReportViewModel} from "../../ErrorReportViewModel"; import {ErrorReportViewModel} from "../../ErrorReportViewModel";
import {Options as BaseOptions} from "../../ViewModel"; import {Options as BaseOptions} from "../../ViewModel";
import type {Session} from "../../../matrix/Session.js"; import type {Session} from "../../../matrix/Session.js";
import {SegmentType} from "../../navigation";
export type BaseClassOptions = { export type BaseClassOptions<N extends object = SegmentType> = {
dismiss: () => void; dismiss: () => void;
session: Session; session: Session;
} & BaseOptions; } & BaseOptions<N>;
export abstract class BaseToastNotificationViewModel<T extends BaseClassOptions = BaseClassOptions> extends ErrorReportViewModel<T> { export abstract class BaseToastNotificationViewModel<N extends object = SegmentType, O extends BaseClassOptions<N> = BaseClassOptions<N>> extends ErrorReportViewModel<N, O> {
constructor(options: T) { constructor(options: O) {
super(options); super(options);
} }

View File

@ -18,15 +18,21 @@ import type {Room} from "../../../matrix/room/Room.js";
import {IAvatarContract, avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar"; import {IAvatarContract, avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar";
import {LocalMedia} from "../../../matrix/calls/LocalMedia"; import {LocalMedia} from "../../../matrix/calls/LocalMedia";
import {BaseClassOptions, BaseToastNotificationViewModel} from "./BaseToastNotificationViewModel"; import {BaseClassOptions, BaseToastNotificationViewModel} from "./BaseToastNotificationViewModel";
import {SegmentType} from "../../navigation";
type Options = { type Options<N extends MinimumNeededSegmentType = SegmentType> = {
call: GroupCall; call: GroupCall;
room: Room; room: Room;
} & BaseClassOptions; } & BaseClassOptions<N>;
// Since we access the room segment below, the segment type
// needs to at least contain the room segment!
type MinimumNeededSegmentType = {
"room": string;
};
export class CallToastNotificationViewModel extends BaseToastNotificationViewModel<Options> implements IAvatarContract { export class CallToastNotificationViewModel<N extends MinimumNeededSegmentType = SegmentType, O extends Options<N> = Options<N>> extends BaseToastNotificationViewModel<N, O> implements IAvatarContract {
constructor(options: Options) { constructor(options: O) {
super(options); super(options);
this.track( this.track(
this.call.members.subscribe({ this.call.members.subscribe({
@ -46,8 +52,8 @@ export class CallToastNotificationViewModel extends BaseToastNotificationViewMod
); );
// Dismiss the toast if the room is opened manually // Dismiss the toast if the room is opened manually
this.track( this.track(
this.navigation.observe("room").subscribe(roomId => { this.navigation.observe("room").subscribe((roomId) => {
if (roomId === this.call.roomId) { if ((roomId as unknown as string) === this.call.roomId) {
this.dismiss(); this.dismiss();
} }
})); }));
@ -58,8 +64,8 @@ export class CallToastNotificationViewModel extends BaseToastNotificationViewMod
const stream = await this.platform.mediaDevices.getMediaTracks(false, true); const stream = await this.platform.mediaDevices.getMediaTracks(false, true);
const localMedia = new LocalMedia().withUserMedia(stream); const localMedia = new LocalMedia().withUserMedia(stream);
await this.call.join(localMedia, log); await this.call.join(localMedia, log);
const url = this.urlCreator.openRoomActionUrl(this.call.roomId); const url = this.urlRouter.openRoomActionUrl(this.call.roomId);
this.urlCreator.pushUrl(url); this.urlRouter.pushUrl(url);
}); });
} }

View File

@ -20,12 +20,13 @@ import {ViewModel, Options as BaseOptions} from "../../ViewModel";
import type {GroupCall} from "../../../matrix/calls/group/GroupCall"; import type {GroupCall} from "../../../matrix/calls/group/GroupCall";
import type {Room} from "../../../matrix/room/Room.js"; import type {Room} from "../../../matrix/room/Room.js";
import type {Session} from "../../../matrix/Session.js"; import type {Session} from "../../../matrix/Session.js";
import type {SegmentType} from "../../navigation";
type Options = { type Options = {
session: Session; session: Session;
} & BaseOptions; } & BaseOptions;
export class ToastCollectionViewModel extends ViewModel<Options> { export class ToastCollectionViewModel extends ViewModel<SegmentType, Options> {
public readonly toastViewModels: ObservableArray<CallToastNotificationViewModel> = new ObservableArray(); public readonly toastViewModels: ObservableArray<CallToastNotificationViewModel> = new ObservableArray();
constructor(options: Options) { constructor(options: Options) {