mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
support isOwn on messages
This commit is contained in:
parent
a5a333b71a
commit
a4bc2dd2b0
@ -29,7 +29,7 @@ export default class SessionViewModel extends EventEmitter {
|
||||
if (this._currentRoomViewModel) {
|
||||
this._currentRoomViewModel.disable();
|
||||
}
|
||||
this._currentRoomViewModel = new RoomViewModel(room);
|
||||
this._currentRoomViewModel = new RoomViewModel(room, this._session.userId);
|
||||
this._currentRoomViewModel.enable();
|
||||
this.emit("change", "currentRoom");
|
||||
}
|
||||
|
@ -2,9 +2,10 @@ import EventEmitter from "../../../EventEmitter.js";
|
||||
import TimelineViewModel from "./timeline/TimelineViewModel.js";
|
||||
|
||||
export default class RoomViewModel extends EventEmitter {
|
||||
constructor(room) {
|
||||
constructor(room, ownUserId) {
|
||||
super();
|
||||
this._room = room;
|
||||
this._ownUserId = ownUserId;
|
||||
this._timeline = null;
|
||||
this._timelineVM = null;
|
||||
this._onRoomChange = this._onRoomChange.bind(this);
|
||||
@ -15,7 +16,7 @@ export default class RoomViewModel extends EventEmitter {
|
||||
this._room.on("change", this._onRoomChange);
|
||||
try {
|
||||
this._timeline = await this._room.openTimeline();
|
||||
this._timelineVM = new TimelineViewModel(this._timeline);
|
||||
this._timelineVM = new TimelineViewModel(this._timeline, this._ownUserId);
|
||||
this.emit("change", "timelineViewModel");
|
||||
} catch (err) {
|
||||
console.error(`room.openTimeline(): ${err.message}:\n${err.stack}`);
|
||||
|
@ -18,12 +18,12 @@ import TilesCollection from "./TilesCollection.js";
|
||||
import tilesCreator from "./tilesCreator.js";
|
||||
|
||||
export default class TimelineViewModel {
|
||||
constructor(timeline) {
|
||||
constructor(timeline, ownUserId) {
|
||||
this._timeline = timeline;
|
||||
// once we support sending messages we could do
|
||||
// timeline.entries.concat(timeline.pendingEvents)
|
||||
// for an ObservableList that also contains local echos
|
||||
this._tiles = new TilesCollection(timeline.entries, tilesCreator({timeline}));
|
||||
this._tiles = new TilesCollection(timeline.entries, tilesCreator({timeline, ownUserId}));
|
||||
}
|
||||
|
||||
// doesn't fill gaps, only loads stored entries/tiles
|
||||
|
@ -4,6 +4,7 @@ export default class MessageTile extends SimpleTile {
|
||||
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this._isOwn = this._entry.event.sender === options.ownUserId;
|
||||
this._date = new Date(this._entry.event.origin_server_ts);
|
||||
}
|
||||
|
||||
@ -23,6 +24,10 @@ export default class MessageTile extends SimpleTile {
|
||||
return this._date.toLocaleTimeString();
|
||||
}
|
||||
|
||||
get isOwn() {
|
||||
return this._isOwn;
|
||||
}
|
||||
|
||||
_getContent() {
|
||||
const event = this._entry.event;
|
||||
return event && event.content;
|
||||
|
@ -5,9 +5,9 @@ import LocationTile from "./tiles/LocationTile.js";
|
||||
import RoomNameTile from "./tiles/RoomNameTile.js";
|
||||
import RoomMemberTile from "./tiles/RoomMemberTile.js";
|
||||
|
||||
export default function ({timeline}) {
|
||||
export default function ({timeline, ownUserId}) {
|
||||
return function tilesCreator(entry, emitUpdate) {
|
||||
const options = {entry, emitUpdate};
|
||||
const options = {entry, emitUpdate, ownUserId};
|
||||
if (entry.isGap) {
|
||||
return new GapTile(options, timeline);
|
||||
} else if (entry.event) {
|
||||
|
@ -59,4 +59,8 @@ export default class Session {
|
||||
get syncToken() {
|
||||
return this._session.syncToken;
|
||||
}
|
||||
|
||||
get userId() {
|
||||
return this._sessionInfo.userId;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user