From 220ddc7175aefc0e520516a68be91a6cc0537848 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Tue, 9 Aug 2022 14:23:40 +0530 Subject: [PATCH] Fix merge conflict --- src/domain/session/room/CallViewModel.ts | 9 ++-- src/matrix/e2ee/RoomEncryption.js | 1 - src/matrix/net/HomeServerApi.ts | 2 +- src/matrix/net/TokenRefresher.ts | 6 ++- src/observable/value/BaseObservableValue.ts | 33 ------------- src/observable/value/MappedObservableValue.ts | 46 +++++++++++++++++++ yarn.lock | 7 --- 7 files changed, 56 insertions(+), 48 deletions(-) create mode 100644 src/observable/value/MappedObservableValue.ts diff --git a/src/domain/session/room/CallViewModel.ts b/src/domain/session/room/CallViewModel.ts index 020c9f17..044bf432 100644 --- a/src/domain/session/room/CallViewModel.ts +++ b/src/domain/session/room/CallViewModel.ts @@ -16,6 +16,7 @@ limitations under the License. import {AvatarSource} from "../../AvatarSource"; import {ViewModel, Options as BaseOptions} from "../../ViewModel"; +import { SegmentType } from "../../navigation"; import {getStreamVideoTrack, getStreamAudioTrack} from "../../../matrix/calls/common"; import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar"; import {EventObservableValue} from "../../../observable/value/EventObservableValue"; @@ -34,13 +35,13 @@ type Options = BaseOptions & { room: Room, }; -export class CallViewModel extends ViewModel { +export class CallViewModel extends ViewModel { public readonly memberViewModels: BaseObservableList; constructor(options: Options) { super(options); const ownMemberViewModelMap = new ObservableValueMap("self", new EventObservableValue(this.call, "change")) - .mapValues((call, emitChange) => new OwnMemberViewModel(this.childOptions({call, emitChange})), () => {}); + .mapValues((call, emitChange) => new OwnMemberViewModel(this.childOptions({call, room: options.room, emitChange})), () => {}); this.memberViewModels = this.call.members .filterValues(member => member.isConnected) .mapValues(member => new CallMemberViewModel(this.childOptions({member, mediaRepository: this.getOption("room").mediaRepository}))) @@ -119,7 +120,7 @@ export class CallViewModel extends ViewModel { } } -class OwnMemberViewModel extends ViewModel implements IStreamViewModel { +class OwnMemberViewModel extends ViewModel implements IStreamViewModel { private memberObservable: undefined | BaseObservableValue; constructor(options: Options) { @@ -190,7 +191,7 @@ type MemberOptions = BaseOptions & { mediaRepository: MediaRepository }; -export class CallMemberViewModel extends ViewModel implements IStreamViewModel { +export class CallMemberViewModel extends ViewModel implements IStreamViewModel { get stream(): Stream | undefined { return this.member.remoteMedia?.userMedia; } diff --git a/src/matrix/e2ee/RoomEncryption.js b/src/matrix/e2ee/RoomEncryption.js index 557cadac..fd824109 100644 --- a/src/matrix/e2ee/RoomEncryption.js +++ b/src/matrix/e2ee/RoomEncryption.js @@ -548,7 +548,6 @@ import {createMockStorage} from "../../mocks/Storage"; import {Clock as MockClock} from "../../mocks/Clock"; import {poll} from "../../mocks/poll"; import {Instance as NullLoggerInstance} from "../../logging/NullLogger"; -import {ConsoleLogger} from "../../logging/ConsoleLogger"; import {HomeServer as MockHomeServer} from "../../mocks/HomeServer.js"; export function tests() { diff --git a/src/matrix/net/HomeServerApi.ts b/src/matrix/net/HomeServerApi.ts index fd4e7dc4..77eda7ee 100644 --- a/src/matrix/net/HomeServerApi.ts +++ b/src/matrix/net/HomeServerApi.ts @@ -367,7 +367,7 @@ export class HomeServerApi { } import {Request as MockRequest} from "../../mocks/Request.js"; -import {BaseObservableValue} from "../../observable/ObservableValue"; +import {BaseObservableValue} from "../../observable/value/BaseObservableValue"; export function tests() { return { diff --git a/src/matrix/net/TokenRefresher.ts b/src/matrix/net/TokenRefresher.ts index 2010cebe..16b44b1c 100644 --- a/src/matrix/net/TokenRefresher.ts +++ b/src/matrix/net/TokenRefresher.ts @@ -14,7 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {BaseObservableValue, ObservableValue} from "../../observable/ObservableValue"; +import {ObservableValue} from "../../observable/value/ObservableValue"; +import { BaseObservableValue } from "../../observable/value/BaseObservableValue"; +import { MappedObservableValue } from "../../observable/value/MappedObservableValue"; import type {Clock, Timeout} from "../../platform/web/dom/Clock"; import {OidcApi} from "./OidcApi"; @@ -54,7 +56,7 @@ export class TokenRefresher { accessTokenExpiresAt, refreshToken, }); - this._accessToken = this._token.map(t => t.accessToken); + this._accessToken = new MappedObservableValue(this._token, (t) => t.accessToken); this._anticipation = anticipation; this._oidcApi = oidcApi; diff --git a/src/observable/value/BaseObservableValue.ts b/src/observable/value/BaseObservableValue.ts index 73aefb96..85437262 100644 --- a/src/observable/value/BaseObservableValue.ts +++ b/src/observable/value/BaseObservableValue.ts @@ -36,39 +36,6 @@ export abstract class BaseObservableValue extends BaseObservable<(value: T) = return new WaitForHandle(this, predicate); } } - - map(mapper: (value: T) => C): BaseObservableValue { - return new MappedObservableValue(this, mapper); - } -} - - -export class MappedObservableValue extends BaseObservableValue { - private sourceSubscription?: SubscriptionHandle; - - constructor( - private readonly source: BaseObservableValue

, - private readonly mapper: (value: P) => C - ) { - super(); - } - - onUnsubscribeLast() { - super.onUnsubscribeLast(); - this.sourceSubscription = this.sourceSubscription!(); - } - - onSubscribeFirst() { - super.onSubscribeFirst(); - this.sourceSubscription = this.source.subscribe(() => { - this.emit(this.get()); - }); - } - - get(): C { - const sourceValue = this.source.get(); - return this.mapper(sourceValue); - } } interface IWaitHandle { diff --git a/src/observable/value/MappedObservableValue.ts b/src/observable/value/MappedObservableValue.ts new file mode 100644 index 00000000..7105dfb0 --- /dev/null +++ b/src/observable/value/MappedObservableValue.ts @@ -0,0 +1,46 @@ +/* +Copyright 2021 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the 'License'); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an 'AS IS' BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { BaseObservableValue } from "./BaseObservableValue"; +import { SubscriptionHandle } from "../BaseObservable"; + +export class MappedObservableValue extends BaseObservableValue { + private sourceSubscription?: SubscriptionHandle; + + constructor( + private readonly source: BaseObservableValue

, + private readonly mapper: (value: P) => C + ) { + super(); + } + + onUnsubscribeLast() { + super.onUnsubscribeLast(); + this.sourceSubscription = this.sourceSubscription!(); + } + + onSubscribeFirst() { + super.onSubscribeFirst(); + this.sourceSubscription = this.source.subscribe(() => { + this.emit(this.get()); + }); + } + + get(): C { + const sourceValue = this.source.get(); + return this.mapper(sourceValue); + } +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 0d62c5f7..44f07a81 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1670,17 +1670,10 @@ type-fest@^0.20.2: resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.20.2.tgz#1bf207f4b28f91583666cb5fbd327887301cd5f4" integrity sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ== -<<<<<<< HEAD -typescript@^4.4: - version "4.6.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.3.tgz#eefeafa6afdd31d725584c67a0eaba80f6fc6c6c" - integrity sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw== -======= typescript@^4.7.0: version "4.7.4" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235" integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ== ->>>>>>> sandhose/oidc-login typeson-registry@^1.0.0-alpha.20: version "1.0.0-alpha.39"