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

View file

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

View file

@ -38,9 +38,9 @@ import {ViewModel} from "../../../ViewModel.js";
export class TimelineViewModel extends ViewModel { export class TimelineViewModel extends ViewModel {
constructor(options) { constructor(options) {
super(options); super(options);
const {room, timeline, ownUserId} = options; const {room, timeline} = options;
this._timeline = this.track(timeline); 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 { export class BaseMessageTile extends SimpleTile {
constructor(options) { constructor(options) {
super(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._date = this._entry.timestamp ? new Date(this._entry.timestamp) : null;
this._isContinuation = false; this._isContinuation = false;
} }

View file

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