Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

fix thinko when changing from ClientPeg to context in static method (DUH) #1875

Merged
merged 1 commit into from
May 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/components/views/elements/ReplyThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,6 @@ export default class ReplyThread extends React.Component {
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) {
if (!ev || ev.isRedacted()) return;

Expand Down Expand Up @@ -199,7 +183,7 @@ export default class ReplyThread extends React.Component {
async initialize() {
const {parentEv} = this.props;
// 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 (ev) {
Expand All @@ -223,7 +207,7 @@ export default class ReplyThread extends React.Component {
return;
}

const loadedEv = await ReplyThread.getEvent(this.room, inReplyToEventId);
const loadedEv = await this.getEvent(inReplyToEventId);
if (this.unmounted) return;

if (loadedEv) {
Expand All @@ -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() {
return this.state.events.length > 1;
}
Expand Down