timeline has the own member, so can just use timeline, not ownUserId

This commit is contained in:
Bruno Windels 2021-05-31 15:18:44 +02:00
parent 2bd7c23076
commit 00231443d3
5 changed files with 10 additions and 14 deletions

View file

@ -153,10 +153,7 @@ export class SessionViewModel extends ViewModel {
_createRoomViewModel(roomId) {
const room = this._sessionContainer.session.rooms.get(roomId);
if (room) {
const roomVM = new RoomViewModel(this.childOptions({
room,
ownUserId: this._sessionContainer.session.user.id,
}));
const roomVM = new RoomViewModel(this.childOptions({room}));
roomVM.load();
return roomVM;
}
@ -173,10 +170,7 @@ export class SessionViewModel extends ViewModel {
async _createArchivedRoomViewModel(roomId) {
const room = await this._sessionContainer.session.loadArchivedRoom(roomId);
if (room) {
const roomVM = new RoomViewModel(this.childOptions({
room,
ownUserId: this._sessionContainer.session.user.id,
}));
const roomVM = new RoomViewModel(this.childOptions({room}));
roomVM.load();
return roomVM;
}

View file

@ -22,9 +22,8 @@ import {ViewModel} from "../../ViewModel.js";
export class RoomViewModel extends ViewModel {
constructor(options) {
super(options);
const {room, ownUserId} = options;
const {room} = options;
this._room = room;
this._ownUserId = ownUserId;
this._timelineVM = null;
this._onRoomChange = this._onRoomChange.bind(this);
this._timelineError = null;
@ -46,7 +45,6 @@ export class RoomViewModel extends ViewModel {
const timelineVM = this.track(new TimelineViewModel(this.childOptions({
room: this._room,
timeline,
ownUserId: this._ownUserId,
})));
this._timelineVM = timelineVM;
this.emitChange("timelineViewModel");

View file

@ -38,9 +38,9 @@ import {ViewModel} from "../../../ViewModel.js";
export class TimelineViewModel extends ViewModel {
constructor(options) {
super(options);
const {room, timeline, ownUserId} = options;
const {room, timeline} = options;
this._timeline = this.track(timeline);
this._tiles = new TilesCollection(timeline.entries, tilesCreator(this.childOptions({room, timeline, ownUserId})));
this._tiles = new TilesCollection(timeline.entries, tilesCreator(this.childOptions({room, timeline})));
}
/**

View file

@ -20,7 +20,7 @@ import {getIdentifierColorNumber, avatarInitials, getAvatarHttpUrl} from "../../
export class BaseMessageTile extends SimpleTile {
constructor(options) {
super(options);
this._isOwn = this._entry.sender === options.ownUserId;
this._isOwn = this._entry.sender === options.timeline.me.userId;
this._date = this._entry.timestamp ? new Date(this._entry.timestamp) : null;
this._isContinuation = false;
}

View file

@ -228,4 +228,8 @@ export class Timeline {
get powerLevels() {
return this._powerLevels;
}
get me() {
return this._ownMember;
}
}