This commit is contained in:
Bruno Windels 2022-02-04 17:49:10 +01:00
parent 0b04612d6c
commit 0bb3cfcfad
8 changed files with 96 additions and 17 deletions

View file

@ -21,6 +21,7 @@ import {InviteTileViewModel} from "./InviteTileViewModel.js";
import {RoomBeingCreatedTileViewModel} from "./RoomBeingCreatedTileViewModel.js"; import {RoomBeingCreatedTileViewModel} from "./RoomBeingCreatedTileViewModel.js";
import {RoomFilter} from "./RoomFilter.js"; import {RoomFilter} from "./RoomFilter.js";
import {ApplyMap} from "../../../observable/map/ApplyMap.js"; import {ApplyMap} from "../../../observable/map/ApplyMap.js";
import {LogMap} from "../../../observable/map/LogMap.js";
import {addPanelIfNeeded} from "../../navigation/index.js"; import {addPanelIfNeeded} from "../../navigation/index.js";
export class LeftPanelViewModel extends ViewModel { export class LeftPanelViewModel extends ViewModel {
@ -38,7 +39,7 @@ export class LeftPanelViewModel extends ViewModel {
_mapTileViewModels(roomsBeingCreated, invites, rooms) { _mapTileViewModels(roomsBeingCreated, invites, rooms) {
// join is not commutative, invites will take precedence over 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; let vm;
if (item.isBeingCreated) { if (item.isBeingCreated) {
vm = new RoomBeingCreatedTileViewModel(this.childOptions({roomBeingCreated: item, emitChange})); vm = new RoomBeingCreatedTileViewModel(this.childOptions({roomBeingCreated: item, emitChange}));
@ -54,6 +55,10 @@ export class LeftPanelViewModel extends ViewModel {
} }
return vm; return vm;
}); });
return joined;
// return new LogMap(joined, (op, key, value) => {
// console.log("room list", op, key, value);
// });
} }
_updateCurrentVM(vm) { _updateCurrentVM(vm) {

View file

@ -108,13 +108,14 @@ export class LogItem implements ILogItem {
return item; return item;
} }
set(key: string | object, value?: unknown): void { set(key: string | object, value?: unknown): ILogItem {
if(typeof key === "object") { if(typeof key === "object") {
const values = key; const values = key;
Object.assign(this._values, values); Object.assign(this._values, values);
} else { } else {
this._values[key] = value; this._values[key] = value;
} }
return this;
} }
serialize(filter: LogFilter, parentStartTime: number | undefined, forced: boolean): ISerializedItem | undefined { serialize(filter: LogFilter, parentStartTime: number | undefined, forced: boolean): ISerializedItem | undefined {

View file

@ -43,7 +43,7 @@ export interface ILogItem {
readonly values: LogItemValues; readonly values: LogItemValues;
wrap<T>(labelOrValues: LabelOrValues, callback: LogCallback<T>, logLevel?: LogLevel, filterCreator?: FilterCreator): T; wrap<T>(labelOrValues: LabelOrValues, callback: LogCallback<T>, logLevel?: LogLevel, filterCreator?: FilterCreator): T;
log(labelOrValues: LabelOrValues, logLevel?: LogLevel): ILogItem; 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; runDetached(labelOrValues: LabelOrValues, callback: LogCallback<unknown>, logLevel?: LogLevel, filterCreator?: FilterCreator): ILogItem;
wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback<unknown>, logLevel?: LogLevel, filterCreator?: FilterCreator): void; wrapDetached(labelOrValues: LabelOrValues, callback: LogCallback<unknown>, logLevel?: LogLevel, filterCreator?: FilterCreator): void;
refDetached(logItem: ILogItem, logLevel?: LogLevel): void; refDetached(logItem: ILogItem, logLevel?: LogLevel): void;

View file

@ -64,10 +64,10 @@ export class Session {
this._activeArchivedRooms = new Map(); this._activeArchivedRooms = new Map();
this._invites = new ObservableMap(); this._invites = new ObservableMap();
this._inviteUpdateCallback = (invite, params) => this._invites.update(invite.id, params); 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); this._roomsBeingCreated.update(rbc.localId, params);
if (rbc.roomId && !!this.rooms.get(rbc.roomId)) { if (rbc.roomId && !!this.rooms.get(rbc.roomId)) {
this._tryReplaceRoomBeingCreated(rbc.roomId); this._tryReplaceRoomBeingCreated(rbc.roomId, log);
} }
}; };
this._roomsBeingCreated = new ObservableMap(); this._roomsBeingCreated = new ObservableMap();
@ -686,16 +686,16 @@ export class Session {
} }
} }
_tryReplaceRoomBeingCreated(roomId) { _tryReplaceRoomBeingCreated(roomId, log) {
console.trace("_tryReplaceRoomBeingCreated " + roomId);
for (const [,roomBeingCreated] of this._roomsBeingCreated) { for (const [,roomBeingCreated] of this._roomsBeingCreated) {
if (roomBeingCreated.roomId === roomId) { if (roomBeingCreated.roomId === roomId) {
const observableStatus = this._observedRoomStatus.get(roomBeingCreated.localId); const observableStatus = this._observedRoomStatus.get(roomBeingCreated.localId);
if (observableStatus) { 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); observableStatus.set(observableStatus.get() | RoomStatus.Replaced);
} else {
console.log("no observableStatus");
} }
this._roomsBeingCreated.remove(roomBeingCreated.localId); this._roomsBeingCreated.remove(roomBeingCreated.localId);
return; return;
@ -703,12 +703,12 @@ export class Session {
} }
} }
applyRoomCollectionChangesAfterSync(inviteStates, roomStates, archivedRoomStates) { 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) {
this._rooms.add(rs.id, rs.room); this._rooms.add(rs.id, rs.room);
this._tryReplaceRoomBeingCreated(rs.id); this._tryReplaceRoomBeingCreated(rs.id, log);
} else if (rs.shouldRemove) { } else if (rs.shouldRemove) {
this._rooms.remove(rs.id); this._rooms.remove(rs.id);
} }

View file

@ -316,7 +316,7 @@ export class Sync {
for(let is of inviteStates) { for(let is of inviteStates) {
log.wrap("invite", log => is.invite.afterSync(is.changes, log), log.level.Detail); 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() { _openSyncTxn() {

View file

@ -96,7 +96,10 @@ function processRoomAccountData(data, event) {
} }
export function processStateEvent(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; const algorithm = event.content?.algorithm;
if (!data.encryption && algorithm === MEGOLM_ALGORITHM) { if (!data.encryption && algorithm === MEGOLM_ALGORITHM) {
data = data.cloneIfNeeded(); data = data.cloneIfNeeded();

View file

@ -121,7 +121,7 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
console.log("done creating the room now", this._roomId); console.log("done creating the room now", this._roomId);
// TODO: somehow check in Session if we need to replace this with a joined room // 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 // 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> { private async loadProfiles(hsApi: HomeServerApi, log: ILogItem): Promise<void> {
@ -139,8 +139,8 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
} }
} }
private emitChange() { private emitChange(params?, log?) {
this.updateCallback(this); this.updateCallback(this, params, log);
this.emit("change"); this.emit("change");
} }

View 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);
}
}