Merge pull request #1875 from matrix-org/t3chguy/m.relates_to

fix thinko when changing from ClientPeg to context in static method (DUH)
This commit is contained in:
Luke Barnard 2018-05-03 18:14:17 +01:00 committed by GitHub
commit fecbac0b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,22 +59,6 @@ export default class ReplyThread extends React.Component {
this.collapse = this.collapse.bind(this); this.collapse = this.collapse.bind(this);
} }
static async getEvent(room, eventId) {
const event = room.findEventById(eventId);
if (event) return event;
try {
// ask the client to fetch the event we want using the context API, only interface to do so is to ask
// for a timeline with that event, but once it is loaded we can use findEventById to look up the ev map
await this.context.matrixClient.getEventTimeline(room.getUnfilteredTimelineSet(), eventId);
} catch (e) {
// if it fails catch the error and return early, there's no point trying to find the event in this case.
// Return null as it is falsey and thus should be treated as an error (as the event cannot be resolved).
return null;
}
return room.findEventById(eventId);
}
static getParentEventId(ev) { static getParentEventId(ev) {
if (!ev || ev.isRedacted()) return; if (!ev || ev.isRedacted()) return;
@ -199,7 +183,7 @@ export default class ReplyThread extends React.Component {
async initialize() { async initialize() {
const {parentEv} = this.props; const {parentEv} = this.props;
// at time of making this component we checked that props.parentEv has a parentEventId // at time of making this component we checked that props.parentEv has a parentEventId
const ev = await ReplyThread.getEvent(this.room, ReplyThread.getParentEventId(parentEv)); const ev = await this.getEvent(ReplyThread.getParentEventId(parentEv));
if (this.unmounted) return; if (this.unmounted) return;
if (ev) { if (ev) {
@ -223,7 +207,7 @@ export default class ReplyThread extends React.Component {
return; return;
} }
const loadedEv = await ReplyThread.getEvent(this.room, inReplyToEventId); const loadedEv = await this.getEvent(inReplyToEventId);
if (this.unmounted) return; if (this.unmounted) return;
if (loadedEv) { if (loadedEv) {
@ -233,6 +217,22 @@ export default class ReplyThread extends React.Component {
} }
} }
async getEvent(eventId) {
const event = this.room.findEventById(eventId);
if (event) return event;
try {
// ask the client to fetch the event we want using the context API, only interface to do so is to ask
// for a timeline with that event, but once it is loaded we can use findEventById to look up the ev map
await this.context.matrixClient.getEventTimeline(this.room.getUnfilteredTimelineSet(), eventId);
} catch (e) {
// if it fails catch the error and return early, there's no point trying to find the event in this case.
// Return null as it is falsey and thus should be treated as an error (as the event cannot be resolved).
return null;
}
return this.room.findEventById(eventId);
}
canCollapse() { canCollapse() {
return this.state.events.length > 1; return this.state.events.length > 1;
} }