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.
This commit is contained in:
Bruno Windels 2019-07-29 10:27:12 +02:00
parent 56cee450d1
commit 9b94c4bb61
7 changed files with 39 additions and 29 deletions

View file

@ -5,7 +5,7 @@ export default class MessageTile extends SimpleTile {
constructor(options) { constructor(options) {
super(options); super(options);
this._isOwn = this._entry.event.sender === options.ownUserId; 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; this._isContinuation = false;
} }
@ -14,7 +14,7 @@ export default class MessageTile extends SimpleTile {
} }
get sender() { get sender() {
return this._entry.event.sender; return this._entry.sender;
} }
get date() { get date() {
@ -34,8 +34,7 @@ export default class MessageTile extends SimpleTile {
} }
_getContent() { _getContent() {
const event = this._entry.event; return this._entry.content;
return event && event.content;
} }
updatePreviousSibling(prev) { updatePreviousSibling(prev) {

View file

@ -7,21 +7,20 @@ export default class RoomNameTile extends SimpleTile {
} }
get announcement() { get announcement() {
const event = this._entry.event; const {sender, content, stateKey} = this._entry;
const content = event.content;
switch (content.membership) { switch (content.membership) {
case "invite": return `${event.state_key} was invited to the room by ${event.sender}`; case "invite": return `${stateKey} was invited to the room by ${sender}`;
case "join": return `${event.state_key} joined the room`; case "join": return `${stateKey} joined the room`;
case "leave": { case "leave": {
if (event.state_key === event.sender) { if (stateKey === sender) {
return `${event.state_key} left the room`; return `${stateKey} left the room`;
} else { } else {
const reason = content.reason; 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}`; case "ban": return `${stateKey} was banned from the room by ${sender}`;
default: return `${event.sender} membership changed to ${content.membership}`; default: return `${sender} membership changed to ${content.membership}`;
} }
} }
} }

View file

@ -7,8 +7,7 @@ export default class RoomNameTile extends SimpleTile {
} }
get announcement() { get announcement() {
const event = this._entry.event; const content = this._entry.content;
const content = event.content; return `${this._entry.sender} named the room "${content.name}"`
return `${event.sender} named the room "${content.name}"`
} }
} }

View file

@ -4,9 +4,8 @@ export default class TextTile extends MessageTile {
get text() { get text() {
const content = this._getContent(); const content = this._getContent();
const body = content && content.body; const body = content && content.body;
const sender = this._entry.event.sender; if (content.msgtype === "m.emote") {
if (this._entry.type === "m.emote") { return `* ${this._entry.sender} ${body}`;
return `* ${sender} ${body}`;
} else { } else {
return body; return body;
} }

View file

@ -1,6 +1,5 @@
import GapTile from "./tiles/GapTile.js"; import GapTile from "./tiles/GapTile.js";
import TextTile from "./tiles/TextTile.js"; import TextTile from "./tiles/TextTile.js";
import ImageTile from "./tiles/ImageTile.js";
import LocationTile from "./tiles/LocationTile.js"; import LocationTile from "./tiles/LocationTile.js";
import RoomNameTile from "./tiles/RoomNameTile.js"; import RoomNameTile from "./tiles/RoomNameTile.js";
import RoomMemberTile from "./tiles/RoomMemberTile.js"; import RoomMemberTile from "./tiles/RoomMemberTile.js";
@ -10,11 +9,10 @@ export default function ({timeline, ownUserId}) {
const options = {entry, emitUpdate, ownUserId}; const options = {entry, emitUpdate, ownUserId};
if (entry.isGap) { if (entry.isGap) {
return new GapTile(options, timeline); return new GapTile(options, timeline);
} else if (entry.event) { } else if (entry.eventType) {
const event = entry.event; switch (entry.eventType) {
switch (event.type) {
case "m.room.message": { case "m.room.message": {
const content = event.content; const content = entry.content;
const msgtype = content && content.msgtype; const msgtype = content && content.msgtype;
switch (msgtype) { switch (msgtype) {
case "m.text": case "m.text":

View file

@ -18,12 +18,20 @@ export default class EventEntry extends BaseEntry {
return this._eventEntry.event.content; return this._eventEntry.event.content;
} }
get event() { get eventType() {
return this._eventEntry.event; return this._eventEntry.event.type;
} }
get type() { get stateKey() {
return this._eventEntry.event.type; return this._eventEntry.event.state_key;
}
get sender() {
return this._eventEntry.event.sender;
}
get timestamp() {
return this._eventEntry.event.origin_server_ts;
} }
get id() { get id() {

View file

@ -23,14 +23,22 @@ export default class PendingEventEntry extends BaseEntry {
return null; return null;
} }
get type() { get eventType() {
return this._pendingEvent.eventType; return this._pendingEvent.eventType;
} }
get stateKey() {
return null;
}
get sender() { get sender() {
return this._user.id; return this._user.id;
} }
get timestamp() {
return null;
}
get id() { get id() {
return this._pendingEvent.txnId; return this._pendingEvent.txnId;
} }