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) {
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) {

View File

@ -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}`;
}
}
}

View File

@ -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}"`
}
}

View File

@ -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;
}

View File

@ -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":

View File

@ -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() {

View File

@ -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;
}