Add return types

This commit is contained in:
RMidhunSuresh 2023-01-24 13:24:15 +05:30
parent b86fdd476f
commit eb7fcc6da2
No known key found for this signature in database

View File

@ -14,12 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import {CallToastNotificationViewModel} from "./CallToastNotificationViewModel";
import {ObservableArray} from "../../../observable"; import {ObservableArray} from "../../../observable";
import {ViewModel, Options as BaseOptions} from "../../ViewModel"; 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 {CallToastNotificationViewModel} from "./CallToastNotificationViewModel";
type Options = { type Options = {
session: Session; session: Session;
@ -35,8 +35,8 @@ export class ToastCollectionViewModel extends ViewModel<Options> {
this.track(callsObservableMap.subscribe(this)); this.track(callsObservableMap.subscribe(this));
} }
onAdd(_, call) { onAdd(_, call: GroupCall) {
if (this.shouldShowNotification(call)) { if (this._shouldShowNotification(call)) {
const room = this._findRoomForCall(call); const room = this._findRoomForCall(call);
const dismiss = () => { const dismiss = () => {
const idx = this.toastViewModels.array.findIndex(vm => vm.call === call); const idx = this.toastViewModels.array.findIndex(vm => vm.call === call);
@ -50,17 +50,16 @@ export class ToastCollectionViewModel extends ViewModel<Options> {
} }
} }
onRemove(_, call) { onRemove(_, call: GroupCall) {
const idx = this.toastViewModels.array.findIndex(vm => vm.call === call); const idx = this.toastViewModels.array.findIndex(vm => vm.call === call);
if (idx !== -1) { if (idx !== -1) {
this.toastViewModels.remove(idx); this.toastViewModels.remove(idx);
} }
} }
onUpdate(_, call) { onUpdate(_, call: GroupCall) {
const idx = this.toastViewModels.array.findIndex(vm => vm.call === call); const idx = this.toastViewModels.array.findIndex(vm => vm.call === call);
if (idx !== -1) { if (idx !== -1) {
// todo: is this correct?
this.toastViewModels.update(idx, this.toastViewModels.at(idx)!); this.toastViewModels.update(idx, this.toastViewModels.at(idx)!);
} }
} }
@ -77,7 +76,7 @@ export class ToastCollectionViewModel extends ViewModel<Options> {
return rooms.get(id); return rooms.get(id);
} }
private shouldShowNotification(call: GroupCall): boolean { private _shouldShowNotification(call: GroupCall): boolean {
const currentlyOpenedRoomId = this.navigation.path.get("room")?.value; const currentlyOpenedRoomId = this.navigation.path.get("room")?.value;
if (!call.isLoadedFromStorage && call.roomId !== currentlyOpenedRoomId) { if (!call.isLoadedFromStorage && call.roomId !== currentlyOpenedRoomId) {
return true; return true;