pass all viewmodel options to tile view models

This commit is contained in:
Bruno Windels 2020-10-28 17:37:45 +01:00
parent d7ccdd3304
commit fe6e4464fd
4 changed files with 19 additions and 10 deletions

View file

@ -43,7 +43,7 @@ export class TimelineViewModel extends ViewModel {
// once we support sending messages we could do // once we support sending messages we could do
// timeline.entries.concat(timeline.pendingEvents) // timeline.entries.concat(timeline.pendingEvents)
// for an ObservableList that also contains local echos // for an ObservableList that also contains local echos
this._tiles = new TilesCollection(timeline.entries, tilesCreator({room, ownUserId, platform: this.platform})); this._tiles = new TilesCollection(timeline.entries, tilesCreator(this.childOptions({room, ownUserId})));
} }
async load() { async load() {

View file

@ -18,22 +18,25 @@ import {SimpleTile} from "./SimpleTile.js";
import {UpdateAction} from "../UpdateAction.js"; import {UpdateAction} from "../UpdateAction.js";
export class GapTile extends SimpleTile { export class GapTile extends SimpleTile {
constructor(options, timeline) { constructor(options) {
super(options); super(options);
this._timeline = timeline;
this._loading = false; this._loading = false;
this._error = null; this._error = null;
} }
get _room() {
return this.getOption("room");
}
async fill() { async fill() {
// prevent doing this twice // prevent doing this twice
if (!this._loading) { if (!this._loading) {
this._loading = true; this._loading = true;
this.emitChange("isLoading"); this.emitChange("isLoading");
try { try {
await this._timeline.fillGap(this._entry, 10); await this._room.fillGap(this._entry, 10);
} catch (err) { } catch (err) {
console.error(`timeline.fillGap(): ${err.message}:\n${err.stack}`); console.error(`room.fillGap(): ${err.message}:\n${err.stack}`);
this._error = err; this._error = err;
this.emitChange("error"); this.emitChange("error");
// rethrow so caller of this method // rethrow so caller of this method

View file

@ -20,12 +20,19 @@ import {getIdentifierColorNumber, avatarInitials} from "../../../../avatar.js";
export class MessageTile extends SimpleTile { export class MessageTile extends SimpleTile {
constructor(options) { constructor(options) {
super(options); super(options);
this._mediaRepository = options.mediaRepository;
this._isOwn = this._entry.sender === options.ownUserId; this._isOwn = this._entry.sender === options.ownUserId;
this._date = this._entry.timestamp ? new Date(this._entry.timestamp) : null; this._date = this._entry.timestamp ? new Date(this._entry.timestamp) : null;
this._isContinuation = false; this._isContinuation = false;
} }
get _room() {
return this.getOption("room");
}
get _mediaRepository() {
return this._room.mediaRepository;
}
get shape() { get shape() {
return "message"; return "message";
} }

View file

@ -23,12 +23,11 @@ import {RoomMemberTile} from "./tiles/RoomMemberTile.js";
import {EncryptedEventTile} from "./tiles/EncryptedEventTile.js"; import {EncryptedEventTile} from "./tiles/EncryptedEventTile.js";
import {EncryptionEnabledTile} from "./tiles/EncryptionEnabledTile.js"; import {EncryptionEnabledTile} from "./tiles/EncryptionEnabledTile.js";
export function tilesCreator({room, ownUserId, platform}) { export function tilesCreator(baseOptions) {
return function tilesCreator(entry, emitUpdate) { return function tilesCreator(entry, emitUpdate) {
const options = {entry, emitUpdate, ownUserId, platform, const options = Object.assign({entry, emitUpdate}, baseOptions);
mediaRepository: room.mediaRepository};
if (entry.isGap) { if (entry.isGap) {
return new GapTile(options, room); return new GapTile(options);
} else if (entry.eventType) { } else if (entry.eventType) {
switch (entry.eventType) { switch (entry.eventType) {
case "m.room.message": { case "m.room.message": {