From 9b94c4bb613884541ce3363b496ccef56f9e7cc9 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 29 Jul 2019 10:27:12 +0200 Subject: [PATCH] don't expose raw event object from entry, pending event doesn't have it it only has content and *some* of the meta fields, but we want to threat pendingevententry and evententry as one and the same in the rest of the application, so don't give access to entire event object. --- .../session/room/timeline/tiles/MessageTile.js | 7 +++---- .../room/timeline/tiles/RoomMemberTile.js | 17 ++++++++--------- .../session/room/timeline/tiles/RoomNameTile.js | 5 ++--- .../session/room/timeline/tiles/TextTile.js | 5 ++--- .../session/room/timeline/tilesCreator.js | 8 +++----- src/matrix/room/timeline/entries/EventEntry.js | 16 ++++++++++++---- .../room/timeline/entries/PendingEventEntry.js | 10 +++++++++- 7 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/domain/session/room/timeline/tiles/MessageTile.js b/src/domain/session/room/timeline/tiles/MessageTile.js index f164c948..46c6fb59 100644 --- a/src/domain/session/room/timeline/tiles/MessageTile.js +++ b/src/domain/session/room/timeline/tiles/MessageTile.js @@ -5,7 +5,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); + this._date = new Date(this._entry.timestamp); this._isContinuation = false; } @@ -14,7 +14,7 @@ export default class MessageTile extends SimpleTile { } get sender() { - return this._entry.event.sender; + return this._entry.sender; } get date() { @@ -34,8 +34,7 @@ export default class MessageTile extends SimpleTile { } _getContent() { - const event = this._entry.event; - return event && event.content; + return this._entry.content; } updatePreviousSibling(prev) { diff --git a/src/domain/session/room/timeline/tiles/RoomMemberTile.js b/src/domain/session/room/timeline/tiles/RoomMemberTile.js index 3f0535fa..58e722c9 100644 --- a/src/domain/session/room/timeline/tiles/RoomMemberTile.js +++ b/src/domain/session/room/timeline/tiles/RoomMemberTile.js @@ -7,21 +7,20 @@ export default class RoomNameTile extends SimpleTile { } get announcement() { - const event = this._entry.event; - const content = event.content; + const {sender, content, stateKey} = this._entry; switch (content.membership) { - case "invite": return `${event.state_key} was invited to the room by ${event.sender}`; - case "join": return `${event.state_key} joined the room`; + case "invite": return `${stateKey} was invited to the room by ${sender}`; + case "join": return `${stateKey} joined the room`; case "leave": { - if (event.state_key === event.sender) { - return `${event.state_key} left the room`; + if (stateKey === sender) { + return `${stateKey} left the room`; } else { const reason = content.reason; - return `${event.state_key} was kicked from the room by ${event.sender}${reason ? `: ${reason}` : ""}`; + return `${stateKey} was kicked from the room by ${sender}${reason ? `: ${reason}` : ""}`; } } - case "ban": return `${event.state_key} was banned from the room by ${event.sender}`; - default: return `${event.sender} membership changed to ${content.membership}`; + case "ban": return `${stateKey} was banned from the room by ${sender}`; + default: return `${sender} membership changed to ${content.membership}`; } } } diff --git a/src/domain/session/room/timeline/tiles/RoomNameTile.js b/src/domain/session/room/timeline/tiles/RoomNameTile.js index 32cd5adf..36ad7934 100644 --- a/src/domain/session/room/timeline/tiles/RoomNameTile.js +++ b/src/domain/session/room/timeline/tiles/RoomNameTile.js @@ -7,8 +7,7 @@ export default class RoomNameTile extends SimpleTile { } get announcement() { - const event = this._entry.event; - const content = event.content; - return `${event.sender} named the room "${content.name}"` + const content = this._entry.content; + return `${this._entry.sender} named the room "${content.name}"` } } diff --git a/src/domain/session/room/timeline/tiles/TextTile.js b/src/domain/session/room/timeline/tiles/TextTile.js index a13f24fb..47680ef0 100644 --- a/src/domain/session/room/timeline/tiles/TextTile.js +++ b/src/domain/session/room/timeline/tiles/TextTile.js @@ -4,9 +4,8 @@ export default class TextTile extends MessageTile { get text() { const content = this._getContent(); const body = content && content.body; - const sender = this._entry.event.sender; - if (this._entry.type === "m.emote") { - return `* ${sender} ${body}`; + if (content.msgtype === "m.emote") { + return `* ${this._entry.sender} ${body}`; } else { return body; } diff --git a/src/domain/session/room/timeline/tilesCreator.js b/src/domain/session/room/timeline/tilesCreator.js index 8af1f18f..9f583650 100644 --- a/src/domain/session/room/timeline/tilesCreator.js +++ b/src/domain/session/room/timeline/tilesCreator.js @@ -1,6 +1,5 @@ import GapTile from "./tiles/GapTile.js"; import TextTile from "./tiles/TextTile.js"; -import ImageTile from "./tiles/ImageTile.js"; import LocationTile from "./tiles/LocationTile.js"; import RoomNameTile from "./tiles/RoomNameTile.js"; import RoomMemberTile from "./tiles/RoomMemberTile.js"; @@ -10,11 +9,10 @@ export default function ({timeline, ownUserId}) { const options = {entry, emitUpdate, ownUserId}; if (entry.isGap) { return new GapTile(options, timeline); - } else if (entry.event) { - const event = entry.event; - switch (event.type) { + } else if (entry.eventType) { + switch (entry.eventType) { case "m.room.message": { - const content = event.content; + const content = entry.content; const msgtype = content && content.msgtype; switch (msgtype) { case "m.text": diff --git a/src/matrix/room/timeline/entries/EventEntry.js b/src/matrix/room/timeline/entries/EventEntry.js index ce3697fa..ea2143f1 100644 --- a/src/matrix/room/timeline/entries/EventEntry.js +++ b/src/matrix/room/timeline/entries/EventEntry.js @@ -18,12 +18,20 @@ export default class EventEntry extends BaseEntry { return this._eventEntry.event.content; } - get event() { - return this._eventEntry.event; + get eventType() { + return this._eventEntry.event.type; } - get type() { - return this._eventEntry.event.type; + get stateKey() { + return this._eventEntry.event.state_key; + } + + get sender() { + return this._eventEntry.event.sender; + } + + get timestamp() { + return this._eventEntry.event.origin_server_ts; } get id() { diff --git a/src/matrix/room/timeline/entries/PendingEventEntry.js b/src/matrix/room/timeline/entries/PendingEventEntry.js index 0a316a5b..4aa143d2 100644 --- a/src/matrix/room/timeline/entries/PendingEventEntry.js +++ b/src/matrix/room/timeline/entries/PendingEventEntry.js @@ -23,14 +23,22 @@ export default class PendingEventEntry extends BaseEntry { return null; } - get type() { + get eventType() { return this._pendingEvent.eventType; } + get stateKey() { + return null; + } + get sender() { return this._user.id; } + get timestamp() { + return null; + } + get id() { return this._pendingEvent.txnId; }