mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
WIP3
This commit is contained in:
parent
0b04612d6c
commit
0bb3cfcfad
@ -21,6 +21,7 @@ import {InviteTileViewModel} from "./InviteTileViewModel.js";
|
||||
import {RoomBeingCreatedTileViewModel} from "./RoomBeingCreatedTileViewModel.js";
|
||||
import {RoomFilter} from "./RoomFilter.js";
|
||||
import {ApplyMap} from "../../../observable/map/ApplyMap.js";
|
||||
import {LogMap} from "../../../observable/map/LogMap.js";
|
||||
import {addPanelIfNeeded} from "../../navigation/index.js";
|
||||
|
||||
export class LeftPanelViewModel extends ViewModel {
|
||||
@ -38,7 +39,7 @@ export class LeftPanelViewModel extends ViewModel {
|
||||
|
||||
_mapTileViewModels(roomsBeingCreated, invites, rooms) {
|
||||
// join is not commutative, invites will take precedence over rooms
|
||||
return roomsBeingCreated.join(invites).join(rooms).mapValues((item, emitChange) => {
|
||||
const joined = invites.join(roomsBeingCreated, rooms).mapValues((item, emitChange) => {
|
||||
let vm;
|
||||
if (item.isBeingCreated) {
|
||||
vm = new RoomBeingCreatedTileViewModel(this.childOptions({roomBeingCreated: item, emitChange}));
|
||||
@ -54,6 +55,10 @@ export class LeftPanelViewModel extends ViewModel {
|
||||
}
|
||||
return vm;
|
||||
});
|
||||
return joined;
|
||||
// return new LogMap(joined, (op, key, value) => {
|
||||
// console.log("room list", op, key, value);
|
||||
// });
|
||||
}
|
||||
|
||||
_updateCurrentVM(vm) {
|
||||
|
@ -108,13 +108,14 @@ export class LogItem implements ILogItem {
|
||||
return item;
|
||||
}
|
||||
|
||||
set(key: string | object, value?: unknown): void {
|
||||
set(key: string | object, value?: unknown): ILogItem {
|
||||
if(typeof key === "object") {
|
||||
const values = key;
|
||||
Object.assign(this._values, values);
|
||||
} else {
|
||||
this._values[key] = value;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
serialize(filter: LogFilter, parentStartTime: number | undefined, forced: boolean): ISerializedItem | undefined {
|
||||
|
@ -43,7 +43,7 @@ export interface ILogItem {
|
||||
readonly values: LogItemValues;
|
||||
wrap<T>(labelOrValues: LabelOrValues, callback: LogCallback<T>, logLevel?: LogLevel, filterCreator?: FilterCreator): T;
|
||||
log(labelOrValues: LabelOrValues, logLevel?: LogLevel): ILogItem;
|
||||
set(key: string | object, value: unknown): void;
|
||||
set(key: string | object, value: unknown): ILogItem;
|
||||
runDetached(labelOrValues: LabelOrValues, callback: LogCallback<unknown>, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem;
|
||||
wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback<unknown>, logLevel?: LogLevel, filterCreator?: FilterCreator): void;
|
||||
refDetached(logItem: ILogItem, logLevel?: LogLevel): void;
|
||||
|
@ -64,10 +64,10 @@ export class Session {
|
||||
this._activeArchivedRooms = new Map();
|
||||
this._invites = new ObservableMap();
|
||||
this._inviteUpdateCallback = (invite, params) => this._invites.update(invite.id, params);
|
||||
this._roomsBeingCreatedUpdateCallback = (rbc, params) => {
|
||||
this._roomsBeingCreatedUpdateCallback = (rbc, params, log) => {
|
||||
this._roomsBeingCreated.update(rbc.localId, params);
|
||||
if (rbc.roomId && !!this.rooms.get(rbc.roomId)) {
|
||||
this._tryReplaceRoomBeingCreated(rbc.roomId);
|
||||
this._tryReplaceRoomBeingCreated(rbc.roomId, log);
|
||||
}
|
||||
};
|
||||
this._roomsBeingCreated = new ObservableMap();
|
||||
@ -686,16 +686,16 @@ export class Session {
|
||||
}
|
||||
}
|
||||
|
||||
_tryReplaceRoomBeingCreated(roomId) {
|
||||
console.trace("_tryReplaceRoomBeingCreated " + roomId);
|
||||
_tryReplaceRoomBeingCreated(roomId, log) {
|
||||
for (const [,roomBeingCreated] of this._roomsBeingCreated) {
|
||||
if (roomBeingCreated.roomId === roomId) {
|
||||
const observableStatus = this._observedRoomStatus.get(roomBeingCreated.localId);
|
||||
if (observableStatus) {
|
||||
console.log("marking room as replaced", observableStatus.get());
|
||||
this._platform.logger.wrapOrRun(log, `replacing room being created`, log => {
|
||||
log.set("localId", roomBeingCreated.localId)
|
||||
.set("roomId", roomBeingCreated.roomId);
|
||||
});
|
||||
observableStatus.set(observableStatus.get() | RoomStatus.Replaced);
|
||||
} else {
|
||||
console.log("no observableStatus");
|
||||
}
|
||||
this._roomsBeingCreated.remove(roomBeingCreated.localId);
|
||||
return;
|
||||
@ -703,12 +703,12 @@ export class Session {
|
||||
}
|
||||
}
|
||||
|
||||
applyRoomCollectionChangesAfterSync(inviteStates, roomStates, archivedRoomStates) {
|
||||
applyRoomCollectionChangesAfterSync(inviteStates, roomStates, archivedRoomStates, log) {
|
||||
// update the collections after sync
|
||||
for (const rs of roomStates) {
|
||||
if (rs.shouldAdd) {
|
||||
this._rooms.add(rs.id, rs.room);
|
||||
this._tryReplaceRoomBeingCreated(rs.id);
|
||||
this._tryReplaceRoomBeingCreated(rs.id, log);
|
||||
} else if (rs.shouldRemove) {
|
||||
this._rooms.remove(rs.id);
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ export class Sync {
|
||||
for(let is of inviteStates) {
|
||||
log.wrap("invite", log => is.invite.afterSync(is.changes, log), log.level.Detail);
|
||||
}
|
||||
this._session.applyRoomCollectionChangesAfterSync(inviteStates, roomStates, archivedRoomStates);
|
||||
this._session.applyRoomCollectionChangesAfterSync(inviteStates, roomStates, archivedRoomStates, log);
|
||||
}
|
||||
|
||||
_openSyncTxn() {
|
||||
|
@ -96,7 +96,10 @@ function processRoomAccountData(data, event) {
|
||||
}
|
||||
|
||||
export function processStateEvent(data, event) {
|
||||
if (event.type === "m.room.encryption") {
|
||||
if (event.type === "m.room.create") {
|
||||
data = data.cloneIfNeeded();
|
||||
data.lastMessageTimestamp = event.origin_server_ts;
|
||||
} else if (event.type === "m.room.encryption") {
|
||||
const algorithm = event.content?.algorithm;
|
||||
if (!data.encryption && algorithm === MEGOLM_ALGORITHM) {
|
||||
data = data.cloneIfNeeded();
|
||||
|
@ -121,7 +121,7 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
||||
console.log("done creating the room now", this._roomId);
|
||||
// TODO: somehow check in Session if we need to replace this with a joined room
|
||||
// in case the room appears first in sync, and this request returns later
|
||||
this.emitChange();
|
||||
this.emitChange(undefined, log);
|
||||
}
|
||||
|
||||
private async loadProfiles(hsApi: HomeServerApi, log: ILogItem): Promise<void> {
|
||||
@ -139,8 +139,8 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
||||
}
|
||||
}
|
||||
|
||||
private emitChange() {
|
||||
this.updateCallback(this);
|
||||
private emitChange(params?, log?) {
|
||||
this.updateCallback(this, params, log);
|
||||
this.emit("change");
|
||||
}
|
||||
|
||||
|
70
src/observable/map/LogMap.js
Normal file
70
src/observable/map/LogMap.js
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
Copyright 2020 Bruno Windels <bruno@windels.cloud>
|
||||
|
||||
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 {BaseObservableMap} from "./BaseObservableMap.js";
|
||||
|
||||
export class LogMap extends BaseObservableMap {
|
||||
constructor(source, log) {
|
||||
super();
|
||||
this._source = source;
|
||||
this.log = log;
|
||||
this._subscription = null;
|
||||
}
|
||||
|
||||
onAdd(key, value) {
|
||||
this.log("add", key, value);
|
||||
this.emitAdd(key, value);
|
||||
}
|
||||
|
||||
onRemove(key, value) {
|
||||
this.log("remove", key, value);
|
||||
this.emitRemove(key, value);
|
||||
}
|
||||
|
||||
onUpdate(key, value, params) {
|
||||
this.log("update", key, value, params);
|
||||
this.emitUpdate(key, value, params);
|
||||
}
|
||||
|
||||
onSubscribeFirst() {
|
||||
this.log("subscribeFirst");
|
||||
this._subscription = this._source.subscribe(this);
|
||||
super.onSubscribeFirst();
|
||||
}
|
||||
|
||||
onUnsubscribeLast() {
|
||||
super.onUnsubscribeLast();
|
||||
this._subscription = this._subscription();
|
||||
this.log("unsubscribeLast");
|
||||
}
|
||||
|
||||
onReset() {
|
||||
this.log("reset");
|
||||
this.emitReset();
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this._source[Symbol.iterator]();
|
||||
}
|
||||
|
||||
get size() {
|
||||
return this._source.size;
|
||||
}
|
||||
|
||||
get(key) {
|
||||
return this._source.get(key);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user