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 {Options as BaseOptions} from "../../ViewModel";
import type {Session} from "../../../matrix/Session.js";
import {SegmentType} from "../../navigation";
export type BaseClassOptions = {
export type BaseClassOptions<N extends object = SegmentType> = {
dismiss: () => void;
session: Session;
} & BaseOptions;
} & BaseOptions<N>;
export abstract class BaseToastNotificationViewModel<T extends BaseClassOptions = BaseClassOptions> extends ErrorReportViewModel<T> {
constructor(options: T) {
export abstract class BaseToastNotificationViewModel<N extends object = SegmentType, O extends BaseClassOptions<N> = BaseClassOptions<N>> extends ErrorReportViewModel<N, O> {
constructor(options: O) {
super(options);
}

View File

@ -18,15 +18,21 @@ import type {Room} from "../../../matrix/room/Room.js";
import {IAvatarContract, avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar";
import {LocalMedia} from "../../../matrix/calls/LocalMedia";
import {BaseClassOptions, BaseToastNotificationViewModel} from "./BaseToastNotificationViewModel";
import {SegmentType} from "../../navigation";
type Options = {
type Options<N extends MinimumNeededSegmentType = SegmentType> = {
call: GroupCall;
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 {
constructor(options: Options) {
export class CallToastNotificationViewModel<N extends MinimumNeededSegmentType = SegmentType, O extends Options<N> = Options<N>> extends BaseToastNotificationViewModel<N, O> implements IAvatarContract {
constructor(options: O) {
super(options);
this.track(
this.call.members.subscribe({
@ -46,8 +52,8 @@ export class CallToastNotificationViewModel extends BaseToastNotificationViewMod
);
// Dismiss the toast if the room is opened manually
this.track(
this.navigation.observe("room").subscribe(roomId => {
if (roomId === this.call.roomId) {
this.navigation.observe("room").subscribe((roomId) => {
if ((roomId as unknown as string) === this.call.roomId) {
this.dismiss();
}
}));
@ -58,8 +64,8 @@ export class CallToastNotificationViewModel extends BaseToastNotificationViewMod
const stream = await this.platform.mediaDevices.getMediaTracks(false, true);
const localMedia = new LocalMedia().withUserMedia(stream);
await this.call.join(localMedia, log);
const url = this.urlCreator.openRoomActionUrl(this.call.roomId);
this.urlCreator.pushUrl(url);
const url = this.urlRouter.openRoomActionUrl(this.call.roomId);
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 {Room} from "../../../matrix/room/Room.js";
import type {Session} from "../../../matrix/Session.js";
import type {SegmentType} from "../../navigation";
type Options = {
session: Session;
} & BaseOptions;
export class ToastCollectionViewModel extends ViewModel<Options> {
export class ToastCollectionViewModel extends ViewModel<SegmentType, Options> {
public readonly toastViewModels: ObservableArray<CallToastNotificationViewModel> = new ObservableArray();
constructor(options: Options) {