mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Merge pull request #1010 from vector-im/calls-fix-toast-issues
Calls: Fixes for toast issues
This commit is contained in:
commit
fabe2abdf4
@ -21,6 +21,7 @@ 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";
|
import type {SegmentType} from "../../navigation";
|
||||||
|
import { RoomStatus } from "../../../lib";
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
session: Session;
|
session: Session;
|
||||||
@ -36,9 +37,9 @@ export class ToastCollectionViewModel extends ViewModel<SegmentType, Options> {
|
|||||||
this.track(callsObservableMap.subscribe(this));
|
this.track(callsObservableMap.subscribe(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
onAdd(_, call: GroupCall) {
|
async onAdd(_, call: GroupCall) {
|
||||||
if (this._shouldShowNotification(call)) {
|
if (this._shouldShowNotification(call)) {
|
||||||
const room = this._findRoomForCall(call);
|
const room = await 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);
|
||||||
if (idx !== -1) {
|
if (idx !== -1) {
|
||||||
@ -71,10 +72,16 @@ export class ToastCollectionViewModel extends ViewModel<SegmentType, Options> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _findRoomForCall(call: GroupCall): Room {
|
private async _findRoomForCall(call: GroupCall): Promise<Room> {
|
||||||
const id = call.roomId;
|
const id = call.roomId;
|
||||||
const rooms = this.getOption("session").rooms;
|
const session = this.getOption("session");
|
||||||
return rooms.get(id);
|
const rooms = session.rooms;
|
||||||
|
// Make sure that we know of this room,
|
||||||
|
// otherwise wait for it to come through sync
|
||||||
|
const observable = await session.observeRoomStatus(id);
|
||||||
|
await observable.waitFor(s => s === RoomStatus.Joined).promise;
|
||||||
|
const room = rooms.get(id);
|
||||||
|
return room;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _shouldShowNotification(call: GroupCall): boolean {
|
private _shouldShowNotification(call: GroupCall): boolean {
|
||||||
|
@ -776,7 +776,7 @@ export class Session {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applyRoomCollectionChangesAfterSync(inviteStates, roomStates, archivedRoomStates, log) {
|
async applyRoomCollectionChangesAfterSync(inviteStates, roomStates, archivedRoomStates, log) {
|
||||||
// update the collections after sync
|
// update the collections after sync
|
||||||
for (const rs of roomStates) {
|
for (const rs of roomStates) {
|
||||||
if (rs.shouldAdd) {
|
if (rs.shouldAdd) {
|
||||||
@ -940,12 +940,20 @@ export class Session {
|
|||||||
async observeRoomStatus(roomId) {
|
async observeRoomStatus(roomId) {
|
||||||
let observable = this._observedRoomStatus.get(roomId);
|
let observable = this._observedRoomStatus.get(roomId);
|
||||||
if (!observable) {
|
if (!observable) {
|
||||||
const status = await this.getRoomStatus(roomId);
|
let status = undefined;
|
||||||
|
// Create and set the observable with value = undefined, so that
|
||||||
|
// we don't loose any sync changes that come in while we are busy
|
||||||
|
// calculating the current room status.
|
||||||
observable = new RetainedObservableValue(status, () => {
|
observable = new RetainedObservableValue(status, () => {
|
||||||
this._observedRoomStatus.delete(roomId);
|
this._observedRoomStatus.delete(roomId);
|
||||||
});
|
});
|
||||||
|
|
||||||
this._observedRoomStatus.set(roomId, observable);
|
this._observedRoomStatus.set(roomId, observable);
|
||||||
|
status = await this.getRoomStatus(roomId);
|
||||||
|
// If observable.value is not undefined anymore, then some
|
||||||
|
// change has come through the sync.
|
||||||
|
if (observable.get() === undefined) {
|
||||||
|
observable.set(status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return observable;
|
return observable;
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,8 @@ export class CallHandler implements RoomStateHandler {
|
|||||||
this._calls.remove(call.id);
|
this._calls.remove(call.id);
|
||||||
txn.calls.remove(call.intent, roomId, call.id);
|
txn.calls.remove(call.intent, roomId, call.id);
|
||||||
}
|
}
|
||||||
} else {
|
} else if(!event.content["m.terminated"]) {
|
||||||
|
// We don't have this call already and it isn't terminated, so create the call:
|
||||||
call = new GroupCall(
|
call = new GroupCall(
|
||||||
event.state_key, // id
|
event.state_key, // id
|
||||||
false, // isLoadedFromStorage
|
false, // isLoadedFromStorage
|
||||||
|
Loading…
Reference in New Issue
Block a user