re-order ReplyThread methods for readability

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2018-05-01 17:42:58 +01:00
parent f0bd4a54e7
commit 11ae0805b0
No known key found for this signature in database
GPG key ID: 3F879DA5AD802A5E

View file

@ -59,43 +59,6 @@ export default class ReplyThread extends React.Component {
this.collapse = this.collapse.bind(this);
}
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));
if (this.unmounted) return;
if (ev) {
this.setState({
events: [ev],
}, this.loadNextEvent);
} else {
this.setState({err: true});
}
}
async loadNextEvent() {
if (this.unmounted) return;
const ev = this.state.events[0];
const inReplyToEventId = ReplyThread.getParentEventId(ev);
if (!inReplyToEventId) {
this.setState({
loading: false,
});
return;
}
const loadedEv = await ReplyThread.getEvent(this.room, inReplyToEventId);
if (this.unmounted) return;
if (loadedEv) {
this.setState({loadedEv});
} else {
this.setState({err: true});
}
}
static async getEvent(room, eventId) {
const event = room.findEventById(eventId);
if (event) return event;
@ -233,6 +196,43 @@ export default class ReplyThread extends React.Component {
this.unmounted = true;
}
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));
if (this.unmounted) return;
if (ev) {
this.setState({
events: [ev],
}, this.loadNextEvent);
} else {
this.setState({err: true});
}
}
async loadNextEvent() {
if (this.unmounted) return;
const ev = this.state.events[0];
const inReplyToEventId = ReplyThread.getParentEventId(ev);
if (!inReplyToEventId) {
this.setState({
loading: false,
});
return;
}
const loadedEv = await ReplyThread.getEvent(this.room, inReplyToEventId);
if (this.unmounted) return;
if (loadedEv) {
this.setState({loadedEv});
} else {
this.setState({err: true});
}
}
canCollapse() {
return this.state.events.length > 1;
}